77行力(大悲 啊啊啊啊,已经痛苦DEBUG两个晚上了,不知道有什么问题,有没有哪个大神帮我调一下,可能写法有不同,我用的是结构体数组。 最新提交记录链接点这里 代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
struct node {
ll l, r, s, tag; // lazytag 懒标记
} tree[N * 4];
ll a[N], m, d, t = 0, len = 0;
void build(int p, int l, int r) {
tree[p].l = l; tree[p].r = r;
if (l == r) {
tree[p].s = a[l];
return;
}
ll mid = (l + r) >> 1;
build(p * 2, l, mid); build(p * 2 + 1, mid + 1, r);
tree[p].s = max(tree[p * 2].s, tree[p * 2 + 1].s); // push_up 回拉
}
void f(int p, int k) {
tree[p].tag += k;
tree[p].s += (tree[p].r - tree[p].l + 1) * k;
}
void pushdown(int p) {
f(p * 2, tree[p].tag);
f(p * 2 + 1, tree[p].tag);
tree[p].tag = 0;
}
void update(ll p, ll l, ll r,ll id, ll k) {
if (tree[p].l == tree[p].r) {
tree[p].s = k;
return;
}
//pushdown(p);
ll mid = (tree[p].l + tree[p].r) >> 1;
if (id <= mid) update(p * 2, l, mid, id, k);
else update(p * 2 + 1, mid + 1, r, id, k);
tree[p].s = max(tree[p * 2].s, tree[p * 2 + 1].s); // push_up
}
ll query(ll p, ll l, ll r) {
if (tree[p].l >= l && tree[p].r <= r) return tree[p].s;
//pushdown(p);
ll mid = (tree[p].l + tree[p].r) >> 1, ans = -1e18; // 初始化为最小值
if (l <= mid) ans = query(p * 2, l, mid);
if (r > mid) ans = max(ans, query(p * 2 + 1, mid + 1, r));
return ans;
}
int main() {
cin >> m >> d;
build(1, 1, m);
for (int i = 0; i < m; i++) {
char c;
cin >> c;
if (c == 'Q') {
int l;
cin >> l;
if (len == 0) t = 0;
else t = query(1, len - l + 1, len);
cout << t << "\n";
}
else {
ll n;
cin >> n;
len++;
update(1, 1, len, len, (n + t) % d);
}
}
return 0;
}