#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e5 + 69;
int st[4 * maxn], n, q, a[maxn], lz[4 * maxn];
void push(int v) {
if (lz[v]) {
st[v * 2] += lz[v];
st[v * 2 + 1] += lz[v];
lz[v * 2] += lz[v];
lz[v * 2 + 1] += lz[v];
lz[v] = 0;
}
}
void build(int v, int tl, int tr) {
if (tl == tr)
st[v] = a[tl];
else {
int mid = (tl + tr) / 2;
build(v * 2, tl, mid);
build(v * 2 + 1, mid + 1, tr);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
void upd(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r) {
st[v]++;
lz[v]++;
}
else {
int mid = (tl + tr) / 2;
push(v);
upd(v * 2, tl, mid, l, r);
upd(v * 2 + 1, mid + 1, tr, l, r);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
int qry(int v, int tl, int tr, int x) {
if (tl == tr)
return tl;
else {
push(v);
int mid = (tl + tr) / 2;
if (st[v * 2] >= x)
return qry(v * 2, tl, mid, x);
else
return qry(v * 2 + 1, mid + 1, tr, x);
}
}
int qryind(int v, int tl, int tr, int p) {
if (tl == tr)
return st[v];
else {
push(v);
int mid = (tl + tr) / 2;
if (mid >= p)
return qryind(v * 2, tl, mid, p);
else
return qryind(v * 2 + 1, mid + 1, tr, p);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> q;
++n;
a[n] = 1e18;
for (int i = 1;i < n;i++)
cin >> a[i];
sort(a + 1, a + n + 1);
build(1, 1, n);
while (q--) {
char t;
cin >> t;
if (t == 'F') {
int c, h;
cin >> c >> h;
int l = qry(1, 1, n, h);
int r = min(n - 1, l + c - 1);
int x = qryind(1, 1, n, r);
int y = qryind(1, 1, n, r + 1);
if (x == y) {
int z = max(l, qry(1, 1, n, x));
int raz = r - z + 1;
int p = qry(1, 1, n, x + 1);
if (z > l)
upd(1, 1, n, l, z - 1);
upd(1, 1, n, p - raz, p - 1);
}
else
upd(1, 1, n, l, r);
}
else {
int l, r;
cin >> l >> r;
cout << max(0ll, qry(1, 1, n, r + 1) - qry(1, 1, n, l)) << '\n';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
7764 KB |
Output is correct |
2 |
Correct |
77 ms |
8196 KB |
Output is correct |
3 |
Correct |
50 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
31 ms |
3420 KB |
Output is correct |
6 |
Correct |
38 ms |
3932 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
19 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
3600 KB |
Output is correct |
2 |
Correct |
38 ms |
3924 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
23 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
3676 KB |
Output is correct |
2 |
Correct |
46 ms |
4188 KB |
Output is correct |
3 |
Correct |
7 ms |
2752 KB |
Output is correct |
4 |
Correct |
37 ms |
3924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
6460 KB |
Output is correct |
2 |
Correct |
76 ms |
7936 KB |
Output is correct |
3 |
Correct |
13 ms |
5468 KB |
Output is correct |
4 |
Correct |
50 ms |
7904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
7260 KB |
Output is correct |
2 |
Correct |
75 ms |
8020 KB |
Output is correct |
3 |
Correct |
51 ms |
8116 KB |
Output is correct |
4 |
Correct |
11 ms |
5464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
7668 KB |
Output is correct |
2 |
Correct |
57 ms |
7764 KB |
Output is correct |
3 |
Correct |
53 ms |
8248 KB |
Output is correct |
4 |
Correct |
11 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
7672 KB |
Output is correct |
2 |
Correct |
83 ms |
8200 KB |
Output is correct |
3 |
Correct |
21 ms |
7256 KB |
Output is correct |
4 |
Correct |
44 ms |
7612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
7500 KB |
Output is correct |
2 |
Correct |
72 ms |
8268 KB |
Output is correct |
3 |
Correct |
100 ms |
8372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
8272 KB |
Output is correct |