Submission #1011672

#TimeUsernameProblemLanguageResultExecution timeMemory
1011672snpmrnhlolWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
577 ms34960 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e5; int v[N]; array <int,3> trains[N + 1]; struct query{ int t,l,r,id; }q2[N]; int ans[N]; int main(){ int n,q; cin>>n>>q; for(int i = 0;i < n;i++){ cin>>v[i]; if(i){ if(v[i]%v[i - 1] == 0){ v[i] = v[i]/v[i - 1]*v[i - 1]; }else{ v[i] = v[i]/v[i - 1]*v[i - 1] + v[i - 1]; } } } int cnt = 0; trains[cnt++] = {0,0,1}; int nr = 0; for(int i = 0;i < n;i++){ if(i && v[i] != v[i - 1]){ trains[cnt++] = {-i,-i + nr - 1,v[i - 1]}; nr = 1; }else nr++; } trains[cnt++] = {-n,-n + nr - 1,v[n - 1]}; ///l,r,jumppower for(int i = 0;i < q;i++){ cin>>q2[i].t>>q2[i].l>>q2[i].r; q2[i].id = i; } sort(q2,q2 + q,[&](query a,query b){ return a.t < b.t; }); int timp = 0; for(int i = 0;i < q;i++){ trains[0][0]+=q2[i].t - timp; trains[0][1]+=q2[i].t - timp; for(int j = 1;j < cnt;j++){ if(trains[j][1] < trains[j - 1][0] - trains[j][2]){ int sum = (trains[j - 1][0] - trains[j][1] - 1)/trains[j][2]; trains[j][0]+=sum*trains[j][2]; trains[j][1]+=sum*trains[j][2]; } } //cout<<q2[i].t<<'\n'; int score = 0; for(int j = 0;j < cnt;j++){ //cout<<trains[j][0]<<' '<<trains[j][1]<<' '<<trains[j][2]<<'\n'; score+=max(0,min(q2[i].r,trains[j][1]) - max(q2[i].l,trains[j][0]) + 1); } ans[q2[i].id] = score; timp = q2[i].t; } for(int i = 0;i < q;i++){ cout<<ans[i]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...