# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 5e5 + 5;
int t,n,a[N], q, per[N], d[N];
int get_pos(int x, int tm) {
return (tm / per[x]) * per[x] - x;
}
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>q;
for (int i = 1; i <= n; i++) {
cin>>d[i];
}
per[0] = 1; per[1] = d[1];
for (int i = 2; i <= n; i++) {
per[i] = (d[i] + per[i - 1] - 1) / per[i - 1] * per[i - 1];
}
while (q--) {
int t, l, r;
cin>>t>>l>>r;
int le = 0, ri = n, ans = -1, ans1 = n + 1;
while (le <= ri) {
int mid = (le + ri) / 2;
if (get_pos(mid, t) >= l) {
ans = mid;
le = mid + 1;
} else ri = mid - 1;
}
le = 0, ri = n;
while (le <= ri) {
int mid = (le + ri) / 2;
if (get_pos(mid, t) <= r) {
ans1 = mid; ri = mid - 1;
} else le = mid + 1;
}
cout<<max(ans - ans1 + 1, 0LL)<<"\n";
}
}
Compilation message
worst_reporter3.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
26588 KB |
Output is correct |
2 |
Correct |
543 ms |
26604 KB |
Output is correct |
3 |
Correct |
528 ms |
26792 KB |
Output is correct |
4 |
Correct |
527 ms |
26620 KB |
Output is correct |
5 |
Correct |
555 ms |
26604 KB |
Output is correct |
6 |
Correct |
570 ms |
26528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
344 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 |
556 ms |
26588 KB |
Output is correct |
2 |
Correct |
543 ms |
26604 KB |
Output is correct |
3 |
Correct |
528 ms |
26792 KB |
Output is correct |
4 |
Correct |
527 ms |
26620 KB |
Output is correct |
5 |
Correct |
555 ms |
26604 KB |
Output is correct |
6 |
Correct |
570 ms |
26528 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
323 ms |
25036 KB |
Output is correct |
14 |
Correct |
350 ms |
25692 KB |
Output is correct |
15 |
Correct |
311 ms |
24356 KB |
Output is correct |
16 |
Correct |
347 ms |
24816 KB |
Output is correct |
17 |
Correct |
425 ms |
29152 KB |
Output is correct |
18 |
Correct |
408 ms |
29124 KB |
Output is correct |
19 |
Correct |
403 ms |
29216 KB |
Output is correct |
20 |
Correct |
444 ms |
29076 KB |
Output is correct |
21 |
Correct |
454 ms |
29196 KB |
Output is correct |
22 |
Correct |
394 ms |
29220 KB |
Output is correct |
23 |
Correct |
429 ms |
29076 KB |
Output is correct |
24 |
Correct |
383 ms |
29356 KB |
Output is correct |
25 |
Correct |
517 ms |
26588 KB |
Output is correct |
26 |
Correct |
520 ms |
26656 KB |
Output is correct |
27 |
Correct |
437 ms |
28704 KB |
Output is correct |
28 |
Correct |
439 ms |
29076 KB |
Output is correct |
29 |
Correct |
461 ms |
28528 KB |
Output is correct |
30 |
Correct |
439 ms |
28724 KB |
Output is correct |
31 |
Correct |
448 ms |
28972 KB |
Output is correct |
32 |
Correct |
447 ms |
25224 KB |
Output is correct |
33 |
Correct |
0 ms |
324 KB |
Output is correct |