Language: C++

#include<iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

#ifdef NO_UNLOCK_IO
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif


struct FastIO {
	static const size_t BUFFER_SIZE = 1 << 17;
	static char inbuf[BUFFER_SIZE | 1], *inptr;
	static char outbuf[BUFFER_SIZE | 1], *outptr, *endbuf;
	template <class Integral>
	static void scan(Integral &x) {
		bool read = false;
		x = 0;
		for (;;) {
			char tmp = *inptr++;
			if (tmp == '\0') {
				size_t len = fread(inbuf, 1, BUFFER_SIZE, stdin);
				inbuf[len] = '\0';
				inptr = inbuf;
				tmp = *inptr++;
			}

			if (tmp >= '0' && tmp <= '9') {
				read = true;
				x = x * 10 + tmp - '0';
			}
			else if (read) {
				++tmp;
				break;
			}
		}
	}
	template <class Arithmetic, class... Rest>
	static void scan(Arithmetic &x, Rest&... y) {
		scan(x);
		scan(y...);
	}
	static void print(const char *s, bool flush = false) {
		size_t count = strlen(s);
		char *tmp = outptr + count;
		if (flush || tmp >= endbuf) {
			fwrite(outbuf, 1, outptr - outbuf, stdout);
			tmp = outbuf + count;
			outptr = outbuf;
		}

		memcpy(outptr, s, count);
		outptr = tmp;
	}
	static void flush() {
		fwrite(outbuf, 1, outptr - outbuf, stdout);

		outptr = outbuf;
	}
};

char FastIO::inbuf[], *FastIO::inptr = FastIO::inbuf;
char FastIO::outbuf[], *FastIO::outptr = FastIO::outbuf;
char *FastIO::endbuf = outbuf + FastIO::BUFFER_SIZE;
int tree[1 << 17];

class UnionFindTree {
public:
	UnionFindTree() {
		memset(tree, 0xFF, sizeof tree);
	}
	size_t find_root(size_t v) {
		return (tree[v] < 0) ? v : (tree[v] = find_root(tree[v]));
	}
	bool unite(size_t x, size_t y) {
		x = find_root(x);
		y = find_root(y);
		if (x == y) return false;
		if (tree[x] > tree[y]) std::swap(x, y);
		tree[x] += tree[y];
		tree[y] = x;

		return true;
	}
	bool connected(size_t x, size_t y) {
		return find_root(x) == find_root(y);
	}
	size_t rank(size_t v) {
		return -tree[find_root(v)];
	}
};

int main() {
	int N;
	vector<int> a(N);
	UnionFindTree uni;
	for (size_t i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		a[i] = tmp;
	}
	vector<int>where(N + 1);
	for (size_t i = 0; i < N; i++)
	{
		where[a[i]] = i;
	}

	bool usedIndex[300000];
	long sum = 0;
	for (size_t i = N; i > 0; i--)
	{
		int index = where[i];//indexは0から
		long res = i;
		if (index - 1 >= 0 && usedIndex[index - 1]) {
			res *= (long)uni.size(A[index - 1]) + 1;
			uni.unite(A[index], A[index - 1]);
		}
		if (index + 1 < N && usedIndex[index + 1]) {
			res *= (long)uni.size(A[index + 1]) + 1;
			uni.unite(A[index], A[index + 1]);
		}
		usedIndex[index] = true;
		sum += res;
	}
	cout << sum<<endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:119:42: error: 'class UnionFindTree' has no member named 'size'
  119 |                         res *= (long)uni.size(A[index - 1]) + 1;
      |                                          ^~~~
a.cc:119:47: error: 'A' was not declared in this scope
  119 |                         res *= (long)uni.size(A[index - 1]) + 1;
      |                                               ^
a.cc:123:42: error: 'class UnionFindTree' has no member named 'size'
  123 |                         res *= (long)uni.size(A[index + 1]) + 1;
      |                                          ^~~~
a.cc:123:47: error: 'A' was not declared in this scope
  123 |                         res *= (long)uni.size(A[index + 1]) + 1;
      |                                               ^