結果
問題 | No.2809 Sort Query |
ユーザー |
|
提出日時 | 2024-04-21 20:19:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 372 ms / 2,000 ms |
コード長 | 2,667 bytes |
コンパイル時間 | 3,912 ms |
コンパイル使用メモリ | 272,652 KB |
実行使用メモリ | 24,664 KB |
最終ジャッジ日時 | 2024-07-12 20:58:22 |
合計ジャッジ時間 | 31,184 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 71 |
コンパイルメッセージ
In constructor 'FenwickTree::FenwickTree(int)', inlined from 'int main()' at main.cpp:60:31: main.cpp:11:9: warning: 'a.FenwickTree::size' may be used uninitialized [-Wmaybe-uninitialized] 11 | size+=sz; | ^~~~ main.cpp: In function 'int main()': main.cpp:60:17: note: 'a' declared here 60 | FenwickTree a(press.size()); | ^
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(x) x.begin(),x.end() using ll=long long; struct FenwickTree{ vector<int> tree; int size; int start; FenwickTree(int sz){ size+=sz; tree.resize(size+1); start=0; while((1<<(start+1))<=size)start++; } void add(int pos,int val){ pos++; while(pos<=size){ tree[pos]+=val; pos+=pos&-pos; } } int bisect(int pos){ int now=0; int val=0; for(int i=start; i>=0; i--){ if(now+(1<<i)<=size&&val+tree[now+(1<<i)]<=pos){ now+=1<<i; val+=tree[now]; } } return now; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin>>N>>Q; vector<ll> A(N); vector<ll> press; rep(i,N){ cin>>A[i]; press.emplace_back(A[i]); } vector<tuple<int,int,ll>> query(Q); rep(i,Q){ cin>>get<0>(query[i]); switch(get<0>(query[i])){ case 3: cin>>get<1>(query[i]); break; case 1: cin>>get<1>(query[i])>>get<2>(query[i]); press.emplace_back(get<2>(query[i])); } } sort(all(press)); press.erase(unique(all(press)),press.end()); FenwickTree a(press.size()); rep(i,Q){ if(get<0>(query[i])==1){ get<2>(query[i])=lower_bound(all(press),get<2>(query[i]))-press.begin(); } } vector<ll> change(N,-1); stack<pair<ll,ll>> chq; stack<int> upd; rep(i,N){ A[i]=lower_bound(all(press),A[i])-press.begin(); change[i]=A[i]; upd.push(i); } a.add(0,N); rep(i,Q){ int t=get<0>(query[i]); if(t==1){ int k;int x; tie(ignore,k,x)=query[i]; change[k-1]=x; upd.push(k-1); } if(t==2){ while(!upd.empty()){ if(change[upd.top()]!=-1){ chq.push({a.bisect(upd.top()),change[upd.top()]}); change[upd.top()]=-1; } upd.pop(); } while(!chq.empty()){ a.add(chq.top().first,-1); a.add(chq.top().second,1); chq.pop(); } } if(t==3){ int x=get<1>(query[i]); if(change[x-1]!=-1){ cout<<press[change[x-1]]<<"\n"; } else{ cout<<press[a.bisect(x-1)]<<"\n"; } } } }