//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 int ii;
using namespace std;
constexpr ii xn = 5e5 + 5;
ii d[xn];
ii 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 'ii 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;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
475 ms |
20684 KB |
Output is correct |
2 |
Correct |
507 ms |
20664 KB |
Output is correct |
3 |
Correct |
485 ms |
20628 KB |
Output is correct |
4 |
Correct |
477 ms |
20636 KB |
Output is correct |
5 |
Correct |
471 ms |
20700 KB |
Output is correct |
6 |
Correct |
500 ms |
20644 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
475 ms |
20684 KB |
Output is correct |
2 |
Correct |
507 ms |
20664 KB |
Output is correct |
3 |
Correct |
485 ms |
20628 KB |
Output is correct |
4 |
Correct |
477 ms |
20636 KB |
Output is correct |
5 |
Correct |
471 ms |
20700 KB |
Output is correct |
6 |
Correct |
500 ms |
20644 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 |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Runtime error |
49 ms |
9340 KB |
Execution killed with signal 8 |
14 |
Halted |
0 ms |
0 KB |
- |