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 一颗糖很好吃 @ 2020-08-05 21:20:00
进来一看,不会欸(溜
by 一颗糖很好吃 @ 2020-08-05 21:24:40
头像好评
by 囧仙 @ 2020-08-05 21:54:03
@CrispyCommand 这题线段树做不了,目测你复杂度假的
by AmamiyaYuuko @ 2020-08-05 22:36:10
@囧仙 哭
by AmamiyaYuuko @ 2020-08-06 04:02:14
@一颗糖很好吃 这个头像是我自己生成的,所以如果您觉得见过的话应该是记错了(?
by 一颗糖很好吃 @ 2020-08-06 07:21:46
我说的是头像很好康( ̄∇ ̄)
by AmamiyaYuuko @ 2020-08-08 21:50:00
@一颗糖很好吃 谢谢(
by fzj2007 @ 2020-08-21 10:56:17
@CrispyCommand 你这维护啥呢...可以看看题解的线段树,维护max和min
by AmamiyaYuuko @ 2020-08-21 11:37:06
@fzj2007 区间最小值啊(
by fzj2007 @ 2020-08-21 11:51:48
@CrispyCommand 阿这神奇的写法 ..