#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t[N], a[N];
int n;
void upd(int id, int val) {
for(id; id <= n; id += id & (-id)) t[id] += val;
}
int get(int id) {
int ans = 0;
for(id; id >= 1; id -= id & (-id)) ans += t[id];
return ans;
}
int find(int x) {
int l = 1, r = n, id = n + 1;
while(l <= r) {
int mid = (l + r) / 2;
if(get(mid) >= x) id = mid, r = mid - 1;
else l = mid + 1;
}
return id;
}
main(){
int q;
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++) {
upd(i, a[i]);
upd(i + 1, -a[i]);
}
++q;
while(--q) {
char c;
cin >> c;
if(c == 'F') {
int cn, h;
cin >> cn >> h;
int id = find(h);
if(id + cn - 1 < n) {
int L = max(id, find(get(id + cn - 1))), R = find(get(id + cn - 1) + 1) - 1;
// id - L + 1 bolo amdeni
upd(R - (id + cn - 1 - L + 1) + 1, 1);
upd(R + 1, -1);
upd(id, 1);
upd(L, -1);
} else upd(id, 1);
continue;
} else {
int L, R;
cin >> L >> R;
cout << find(R + 1) - 1 - find(L) + 1 << "\n";
}
}
}
Compilation message
grow.cpp: In function 'void upd(int, int)':
grow.cpp:10:9: warning: statement has no effect [-Wunused-value]
10 | for(id; id <= n; id += id & (-id)) t[id] += val;
| ^~
grow.cpp: In function 'int get(int)':
grow.cpp:14:9: warning: statement has no effect [-Wunused-value]
14 | for(id; id >= 1; id -= id & (-id)) ans += t[id];
| ^~
grow.cpp: At global scope:
grow.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
2280 KB |
Output is correct |
2 |
Correct |
159 ms |
2612 KB |
Output is correct |
3 |
Correct |
81 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
368 KB |
Output is correct |
3 |
Correct |
6 ms |
372 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
124 ms |
1404 KB |
Output is correct |
6 |
Correct |
158 ms |
1612 KB |
Output is correct |
7 |
Correct |
7 ms |
320 KB |
Output is correct |
8 |
Correct |
114 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
1608 KB |
Output is correct |
2 |
Correct |
168 ms |
1680 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
131 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
1852 KB |
Output is correct |
2 |
Correct |
169 ms |
1612 KB |
Output is correct |
3 |
Correct |
7 ms |
468 KB |
Output is correct |
4 |
Correct |
189 ms |
1752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
1944 KB |
Output is correct |
2 |
Correct |
153 ms |
2228 KB |
Output is correct |
3 |
Correct |
39 ms |
800 KB |
Output is correct |
4 |
Correct |
56 ms |
2248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
1896 KB |
Output is correct |
2 |
Correct |
151 ms |
2356 KB |
Output is correct |
3 |
Correct |
65 ms |
2472 KB |
Output is correct |
4 |
Correct |
47 ms |
920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
2128 KB |
Output is correct |
2 |
Correct |
117 ms |
2252 KB |
Output is correct |
3 |
Correct |
68 ms |
2564 KB |
Output is correct |
4 |
Correct |
38 ms |
812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
2632 KB |
Output is correct |
2 |
Correct |
148 ms |
2192 KB |
Output is correct |
3 |
Correct |
41 ms |
1756 KB |
Output is correct |
4 |
Correct |
118 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
2416 KB |
Output is correct |
2 |
Correct |
163 ms |
2672 KB |
Output is correct |
3 |
Correct |
119 ms |
2860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
3296 KB |
Output is correct |