这个代码虽复杂度不对,但是题目所给附件的样例都过了,为什么会是全WA?
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 100;
int n, c, q, oqt, x, ans, t;
int a[N], b[N];
struct segyid {
int l, r, maxn, sum;
} tree[N * 4];
void make_tree(int p, int l, int r) {
tree[p].l = l, tree[p].r = r;
if(l == r) {
tree[p].sum = b[l];
tree[p].maxn = b[l];
return;
}
int mid = l + r >> 1;
make_tree(p << 1, l, mid);
make_tree(p << 1 | 1, mid + 1, r);
tree[p].maxn = max(tree[p << 1].maxn, tree[p << 1 | 1].maxn);
}
signed main()
{
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> c >> q;
while(q --) {
cin >> oqt;
if(oqt == 1) {
cin >> x;
a[++ t] = a[t - 1] + x;
b[t] = x;
} else if(oqt == 2) {
cin >> x;
ans += x;
} else if(oqt == 3) {
cin >> x;
x += ans;
// if(a[lower_bound(a + 1, a + 1 + t, ans) - a] - ans >= x) {
// cout << b[lower_bound(a + 1, a + 1 + t, ans) - a] - (a[lower_bound(a + 1, a + 1 + t, ans) - a] - ans - x) << "\n";
// }
// else {
// x -= a[lower_bound(a + 1, a + 1 + t, ans) - a] - ans;
// }
cout << b[lower_bound(a + 1, a + 1 + t, x) - a] - (a[lower_bound(a + 1, a + 1 + t, x) - a] - x) << "\n";
} else {
make_tree(1, upper_bound(a + 1, a + 1 + t, ans) - a, t);
cout << tree[1].maxn << "\n";
}
}
return 0;
}