这个代码自己看没问题啊,求大佬的帮助!(样例过不了?)
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int w[10000005], ls[10000005], rs[10000005];
long long ansl, ansr;
stack<int> rc;
int main() {
ios::sync_with_stdio(0);
int n, t;
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> w[i];
}
rc.push(1);
for (int i = 2; i <= n; i ++) {
t = 0;
while (!rc.empty() && w[rc.top()] > w[i]) {
t = rc.top();
rc.pop();
}
if (rc.empty()) {
ls[i] = t;
} else {
ls[i] = rs[rc.top()];
rs[rc.top()] = i;
}
rc.push(i);
}
for (int i = 1; i <= n; i ++) {
ansl ^= 1ll * i * (ls[i] + 1);
ansl ^= 1ll * i * (rs[i] + 1);
}
cout << ansl << ' ' << ansr;
return 0;
}
样例测试:
5
4 1 3 2 5
6 0Program ended with exit code: 0