#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];
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];
ll D[n + 1] = {};
D[0] = 1;
for(int i = 1; i <= n; i++)
D[i] = D[i - 1] * ((d[i] + D[i - 1] - 1)/ D[i - 1]);
int nxt[n + 1] = {};
nxt[n] = n + 1;
for(int i = n - 1; i >= 0; i--) {
nxt[i] = (D[i] == D[i + 1] ? nxt[i + 1] : i + 1);
}
// for(int i = 0; i <= n; i++)
// cout << D[i] << ' ';
// cout << '\n';
for(int i = 1; i <= q; i++) {
ll t, l, r;
cin >> t >> l >> r;
int x = 1, pos = t;
ll ans = (l <= t && t <= r);
while(x <= n) {
ll pos_r = -x + (pos + x - 1) / D[x] * D[x];
ll pos_l = pos_r - (nxt[x] - 1 - x);
// cout << x << ' ' << nxt[x] << '\n';
// cout << pos_l << ' ' << pos_r << '\n';
ll lb = max(pos_l, l), rb = min(pos_r, r);
ans += max(rb - lb + 1, 0ll);
pos = pos_l;
x = nxt[x];
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
28584 KB |
Output is correct |
2 |
Correct |
179 ms |
28448 KB |
Output is correct |
3 |
Correct |
186 ms |
28592 KB |
Output is correct |
4 |
Correct |
179 ms |
28504 KB |
Output is correct |
5 |
Correct |
181 ms |
28432 KB |
Output is correct |
6 |
Correct |
176 ms |
28488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
28584 KB |
Output is correct |
2 |
Correct |
179 ms |
28448 KB |
Output is correct |
3 |
Correct |
186 ms |
28592 KB |
Output is correct |
4 |
Correct |
179 ms |
28504 KB |
Output is correct |
5 |
Correct |
181 ms |
28432 KB |
Output is correct |
6 |
Correct |
176 ms |
28488 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
183 ms |
27068 KB |
Output is correct |
14 |
Correct |
196 ms |
27632 KB |
Output is correct |
15 |
Correct |
171 ms |
26220 KB |
Output is correct |
16 |
Correct |
180 ms |
26976 KB |
Output is correct |
17 |
Correct |
260 ms |
31032 KB |
Output is correct |
18 |
Correct |
259 ms |
31024 KB |
Output is correct |
19 |
Correct |
259 ms |
31092 KB |
Output is correct |
20 |
Correct |
261 ms |
31148 KB |
Output is correct |
21 |
Correct |
259 ms |
31032 KB |
Output is correct |
22 |
Correct |
258 ms |
31136 KB |
Output is correct |
23 |
Correct |
254 ms |
30924 KB |
Output is correct |
24 |
Correct |
255 ms |
31128 KB |
Output is correct |
25 |
Correct |
182 ms |
28512 KB |
Output is correct |
26 |
Correct |
181 ms |
28444 KB |
Output is correct |
27 |
Correct |
263 ms |
30568 KB |
Output is correct |
28 |
Correct |
291 ms |
30912 KB |
Output is correct |
29 |
Correct |
282 ms |
30412 KB |
Output is correct |
30 |
Correct |
280 ms |
30592 KB |
Output is correct |
31 |
Correct |
320 ms |
30840 KB |
Output is correct |
32 |
Correct |
177 ms |
27096 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |