90分求助,不知道怎么改快..
查看原帖
90分求助,不知道怎么改快..
131273
FallacyMaker楼主2022/11/17 01:34
// https://www.luogu.com.cn/problem/P5854
#include <bits/stdc++.h>

using ll = long long;

const int N = (int)1e7 + 10;

int a[N], pos[N], l[N], r[N];
int sta[N], now;

int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		f = (ch == '-') ? -1 : 1, ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

int main() {
	int n; 
	n = read();

	for (int i = 1; i <= n; ++i)
		a[i] = read(), pos[a[i]] = i;

	for (int i = 1; i <= n; ++i) {
		int las = 0;
		while (now > 0 && sta[now] > a[i]) {
			las = sta[now];
			--now;
		}
		// std::cerr << "las: " << las << '\n';
		if (las) 
			l[i] = pos[las];
		if (now > 0)
			r[pos[sta[now]]] = i;
		sta[++now] = a[i];
	}

	ll ansL = 0ll, ansR = 0ll;
	for (int i = 1; i <= n; ++i) 
		ansL ^= 1ll * i * (l[i] + 1), ansR ^= 1ll * i * (r[i] + 1);
	std::cout << ansL << ' ' << ansR << '\n';	
	return 0;
}

上来一开始习惯vector直接被爆了,然后换了C-array也差不多,加了快读还是过不了最后一个点,求助..

2022/11/17 01:34
加载中...