signedmain(){ ios; int n,m,K; cin>>n>>m; K = sqrt(n); deque<int> deq[n/K+(m/K)+10]; for(int i=0;i<n;i++){ int temp;cin>>temp; deq[i/K].push_back(temp); } for(int i=0;i<m;i++){ string a;cin>>a; if(a[0]=='A'){ int x,y;cin>>y>>x;y--; deq[y/K].insert(deq[y/K].begin()+(y%K), x); int len = deq[y/K].size(),cur = y/K; while(len>K){ int temp = deq[cur].back(); deq[cur].pop_back(); cur++; deq[cur].push_front(temp); len = deq[cur].size(); } } elseif(a[0]=='L'){ int x;cin>>x;x--; deq[x/K].erase(deq[x/K].begin()+(x%K)); int len = deq[x/K].size(),cur = x/K; while(len<K && deq[cur+1].size()!=0){ int temp = deq[cur+1].front(); deq[cur+1].pop_front(); deq[cur].push_back(temp); cur++; len = deq[cur].size(); } } elseif(a[0]=='Q'){ int x;cin>>x;x--; int len = x%K; auto it = deq[x/K].begin(); cout<<*(it+len)<<endl; } } }
#include<bits/stdc++.h> #define int long long #define ios ios::sync_with_stdio(0),cin.tie(0) #define N 100005 usingnamespace std; //值域分塊 constint K = 100;
signedmain(){ ios; int q,arr[N],mn[N/K+10];cin>>q; memset(arr, 0, sizeof(arr)); while(q--){ int temp;cin>>temp; if(temp==1){ int x,y;cin>>x>>y; arr[x]+=y; mn[x/K]+=y; } elseif(temp==2){ int x,y;cin>>x>>y; arr[x]-=y; mn[x/K]-=y; } elseif(temp==3){ int z,sum = 0,ind=0;cin>>z; //ind查詢位於第幾塊 while(sum+mn[ind]<z)sum+=mn[ind++]; int cur_ind = ind*K; for(int i=0;i<=K;i++){ if(arr[cur_ind+i]){ sum+=arr[cur_ind+i]; if(sum>=z){ cout<<ind*K+i<<endl; break; } } } } } }