結果
問題 | No.2809 Sort Query |
ユーザー |
![]() |
提出日時 | 2024-07-01 17:18:07 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,697 bytes |
コンパイル時間 | 2,690 ms |
コンパイル使用メモリ | 217,560 KB |
実行使用メモリ | 221,160 KB |
最終ジャッジ日時 | 2024-07-12 21:07:32 |
合計ジャッジ時間 | 12,877 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 TLE * 1 -- * 69 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long struct SEG{ private: int n; unordered_map<int,int> m; public: SEG(){ n = (1ll<<60); } void add(int a, int w) { for (int x = a; x < n; x |= x + 1) { m[x] += w; } } int f(int k){ k--; int l = 0, now = (1ll<<59)-1, s = 0; for(int i=58;i>=0;i--){ if(s+m[now] <= k){ s += m[now]; l += (1ll<<(i+1)); now += (1ll<<(i+1)); } now -= (1ll<<i); } if(s+m[now] <= k) l++; return l; } }; signed main(){ int N,Q; cin>>N>>Q; vector<int> A(N); for(int i=0;i<N;i++) cin>>A[i]; while(Q--){ int t; cin>>t; if(t == 1){ int a,b; cin>>a>>b; A[a-1] = b; } else if(t == 2){ sort(A.begin(),A.end()); break; } else{ int a; cin>>a; cout<<A[a-1]<<endl; } } SEG seg; unordered_map<int,int> m; for(int i=0;i<N;i++) seg.add(A[i],1); while(Q--){ int t; cin>>t; if(t == 1){ int a,b; cin>>a>>b; m[a-1] = b; } else if(t == 2){ unordered_map<int,int> mm; for(auto [a,b]:m){ seg.add(A[a],-1); seg.add(b,1); A[a] = b; } m = mm; } else{ int a; cin>>a; if(m.count(a-1)) cout<<m[a-1]<<endl; else cout<<seg.f(a)<<endl; } } }