This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5+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 (stderr)
worst_reporter3.cpp: In lambda function:
worst_reporter3.cpp:23:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | ll m = l + r >> 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... |