//InTheNameOfGOD
//PRS;)
#pragma GCC optimize("unroll-loops", "O2", "Ofast", "O3")
#pragma GCC target("avx2", "sse", "sse2")
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for(ii i = l; i < r; i++)
#define max(x, y) (x > y ? x : y)
typedef long long ii;
using namespace std;
constexpr int xn = 5e5 + 5;
ii d[xn];
int main()
{
Fast;
ii n, q;
cin >> n >> q;
rep(i, 0, n) cin >> d[i];
rep(i, 1, n) d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1];
while(q--)
{
ii t, l, r, p1 = 0, p2 = n, p3 = 0, p4 = n;
cin >> t >> l >> r;
while(p1 < p2)
{
ii m = p1 + p2 >> 1;
if((t / d[m]) * d[m] - m - 1 < l) p2 = m;
else p1 = m + 1;
}
while(p3 < p4)
{
ii m = p3 + p4 >> 1;
if((t / d[m]) * d[m] - m - 1 > r) p3 = m + 1;
else p4 = m;
}
ii ans = max(0, p1 - p4);
if(l <= t && t <= r) ans++;
cout << ans << '\n';
}
}
Compilation message
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:26:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | ii m = p1 + p2 >> 1;
| ~~~^~~~
worst_reporter3.cpp:32:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | ii m = p3 + p4 >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
476 ms |
7232 KB |
Output is correct |
2 |
Correct |
484 ms |
7332 KB |
Output is correct |
3 |
Correct |
469 ms |
7284 KB |
Output is correct |
4 |
Correct |
497 ms |
7472 KB |
Output is correct |
5 |
Correct |
483 ms |
7268 KB |
Output is correct |
6 |
Correct |
480 ms |
7152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
476 ms |
7232 KB |
Output is correct |
2 |
Correct |
484 ms |
7332 KB |
Output is correct |
3 |
Correct |
469 ms |
7284 KB |
Output is correct |
4 |
Correct |
497 ms |
7472 KB |
Output is correct |
5 |
Correct |
483 ms |
7268 KB |
Output is correct |
6 |
Correct |
480 ms |
7152 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 |
292 ms |
16172 KB |
Output is correct |
14 |
Correct |
303 ms |
21764 KB |
Output is correct |
15 |
Correct |
276 ms |
20440 KB |
Output is correct |
16 |
Correct |
290 ms |
20916 KB |
Output is correct |
17 |
Correct |
374 ms |
25264 KB |
Output is correct |
18 |
Correct |
365 ms |
25164 KB |
Output is correct |
19 |
Correct |
371 ms |
25228 KB |
Output is correct |
20 |
Correct |
372 ms |
25144 KB |
Output is correct |
21 |
Correct |
368 ms |
25220 KB |
Output is correct |
22 |
Correct |
369 ms |
25320 KB |
Output is correct |
23 |
Correct |
375 ms |
25148 KB |
Output is correct |
24 |
Correct |
360 ms |
25300 KB |
Output is correct |
25 |
Correct |
493 ms |
22652 KB |
Output is correct |
26 |
Correct |
488 ms |
22732 KB |
Output is correct |
27 |
Correct |
415 ms |
24840 KB |
Output is correct |
28 |
Correct |
405 ms |
25140 KB |
Output is correct |
29 |
Correct |
408 ms |
24740 KB |
Output is correct |
30 |
Correct |
408 ms |
24848 KB |
Output is correct |
31 |
Correct |
408 ms |
25004 KB |
Output is correct |
32 |
Correct |
419 ms |
21240 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |