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>
#define MAXN 500007
using namespace std;
struct qr{
int t,l,r,id;
inline friend bool operator < (qr fr,qr sc){
return fr.t<sc.t;
}
};
int n,q,t,l,r,tim,ans[MAXN],d[MAXN],pos[MAXN];
qr query[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>d[i];
pos[i]=-i;
}
for(int i=1;i<=q;i++){
cin>>t>>l>>r;
query[i]={t,l,r,i};
}
sort(query+1,query+q+1);
for(int i=1;i<=q;i++){
while(tim<query[i].t){
tim++; pos[0]++;
for(int f=1;f<=n;f++){
if(pos[f-1]-pos[f]>=d[f]+1){
pos[f]=pos[f-1]-1;
}else break;
}
}
for(int f=0;f<=n;f++){
if(pos[f]>=query[i].l and pos[f]<=query[i].r)ans[query[i].id]++;
}
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<"\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... |