結果
問題 | No.2809 Sort Query |
ユーザー | GOTKAKO |
提出日時 | 2024-07-12 22:39:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,459 bytes |
コンパイル時間 | 3,142 ms |
コンパイル使用メモリ | 226,280 KB |
実行使用メモリ | 31,240 KB |
最終ジャッジ日時 | 2024-07-12 22:40:11 |
合計ジャッジ時間 | 34,913 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 247 ms
24,144 KB |
testcase_12 | AC | 235 ms
24,168 KB |
testcase_13 | WA | - |
testcase_14 | AC | 240 ms
24,080 KB |
testcase_15 | AC | 242 ms
24,268 KB |
testcase_16 | AC | 238 ms
24,284 KB |
testcase_17 | AC | 240 ms
24,312 KB |
testcase_18 | AC | 231 ms
24,276 KB |
testcase_19 | AC | 228 ms
24,228 KB |
testcase_20 | AC | 227 ms
24,308 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 187 ms
21,804 KB |
testcase_32 | AC | 193 ms
22,116 KB |
testcase_33 | AC | 186 ms
21,880 KB |
testcase_34 | AC | 188 ms
21,828 KB |
testcase_35 | AC | 191 ms
21,864 KB |
testcase_36 | AC | 188 ms
24,352 KB |
testcase_37 | AC | 190 ms
24,188 KB |
testcase_38 | AC | 196 ms
24,212 KB |
testcase_39 | AC | 209 ms
24,352 KB |
testcase_40 | AC | 377 ms
24,284 KB |
testcase_41 | AC | 441 ms
21,372 KB |
testcase_42 | AC | 423 ms
21,412 KB |
testcase_43 | AC | 413 ms
21,420 KB |
testcase_44 | AC | 437 ms
21,408 KB |
testcase_45 | AC | 399 ms
21,372 KB |
testcase_46 | AC | 372 ms
21,340 KB |
testcase_47 | AC | 351 ms
21,304 KB |
testcase_48 | AC | 344 ms
21,348 KB |
testcase_49 | AC | 383 ms
21,352 KB |
testcase_50 | AC | 353 ms
21,372 KB |
testcase_51 | AC | 454 ms
21,404 KB |
testcase_52 | AC | 275 ms
21,348 KB |
testcase_53 | AC | 321 ms
21,476 KB |
testcase_54 | AC | 274 ms
21,264 KB |
testcase_55 | AC | 249 ms
21,368 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int> zaatu(vector<int> &A){ vector<int> B = A; sort(B.begin(),B.end()); B.erase(unique(B.begin(),B.end()),B.end()); for(auto &a : A) a = lower_bound(B.begin(),B.end(),a)-B.begin(); return B; } vector<long long> zaatull(vector<long long> &A){ vector<long long> B = A; sort(B.begin(),B.end()); B.erase(unique(B.begin(),B.end()),B.end()); return B; } using SS = int; class SegmentTree{ public: int siz = 1,n; vector<SS> dat; SS op(SS a, SS b){return a+b;} SS e(){return 0;} void renew (SS &a,SS x){ a = op(a,x); //a = x; //その他. } void make(int N){ while(siz < N) siz *= 2; n = N; dat.resize(siz*2,e()); } void make2(int N,vector<SS> &A){ make(N); for(int i=0; i<N; i++){ int pos = i+siz; dat.at(pos) = A.at(i); } for(int i=siz-1; i>0; i--) dat.at(i) = op(dat.at(i*2),dat.at(i*2+1)); } void update(int pos,SS x){ pos = pos+siz; renew(dat.at(pos),x); while(pos != 1){ pos = pos/2; dat.at(pos) = op(dat.at(pos*2),dat.at(pos*2+1)); } } SS findans(int l, int r){ SS retl = e(),retr = e(); l += siz,r += siz; while(l < r){ if(l&1) retl = op(retl,dat.at(l++)); if(r&1) retr = op(dat.at(--r),retr); l >>= 1; r >>= 1; } return op(retl,retr); } SS get(int pos){return dat.at(pos+siz);} SS rangeans(int l, int r){return findans(l,r);} SS allrange(){return dat.at(1);} //rightは) leftは[で 渡す&返す. int maxright(const function<bool(SS)> f,int l = 0){ l += siz; int r = n+siz; vector<int> ls,rs; while(l < r){ if(l&1) ls.push_back(l++); if(r&1) rs.push_back(--r); l >>= 1; r >>= 1; } SS okl = e(); for(int i=0; i<ls.size(); i++){ l = ls.at(i); SS now = op(okl,dat.at(l)); if(!f(now)){ while(l < siz){ l <<= 1; now = op(okl,dat.at(l)); if(f(now)){okl = now; l++;} } return l-siz; } okl = now; } for(int i=rs.size()-1; i>=0; i--){ l = rs.at(i); SS now = op(okl,dat.at(l)); if(!f(now)){ while(l < siz){ l <<= 1; now = op(okl,dat.at(l)); if(f(now)){okl = now; l++;} } return l-siz; } okl = now; } return n; } int minleft(const function<bool(SS)> f,int r = -1){ if(r == -1) r = n; int l = siz; r += siz; vector<int> ls,rs; while(l < r){ if(l&1) ls.push_back(l++); if(r&1) rs.push_back(--r); l >>= 1; r >>= 1; } SS okr = e(); for(int i=0; i<rs.size(); i++){ r = rs.at(i); SS now = op(dat.at(r),okr); if(!f(now)){ while(r < siz){ r <<= 1; r++; now = op(dat.at(r),okr); if(f(now)){okr = now; r--;} } return r+1-siz; } } for(int i=ls.size()-1; i>=0; i--){ r = ls.at(i); SS now = op(dat.at(r),okr); if(!f(now)){ while(r < siz){ r <<= 1; r++; now = op(dat.at(r),okr); if(f(now)){okr = now; r--;} } return r+1-siz; } } return 0; } //ノーマルセグ木.一年の時を経て漸く二分探索実装した. }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N >> Q; vector<long long> B(N,-1); vector<int> St; vector<long long> A(N),all; for(auto &a : A) cin >> a; all = A; vector<tuple<int,long long,long long>> Query(Q,{-1,-1,-1}); for(auto &[t,k,x] : Query){ cin >> t; if(t == 1) cin >> k >> x,k--,all.push_back(x); if(t == 3) cin >> k,k--; } all = zaatull(all); int n = all.size(); for(auto &a : A) a = lower_bound(all.begin(),all.end(),a)-all.begin(); for(auto &[t,k,x] : Query) if(t == 1) x = lower_bound(all.begin(),all.end(),x)-all.begin(); SegmentTree Z; Z.make(n); for(auto &a : A) Z.update(a,1); int border = -1; auto f = [&](SS x){return x<border;}; bool sorted = false; for(auto &[t,k,x] : Query){ if(t == 1){ St.push_back(k); B.at(k) = x; } if(t == 2){ sorted = true; for(auto pos : St){ if(B.at(pos) == -1) continue; long long a1 = A.at(pos),a2 = B.at(pos); Z.update(a1,-1); Z.update(a2,1); B.at(pos) = -1; } St.clear(); } if(t == 3){ if(B.at(k) != -1) cout << all.at(B.at(k)) << "\n"; else if(sorted == false) cout << all.at(A.at(k)) << "\n"; else{ border = k+1; cout << all.at(Z.maxright(f)) << "\n"; } } } }