結果
問題 | No.2809 Sort Query |
ユーザー | hirayuu_yc |
提出日時 | 2024-04-21 20:19:50 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 372 ms
22,280 KB |
testcase_02 | AC | 289 ms
22,412 KB |
testcase_03 | AC | 279 ms
22,088 KB |
testcase_04 | AC | 288 ms
22,204 KB |
testcase_05 | AC | 291 ms
22,412 KB |
testcase_06 | AC | 196 ms
21,136 KB |
testcase_07 | AC | 189 ms
21,056 KB |
testcase_08 | AC | 183 ms
21,004 KB |
testcase_09 | AC | 190 ms
21,028 KB |
testcase_10 | AC | 186 ms
21,008 KB |
testcase_11 | AC | 195 ms
22,196 KB |
testcase_12 | AC | 197 ms
22,236 KB |
testcase_13 | AC | 201 ms
22,360 KB |
testcase_14 | AC | 207 ms
22,236 KB |
testcase_15 | AC | 203 ms
22,364 KB |
testcase_16 | AC | 211 ms
22,240 KB |
testcase_17 | AC | 201 ms
22,236 KB |
testcase_18 | AC | 203 ms
22,240 KB |
testcase_19 | AC | 207 ms
22,240 KB |
testcase_20 | AC | 200 ms
22,232 KB |
testcase_21 | AC | 369 ms
24,540 KB |
testcase_22 | AC | 366 ms
24,540 KB |
testcase_23 | AC | 366 ms
24,536 KB |
testcase_24 | AC | 367 ms
24,664 KB |
testcase_25 | AC | 366 ms
24,448 KB |
testcase_26 | AC | 330 ms
22,796 KB |
testcase_27 | AC | 330 ms
22,684 KB |
testcase_28 | AC | 325 ms
22,796 KB |
testcase_29 | AC | 323 ms
22,876 KB |
testcase_30 | AC | 330 ms
22,920 KB |
testcase_31 | AC | 162 ms
21,064 KB |
testcase_32 | AC | 163 ms
21,196 KB |
testcase_33 | AC | 165 ms
21,004 KB |
testcase_34 | AC | 160 ms
21,108 KB |
testcase_35 | AC | 162 ms
21,028 KB |
testcase_36 | AC | 173 ms
22,104 KB |
testcase_37 | AC | 173 ms
22,368 KB |
testcase_38 | AC | 174 ms
22,236 KB |
testcase_39 | AC | 172 ms
22,236 KB |
testcase_40 | AC | 171 ms
22,240 KB |
testcase_41 | AC | 318 ms
21,028 KB |
testcase_42 | AC | 314 ms
21,152 KB |
testcase_43 | AC | 312 ms
21,132 KB |
testcase_44 | AC | 312 ms
21,056 KB |
testcase_45 | AC | 307 ms
21,136 KB |
testcase_46 | AC | 262 ms
21,264 KB |
testcase_47 | AC | 263 ms
21,136 KB |
testcase_48 | AC | 264 ms
21,132 KB |
testcase_49 | AC | 269 ms
21,132 KB |
testcase_50 | AC | 258 ms
21,132 KB |
testcase_51 | AC | 347 ms
17,292 KB |
testcase_52 | AC | 206 ms
17,420 KB |
testcase_53 | AC | 211 ms
17,544 KB |
testcase_54 | AC | 163 ms
17,420 KB |
testcase_55 | AC | 179 ms
17,424 KB |
testcase_56 | AC | 206 ms
15,884 KB |
testcase_57 | AC | 168 ms
13,256 KB |
testcase_58 | AC | 154 ms
13,376 KB |
testcase_59 | AC | 166 ms
13,132 KB |
testcase_60 | AC | 198 ms
16,448 KB |
testcase_61 | AC | 259 ms
19,564 KB |
testcase_62 | AC | 165 ms
13,324 KB |
testcase_63 | AC | 224 ms
16,680 KB |
testcase_64 | AC | 295 ms
20,940 KB |
testcase_65 | AC | 159 ms
14,364 KB |
testcase_66 | AC | 2 ms
5,376 KB |
testcase_67 | AC | 2 ms
5,376 KB |
testcase_68 | AC | 2 ms
5,376 KB |
testcase_69 | AC | 1 ms
5,376 KB |
testcase_70 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
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"; } } } }