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 arr[500005];
int period[500005];
struct group{ int period, L, R; };
vector<group> G;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
for(int i = 1;i <= n;i++) cin >> arr[i];
period[0] = 1;
for(int i = 1;i <= n;i++){
int times = arr[i] / period[i-1];
if(arr[i] % period[i-1] != 0) times++;
period[i] = times * period[i-1];
}
int curR = 0;
for(int i = 0;i <= n;i++){
if(i == n || period[i] != period[i+1]){
G.push_back({period[i], -i, -curR});
curR = i+1;
}
}
while(q--){
int t, l, r; cin >> t >> l >> r;
int ans = 0;
for(group g : G){
int move = t / g.period;
int L = g.L + move * g.period;
int R = g.R + move * g.period;
///l, r are the query range. L, R are the range of people
ans += max(0,min({r-l, R-L, R-l, r-L})+1); ///overlap of the 2 ranges
}
cout << ans << "\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... |