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;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,q,a,b,t;
cin >> n >> q;
vector<int> haha(n+1,1);
for(int i = 1; i <= n; i++) {
cin >> haha[i];
haha[i] = haha[i-1]*((haha[i]+haha[i-1]-1)/haha[i-1]);
}
for(int i = 0; i < q; i++) {
cin >> t >> a >> b;
int c = a,ans = 0;
if(t >= c) {
int l = 0,r = haha.size()-1;
while(l < r) {
int mid = (l+r+1)/2;
if(-mid+haha[mid]*(t/haha[mid]) >= c) {
l = mid;
}
else {
r = mid-1;
}
}
ans+=l+1;
}
c = b+1;
if(t >= c) {
int l = 0,r = haha.size()-1;
while(l < r) {
int mid = (l+r+1)/2;
if(-mid+haha[mid]*(t/haha[mid]) >= c) {
l = mid;
}
else {
r = mid-1;
}
}
ans-=l+1;
}
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |