#include <bits/stdc++.h>
using namespace std;
#define int long long int
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
int arr[100005], seg[4*100005], lazy[4*100005];
void lazypropagate(int n, int l, int r) {
if (lazy[n]) {
seg[n] += lazy[n];
if (l != r) {
lazy[2*n] += lazy[n];
lazy[2*n+1] += lazy[n];
}
lazy[n] = 0;
}
}
void build(int n, int l, int r) {
if (l == r) {
seg[n] = arr[l];
} else {
int m = (l+r)/2;
build(2*n, l, m);
build(2*n+1, m+1, r);
seg[n] = max(seg[2*n], seg[2*n+1]);
}
}
void update(int n, int l, int r, int a, int b, int v) {
lazypropagate(n, l, r);
if (b < l || r < a) {
return;
} else if (a <= l && r <= b) {
lazy[n] = v;
lazypropagate(n, l, r);
} else {
int m = (l+r)/2;
update(2*n, l, m, a, b, v);
update(2*n+1, m+1, r, a, b, v);
seg[n] = max(seg[2*n], seg[2*n+1]);
}
}
int query(int n, int l, int r, int a, int b) {
if (b < l || r < a) {
return 0;
}
lazypropagate(n, l, r);
if (a <= l && r <= b) {
return seg[n];
} else {
int m = (l+r)/2;
return max(query(2*n, l, m, a, b), query(2*n+1, m+1, r, a, b));
}
}
int search(int n, int h) {
int l = 0, r = n-1;
while(l < r) {
int m = (l+r)/2, v;
v = query(1, 0, n-1, m, m);
if (v >= h) {
r = m;
} else {
l = m+1;
}
}
if (query(1, 0, n-1, l, l) < h) {
return n;
}
return l;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
arr[i] = a[i];
}
build(1, 0, n-1);
while(m--) {
char ch;
cin >> ch;
if (ch == 'F') {
int c, h, ind1, ind2, ind3, hm;
cin >> c >> h;
ind1 = search(n, h);
if (ind1 == n) {
continue;
}
if (ind1+c >= n) {
update(1, 0, n-1, ind1, n-1, 1);
continue;
}
hm = query(1, 0, n-1, ind1+c-1, ind1+c-1);
ind2 = search(n, hm);
if (ind1 == ind2) {
ind3 = search(n, hm+1);
update(1, 0, n-1, ind3-c, ind3-1, 1);
continue;
}
update(1, 0, n-1, ind1, ind2-1, 1);
c -= ind2-ind1;
ind3 = search(n, hm+1);
update(1, 0, n-1, ind3-c, ind3-1, 1);
} else {
int mn, mx;
cin >> mn >> mx;
cout << search(n, mx+1)-search(n, mn) << "\n";
}
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
7116 KB |
Output is correct |
2 |
Correct |
441 ms |
7672 KB |
Output is correct |
3 |
Correct |
164 ms |
7440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
612 KB |
Output is correct |
3 |
Correct |
6 ms |
572 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
188 ms |
1844 KB |
Output is correct |
6 |
Correct |
213 ms |
1996 KB |
Output is correct |
7 |
Correct |
18 ms |
1112 KB |
Output is correct |
8 |
Correct |
129 ms |
1476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
2124 KB |
Output is correct |
2 |
Correct |
215 ms |
2124 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
148 ms |
1540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
2136 KB |
Output is correct |
2 |
Correct |
245 ms |
2024 KB |
Output is correct |
3 |
Correct |
27 ms |
860 KB |
Output is correct |
4 |
Correct |
226 ms |
2128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
4688 KB |
Output is correct |
2 |
Correct |
437 ms |
6996 KB |
Output is correct |
3 |
Correct |
56 ms |
2132 KB |
Output is correct |
4 |
Correct |
124 ms |
6980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
6740 KB |
Output is correct |
2 |
Correct |
434 ms |
6996 KB |
Output is correct |
3 |
Correct |
162 ms |
7252 KB |
Output is correct |
4 |
Correct |
61 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
6816 KB |
Output is correct |
2 |
Correct |
307 ms |
7248 KB |
Output is correct |
3 |
Correct |
164 ms |
7508 KB |
Output is correct |
4 |
Correct |
58 ms |
2128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
7516 KB |
Output is correct |
2 |
Correct |
412 ms |
7044 KB |
Output is correct |
3 |
Correct |
71 ms |
6992 KB |
Output is correct |
4 |
Correct |
311 ms |
7100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
7508 KB |
Output is correct |
2 |
Correct |
419 ms |
7504 KB |
Output is correct |
3 |
Correct |
596 ms |
7900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
8396 KB |
Output is correct |