#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 5e5+10;
ll d[N], t[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
ll n, q;
cin >> n >> q;
for(int i = 1; i <= n; ++i) {
cin >> d[i];
}
t[0] = 1;
for(int i = 1; i <= n; ++i) {
t[i] = (d[i]+t[i-1]-1) / t[i-1] * t[i-1];
}
auto coord = [&](ll x, ll time) -> ll {
return -x + time / t[x] * t[x];
};
auto query = [&](ll x, ll t) -> ll {
ll l = 0, r = n, ans = n+1;
while(r >= l) {
ll m = l + r >> 1;
if(coord(m, t) <= x) {
r = m - 1;
ans = m;
} else {
l = m + 1;
}
}
return n - ans + 1;
};
for(int i = 0; i < q; ++i) {
ll t, l, r;
cin >> t >> l >> r;
cout << query(r, t) - query(l - 1, t) << '\n';
}
}
Compilation message
worst_reporter3.cpp: In lambda function:
worst_reporter3.cpp:23:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | ll m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
25920 KB |
Output is correct |
2 |
Correct |
600 ms |
26564 KB |
Output is correct |
3 |
Correct |
594 ms |
26568 KB |
Output is correct |
4 |
Correct |
600 ms |
26560 KB |
Output is correct |
5 |
Correct |
595 ms |
26680 KB |
Output is correct |
6 |
Correct |
602 ms |
26564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
25920 KB |
Output is correct |
2 |
Correct |
600 ms |
26564 KB |
Output is correct |
3 |
Correct |
594 ms |
26568 KB |
Output is correct |
4 |
Correct |
600 ms |
26560 KB |
Output is correct |
5 |
Correct |
595 ms |
26680 KB |
Output is correct |
6 |
Correct |
602 ms |
26564 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
369 ms |
25184 KB |
Output is correct |
14 |
Correct |
379 ms |
25584 KB |
Output is correct |
15 |
Correct |
360 ms |
24280 KB |
Output is correct |
16 |
Correct |
362 ms |
24924 KB |
Output is correct |
17 |
Correct |
454 ms |
29252 KB |
Output is correct |
18 |
Correct |
455 ms |
29124 KB |
Output is correct |
19 |
Correct |
450 ms |
29108 KB |
Output is correct |
20 |
Correct |
461 ms |
29136 KB |
Output is correct |
21 |
Correct |
452 ms |
29144 KB |
Output is correct |
22 |
Correct |
457 ms |
29380 KB |
Output is correct |
23 |
Correct |
451 ms |
28996 KB |
Output is correct |
24 |
Correct |
459 ms |
29184 KB |
Output is correct |
25 |
Correct |
588 ms |
26508 KB |
Output is correct |
26 |
Correct |
588 ms |
26564 KB |
Output is correct |
27 |
Correct |
495 ms |
28660 KB |
Output is correct |
28 |
Correct |
483 ms |
29116 KB |
Output is correct |
29 |
Correct |
487 ms |
28484 KB |
Output is correct |
30 |
Correct |
492 ms |
28612 KB |
Output is correct |
31 |
Correct |
496 ms |
28904 KB |
Output is correct |
32 |
Correct |
472 ms |
25080 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |