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
const int N = 5e5 + 5;
int d[N];
int n, q;
int get(int T,int P) {
int l = 0;
int r = n + 1;
for(; l < r ;) {
int m = (l + r) / 2;
if (T / d[m] * d[m] < P + m)
r = m;
else
l = m + 1;
}
return l;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
d[0] = 1;
for(int i = 1 ; i <= n ; ++i) {
int x; cin >> x;
int k = (d[i - 1] + x - 1) / d[i - 1];
d[i] = k * d[i - 1];
}
for(int i = 1 ; i <= q ; ++i) {
int T; cin >> T;
int l; cin >> l;
int r; cin >> r;
cout << get(T,l) - get(T,r + 1) << "\n";
}
}
/*
3 6
2
5
3
1 2 4
2 2 4
3 2 4
4 2 4
5 2 4
6 2 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |