Submission #972325

#TimeUsernameProblemLanguageResultExecution timeMemory
972325LCJLYWorst Reporter 3 (JOI18_worst_reporter3)C++14
12 / 100
28 ms17488 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl; typedef pair<long long,long long>pii; typedef pair<int,pii>pi2; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); void solve(){ int n,q; cin >> n >> q; int arr[n]; int pos[n]; for(int x=1;x<=n;x++){ cin >> arr[x]; pos[x]=-x; } pos[0]=0; vector<pair<pii,int>>que[1005]; int temp,temp2,temp3; for(int x=0;x<q;x++){ cin >> temp >> temp2 >> temp3; que[temp].push_back({{temp2,temp3},x}); } int ans[1005]; for(int x=1;x<1005;x++){ pos[0]++; for(int y=1;y<=n;y++){ if(abs(pos[y]-pos[y-1])>=arr[y]+1){ pos[y]=pos[y-1]-1; } } for(auto it:que[x]){ int l=it.first.first; int r=it.first.second; int index=it.second; reverse(pos,pos+n+1); int hold=lower_bound(pos,pos+1+n,l)-(pos+1); int hold2=upper_bound(pos,pos+1+n,r)-(pos+1); reverse(pos,pos+n+1); ans[index]=hold2-hold; } //for(int y=0;y<=n;y++){ //cout << pos[y] << " "; //} //cout << endl; } for(int x=0;x<q;x++){ cout << ans[x] << "\n"; } } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int t=1; //freopen("in.txt","r",stdin); //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...