#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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
13104 KB |
Output is correct |
2 |
Correct |
172 ms |
12984 KB |
Output is correct |
3 |
Correct |
183 ms |
13076 KB |
Output is correct |
4 |
Correct |
169 ms |
13088 KB |
Output is correct |
5 |
Correct |
175 ms |
12996 KB |
Output is correct |
6 |
Correct |
173 ms |
13028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
13104 KB |
Output is correct |
2 |
Correct |
172 ms |
12984 KB |
Output is correct |
3 |
Correct |
183 ms |
13076 KB |
Output is correct |
4 |
Correct |
169 ms |
13088 KB |
Output is correct |
5 |
Correct |
175 ms |
12996 KB |
Output is correct |
6 |
Correct |
173 ms |
13028 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 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 |
168 ms |
11044 KB |
Output is correct |
14 |
Correct |
172 ms |
11012 KB |
Output is correct |
15 |
Correct |
168 ms |
11028 KB |
Output is correct |
16 |
Correct |
170 ms |
11028 KB |
Output is correct |
17 |
Correct |
255 ms |
12492 KB |
Output is correct |
18 |
Correct |
248 ms |
12496 KB |
Output is correct |
19 |
Correct |
257 ms |
12440 KB |
Output is correct |
20 |
Correct |
257 ms |
12496 KB |
Output is correct |
21 |
Correct |
249 ms |
12492 KB |
Output is correct |
22 |
Correct |
252 ms |
12456 KB |
Output is correct |
23 |
Correct |
276 ms |
12532 KB |
Output is correct |
24 |
Correct |
251 ms |
12460 KB |
Output is correct |
25 |
Correct |
174 ms |
13032 KB |
Output is correct |
26 |
Correct |
192 ms |
13156 KB |
Output is correct |
27 |
Correct |
256 ms |
12948 KB |
Output is correct |
28 |
Correct |
275 ms |
12836 KB |
Output is correct |
29 |
Correct |
274 ms |
12800 KB |
Output is correct |
30 |
Correct |
275 ms |
12876 KB |
Output is correct |
31 |
Correct |
269 ms |
12820 KB |
Output is correct |
32 |
Correct |
169 ms |
12492 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |