#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 1e3 + 10;
const int N = 5e5 + 10;
int n, q;
ll d[N], T[N], L[N], R[N];
struct query {
ll l, r, i, t;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> d[i];
for(int i = 1; i <= q; i++) {
cin >> T[i] >> L[i] >> R[i];
}
if(n <= 1000 && q <= 1000) {
int ans[q + 1] = {};
vector<query> g[M];
for(int i = 1; i <= q; i++) {
g[T[i]].push_back({L[i], R[i], i, T[i]});
}
vector<int> ar(n + 1);
for(int i = 0; i <= n; i++) ar[i] = -i;
for(int t = 1; t < M; t++) {
ar[0]++;
for(int i = 1; i <= n; i++)
if(!i || ar[i - 1] - ar[i] > d[i]) ar[i] = ar[i - 1] - 1;
// for(int c : ar) cout << c << ' ';
// cout << '\n';
for(query cur : g[t]) {
for(int c : ar) {
ans[cur.i] += (cur.l <= c && c <= cur.r);
}
}
}
for(int i = 1; i <= q; i++)
cout << ans[i] << '\n';
return 0;
}
bool flag = 1;
for(int i = 1; i <= n; i++)
flag &= (d[i] == 1);
if(flag) {
for(int i = 1; i <= q; i++) {
ll lb = max(T[i] - n, L[i]), rb = min(T[i], R[i]);
cout << max(rb - lb + 1, 0ll) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
19052 KB |
Output is correct |
2 |
Correct |
161 ms |
18988 KB |
Output is correct |
3 |
Correct |
175 ms |
18888 KB |
Output is correct |
4 |
Correct |
174 ms |
18972 KB |
Output is correct |
5 |
Correct |
164 ms |
18932 KB |
Output is correct |
6 |
Correct |
163 ms |
18904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
19052 KB |
Output is correct |
2 |
Correct |
161 ms |
18988 KB |
Output is correct |
3 |
Correct |
175 ms |
18888 KB |
Output is correct |
4 |
Correct |
174 ms |
18972 KB |
Output is correct |
5 |
Correct |
164 ms |
18932 KB |
Output is correct |
6 |
Correct |
163 ms |
18904 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
340 KB |
Output is correct |
13 |
Incorrect |
137 ms |
15928 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |