#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << "," << p.second << ")"; return o;}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";for(auto e:x)o<< e << ", ";return o<<"}";}
#define debug(X) cerr << "["#X"]:" << X << '\n';
#else
#define debug(X) ;
#endif
#define ll long long
#define all(x) (x).begin(), (x).end()
#define cerr if(0)cout
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(all(a));
int base = 1;
while (base < n) base *= 2;
struct Node {
int mx, lazy;
Node() {
mx = lazy = 0;
}
};
vector<Node> tree(2*base);
for (int i = 0; i < n; i++) {
tree[base+i].mx = a[i];
}
for (int i = base-1; i >= 1; i--) {
tree[i].mx = max(tree[2*i].mx, tree[2*i+1].mx);
}
auto push_to_sons = [&](int v) {
if (tree[v].lazy == 0) return;
int x = tree[v].lazy;
tree[2*v].mx += x;
tree[2*v+1].mx += x;
tree[2*v].lazy += x;
tree[2*v+1].lazy += x;
tree[v].lazy = 0;
};
function<void(int, int, int, int, int, int)> update = [&](int l, int r, int x, int v, int a, int b) {
if (r < a || b < l) return;
if (l <= a && b <= r) {
tree[v].mx += x;
tree[v].lazy += x;
return;
}
push_to_sons(v);
int mid = (a+b)/2;
update(l, r, x, 2*v, a, mid); update(l, r, x, 2*v+1, mid+1, b);
tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
};
function<int(int, int, int, int)> find = [&](int x, int v, int a, int b) {
if (tree[v].mx < x) return -1;
if (a == b) return a;
push_to_sons(v);
int mid = (a+b)/2;
int y = find(x, 2*v, a, mid);
if (y != -1) return y;
return find(x, 2*v+1, mid+1, b);
};
function<int(int, int, int, int)> find2 = [&](int x, int v, int a, int b) {
if (tree[v].mx <= x) return -1;
if (a == b) return a;
push_to_sons(v);
int mid = (a+b)/2;
int y = find2(x, 2*v, a, mid);
if (y != -1) return y;
return find2(x, 2*v+1, mid+1, b);
};
function<int(int, int, int, int)> val = [&](int x, int v, int a, int b) {
if (a == b) return tree[v].mx;
push_to_sons(v);
int mid = (a+b)/2;
if (x <= mid) return val(x, 2*v, a, mid);
else return val(x, 2*v+1, mid+1, b);
};
auto print = [&]() {
for (int i = 1; i < 2*base; i++) {
if (i < base) push_to_sons(i);
cerr << "(" << tree[i].mx << ", " << tree[i].lazy << ") ";
}
cerr << '\n';
return;
};
while (m--) {
char c;
cin >> c;
if (c == 'F') {
int c, h;
cin >> c >> h;
int idx = find(h, 1, 0, base-1);
cerr << "FFF " << idx << '\n';
if (idx == -1) continue;
int end = min(n-1, idx+c-1);
int fi = find(val(end, 1, 0, base-1), 1, 0, base-1);
int last = find2(val(end, 1, 0, base-1), 1, 0, base-1)-1;
if (last == -2) last = n-1;
cerr << "val: " << val(end, 1, 0, base-1) << '\n';
cerr << "fi: " << fi << '\n';
cerr << "last: " << last << '\n';
if (idx != fi) {
update(idx, fi-1, 1, 1, 0, base-1);
update(max(fi, last-(c-(fi-idx))+1), last, 1, 1, 0, base-1);
}
else {
update(idx, end, 1, 1, 0, base-1);
}
print();
}
else {
int minn, maxx;
cin >> minn >> maxx;
int low = find(minn, 1, 0, base-1), up = find2(maxx, 1, 0, base-1);
cerr << low << ' ' << up << '\n';
if (low == -1) {cout << 0 << '\n'; continue;}
if (up == -1) {cout << n-low << '\n'; continue;}
up--;
cout << up-low+1 << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
2848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
109 ms |
552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
1616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1048 ms |
2668 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
2684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
2724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
2712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
312 ms |
3244 KB |
Output is correct |