#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int N = 1e5 + 10;
int n;
int h[N];
int fenwick[N];
void update(int idx, int val) {
for(; idx < N; idx += (idx & -idx)) {
fenwick[idx] += val;
}
}
int query(int idx) {
int res = 0;
for(; idx > 0; idx -= (idx & -idx)) {
res += fenwick[idx];
}
return res;
}
int lowerbound(int x) {
int l = 1, r = n, low = n + 1;
while(l <= r) {
int mid = (l + r) / 2;
if(h[mid] + query(mid) < x) {
l = mid + 1;
}
else {
r = mid - 1;
low = mid;
}
}
return low;
}
int upperbound(int x) {
int l = 1, r = n, up = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(h[mid] + query(mid) > x) {
r = mid - 1;
}
else {
l = mid + 1;
up = mid;
}
}
return up;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int m;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> h[i];
}
sort(h + 1, h + n + 1);
while(m--) {
char t;
int a, b;
cin >> t >> a >> b;
if(t == 'F') {
int idx = lowerbound(b);
if(h[idx + a - 1] + query(idx + a - 1) != b) {
int idx2 = lowerbound(b + 1);
int idx3 = upperbound(b + 1);
update(idx, 1);
update(idx2, -1);
a -= idx2 - idx;
update(idx3 - a + 1, 1);
update(idx3 + 1, -1);
}
else {
update(idx, 1);
update(idx + a, -1);
}
}
else {
cout << upperbound(b) - lowerbound(a) + 1 << '\n';
}
if(DEBUG) {
cout << "Debugging : \n";
for(int i = 1; i <= n; i++) {
cout << h[i] + query(i) << " ";
}
cout << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
1688 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
716 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
1432 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
1744 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
1616 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
2036 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
1832 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
1956 KB |
Execution killed with signal 11 |