#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 5;
int d[N], n, q;
int solveTestCase() {
cin >> n >> q;
d[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> d[i];
d[i] = d[i] / d[i - 1] * d[i - 1] + (d[i] % d[i - 1] ? d[i - 1] : 0);
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
int low = 0, high = n, ans1 = n + 1, ans2 = n + 1;
while (low <= high) {
int mid = (low + high) / 2;
int val = -mid + t / d[mid] * d[mid];
if (-mid + t / d[mid] * d[mid] <= r)
high = mid - 1, ans1 = mid;
else
low = mid + 1;
}
low = 0, high = n;
while (low <= high) {
int mid = (low + high) / 2;
int val = -mid + t / d[mid] * d[mid];
if (-mid + t / d[mid] * d[mid] < l)
high = mid - 1, ans2 = mid;
else
low = mid + 1;
}
cout << ans2 - ans1 << "\n";
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
// cin >> test;
while (test--)
solveTestCase();
}
Compilation message
worst_reporter3.cpp: In function 'long long int solveTestCase()':
worst_reporter3.cpp:23:17: warning: unused variable 'val' [-Wunused-variable]
23 | int val = -mid + t / d[mid] * d[mid];
| ^~~
worst_reporter3.cpp:33:17: warning: unused variable 'val' [-Wunused-variable]
33 | int val = -mid + t / d[mid] * d[mid];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
617 ms |
22776 KB |
Output is correct |
2 |
Correct |
616 ms |
22904 KB |
Output is correct |
3 |
Correct |
593 ms |
22808 KB |
Output is correct |
4 |
Correct |
593 ms |
22904 KB |
Output is correct |
5 |
Correct |
605 ms |
22776 KB |
Output is correct |
6 |
Correct |
596 ms |
22776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
617 ms |
22776 KB |
Output is correct |
2 |
Correct |
616 ms |
22904 KB |
Output is correct |
3 |
Correct |
593 ms |
22808 KB |
Output is correct |
4 |
Correct |
593 ms |
22904 KB |
Output is correct |
5 |
Correct |
605 ms |
22776 KB |
Output is correct |
6 |
Correct |
596 ms |
22776 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
384 ms |
21284 KB |
Output is correct |
14 |
Correct |
373 ms |
21884 KB |
Output is correct |
15 |
Correct |
354 ms |
20600 KB |
Output is correct |
16 |
Correct |
398 ms |
21164 KB |
Output is correct |
17 |
Correct |
503 ms |
25336 KB |
Output is correct |
18 |
Correct |
445 ms |
25264 KB |
Output is correct |
19 |
Correct |
457 ms |
25520 KB |
Output is correct |
20 |
Correct |
462 ms |
25336 KB |
Output is correct |
21 |
Correct |
457 ms |
25336 KB |
Output is correct |
22 |
Correct |
458 ms |
25336 KB |
Output is correct |
23 |
Correct |
444 ms |
25208 KB |
Output is correct |
24 |
Correct |
445 ms |
25464 KB |
Output is correct |
25 |
Correct |
595 ms |
22776 KB |
Output is correct |
26 |
Correct |
601 ms |
22672 KB |
Output is correct |
27 |
Correct |
511 ms |
24824 KB |
Output is correct |
28 |
Correct |
504 ms |
25208 KB |
Output is correct |
29 |
Correct |
506 ms |
24852 KB |
Output is correct |
30 |
Correct |
501 ms |
24972 KB |
Output is correct |
31 |
Correct |
501 ms |
25336 KB |
Output is correct |
32 |
Correct |
474 ms |
21496 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |