#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 998244353
#define LOGN 20
#define MAXN 100005
int N, M, l, r, c, h;
int tree[MAXN];
void add(int k, int a) {
while (k <= N) {
tree[k] += a;
k += k&-k;
}
}
void update(int l, int r, int x) {
add(r+1, -x);
add(l, x);
}
int query(int k) {
int res = 0;
while (k) {
res += tree[k];
k -= k&-k;
}
return res;
}
int main() {
fast
cin >> N >> M;
vector<int> arr(N);
for (int i = 0; i < N; i++)
cin >> arr[i];
sort(arr.begin(), arr.end());
for (int i = 1; i <= N; i++)
update(i, i, arr[i-1]);
char type;
while (M--) {
cin >> type;
if (type == 'F') {
cin >> c >> h;
int L = 1;
int R = N;
int ans = -1;
while (R >= L) {
int mid = L + (R-L)/2;
int q = query(mid);
if (q >= h) {
R = mid - 1;
ans = mid;
} else
L = mid + 1;
}
int rightEnd = ans + c - 1;
if (rightEnd >= N) {
update(ans, N, 1);
} else {
int q = query(rightEnd);
int L = 1;
int R = N;
int ans2 = -1;
while (R >= L) {
int mid = L + (R-L)/2;
int q2 = query(mid);
if (q2 >= q) {
R = mid - 1;
ans2 = mid;
} else
L = mid + 1;
}
L = 1;
R = N;
int right = -1;
while (R >= L) {
int mid = L + (R-L)/2;
int q2 = query(mid);
if (q2 <= q) {
L = mid + 1;
right = mid;
} else
R = mid - 1;
}
int len = ans2-ans;
update(ans, ans2-1, 1);
update(right-c+len+1, right, 1);
}
} else {
cin >> l >> r;
int L = 1;
int R = N;
int ans1 = -1;
while (R >= L) {
int mid = L + (R-L)/2;
int q = query(mid);
if (q >= l) {
R = mid - 1;
ans1 = mid;
} else
L = mid + 1;
}
L = 1;
R = N;
int ans2 = -1;
while (R >= L) {
int mid = L + (R-L)/2;
int q = query(mid);
if (q > r) {
R = mid - 1;
ans2 = mid;
} else
L = mid + 1;
}
if (ans1 == -1)
cout << "0\n";
else {
if (ans2 == -1)
ans2 = N+1;
cout << ans2 - ans1 << "\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
1436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
36 ms |
1008 KB |
Output is correct |
6 |
Execution timed out |
1086 ms |
468 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1055 ms |
468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
1100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1071 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
1496 KB |
Output is correct |
2 |
Execution timed out |
1082 ms |
1364 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
1364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
1976 KB |
Output is correct |