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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q; cin>>n>>q;
int d[n + 1];
for (int i = 1; i <= n; i++){
cin>>d[i];
}
int k[n + 1];
k[0] = 0; k[1] = d[1];
for (int i = 2; i <= n; i++){
k[i] = ceil(1.0 * d[i] / k[i - 1]) * k[i - 1];
}
int all[n + 1], S = 0;
for (int i = 1; i <= n; i++){
if (k[i] != k[i - 1]){
all[++S] = i;
}
}
all[++S] = n + 1;
while (q--){
int t, l, r, L, R; cin>>t>>l>>r;
int out = (l <= t && t <= r), p = t - 1;
for (int i = 1; i + 1 <= S; i++){
L = all[i]; R = all[i + 1] - 1;
int f = (p + L) / k[L], l1 = max(l, f * k[L] - R), r1 = min(r, f * k[L] - L);
out += max(0, (r1 - l1 + 1));
p = (f * k[L] - R) - 1;
}
cout<<out<<"\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... |