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>
using namespace std;
#define int long long
#define INF 1000000000000000000
#define MOD 998244353
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q, t, l, r;
cin >> n >> q;
int a[n+1];
a[0] = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = (a[i]+a[i-1]-1)/a[i-1]*a[i-1];
}
while(q--) {
cin >> t >> l >> r;
int L = 0, R = n+1, m;
while(L < R) {
m = (L+R)/2;
int pos = -m+t/a[m]*a[m];
if(pos > r) L = m+1;
else R = m;
}
int rpos = L;
L = 0; R = n+1;
while(L < R) {
m = (L+R)/2;
int pos = -m+t/a[m]*a[m];
if(pos >= l) L = m+1;
else R = m;
}
int lpos = L;
cout << lpos-rpos << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |