이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |