This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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 (stderr)
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;
| ~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |