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);
long long n,q,a,b,t;
cin >> n >> q;
vector<long long> haha(n+1,1);
for(long long i = 1; i <= n; i++) {
cin >> haha[i];
haha[i] = haha[i-1]*((haha[i]+haha[i-1]-1)/haha[i-1]);
haha[i] = min(haha[i],(long long)INT_MAX);
}
for(long long i = 0; i < q; i++) {
cin >> t >> a >> b;
long long c = a,ans = 0;
if(t >= c) {
long long l = 0,r = haha.size()-1;
while(l < r) {
long long 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) {
long long l = 0,r = haha.size()-1;
while(l < r) {
long long 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... |