AmamiyaYuuko @ 2020-08-05 21:08:13
呜呜呜
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
template <class T>
inline void read(T &x) {
x = 0;
int f = 0;
char ch = getchar();
while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); }
while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
x = f ? -x : x;
return ;
}
typedef long long LL;
LL t[4000010], tag[4000010];
LL C;
int n, q, L, R;
char opt;
inline int lson(int x) { return x << 1; }
inline int rson(int x) { return x << 1 | 1; }
void buildTree(int x, int l, int r) {
if (l == r) {
read(t[x]);
return ;
}
int mid = (l + r) >> 1;
buildTree(lson(x), l, mid), buildTree(rson(x), mid + 1, r);
t[x] = std::min(t[lson(x)], t[rson(x)]);
}
void modify(int nl, int nr, int x, int l, int r, LL d) {
if (nl >= l && nr <= r) {
tag[x] += d;
return ;
}
int mid = (nl + nr) >> 1;
if (l <= mid) modify(nl, mid, lson(x), l, r, d);
if (r > mid) modify(mid + 1, nr, rson(x), l, r, d);
t[x] = std::min(t[lson(x)] + tag[lson(x)], t[rson(x)] + tag[rson(x)]);
}
LL query(int nl, int nr, int x, int l, int r, LL d) {
if (nl >= l && nr <= r && t[x] + tag[x]>= d) return nr - nl + 1;
if (nl == nr) return 0;
int mid = (nl + nr) >> 1;
LL s = 0;
if (l <= mid) s += query(nl, mid, lson(x), l, r, d);
if (r > mid) s += query(mid + 1, nr, rson(x), l, r, d);
return s;
}
int main() {
read(n), read(q);
buildTree(1, 1, n);
while (q--) {
scanf("%c", &opt);
read(L), read(R), read(C);
if (opt == 'M') modify(1, n, 1, L, R, C);
else printf("%lld\n", query(1, n, 1, L, R, C));
}
return 0;
}
by hzy1 @ 2021-01-03 15:04:00
你的pushdown是不是没写啊
by AmamiyaYuuko @ 2021-03-14 21:49:18
@KOMA_ 因为是永久标记所以不用写pushdown吧(