Submission #1163578

#TimeUsernameProblemLanguageResultExecution timeMemory
1163578emptypringlescanSpecijacija (COCI20_specijacija)C++20
0 / 110
275 ms102116 KiB
#include <bits/stdc++.h> using namespace std; const long long buc=350; long long arr[200005],lvl[200005],bruh[200005]; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int n,q,t; cin >> n >> q >> t; vector<int> seg[n/buc+5],snap[n/buc+5]; for(int i=0; i<n; i++){ cin >> arr[i]; lvl[i]=arr[i]-(long long)i*(i+1)/2ll; bruh[i]=(long long)i*(i+1)/2ll; } bruh[n]=(long long)n*(n+1)/2ll; for(int i=0; i<n/buc; i++){ int st=i*buc,en=min((i+1)*buc-1,(long long)n-1); int cur=0; for(int j=1; j<=st+1; j++){ seg[cur].push_back(j); if((int)seg[cur].size()>=buc) cur++; } for(int j=st; j<=en; j++){ int x=lvl[j]; cur=0; while((int)seg[cur].size()<x){ x-=seg[cur].size(); cur++; } int yay=seg[cur][x-1]; seg[cur].push_back(yay); for(int k=(int)seg[cur].size()-2; k>=0; k--){ if(seg[cur][k]==yay) break; swap(seg[cur][k],seg[cur][k+1]); } } for(int j=0; j<=buc; j++){ for(int k:seg[j]){ snap[i].push_back(k); } seg[j].clear(); } } long long prevans=0; const long long mod=(long long)(n+1)*(n+2)/2ll; while(q--){ long long xx,yy; cin >> xx >> yy; long long x=(xx-1+t*prevans)%mod+1; long long y=(yy-1+t*prevans)%mod+1; if(x<y) swap(x,y); int depx=lower_bound(bruh,bruh+n+1,x)-bruh-1; int depy=lower_bound(bruh,bruh+n+1,y)-bruh-1; int lx=x-bruh[depx]; int ly=y-bruh[depy]; while(depx>depy){ if(depx-buc>=depy&&depx%buc==0){ lx=snap[depx/buc-1][lx-1]; depx-=buc; } else{ lx-=(lvl[depx-1]<lx); depx--; } } //cout << lx << ' ' << depx << ' ' << ly << ' ' << depy << '\n'; if(lx==ly){ prevans=bruh[depx]+lx; cout << bruh[depx]+lx << '\n'; continue; } while(lx!=ly){ //cout << lx << ' ' << ly << '\n'; int nx,ny; if(depx%buc==0){ nx=snap[depx/buc-1][lx-1]; ny=snap[depy/buc-1][ly-1]; if(nx!=ny){ depx-=buc; depy-=buc; lx=nx; ly=ny; continue; } } lx-=(lvl[depx-1]<lx); ly-=(lvl[depy-1]<ly); depx--; depy--; } prevans=bruh[depx]+lx; cout << bruh[depx]+lx << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...