結果
問題 | No.1705 Mode of long array |
ユーザー | harurun |
提出日時 | 2021-09-19 14:31:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 504 ms / 3,000 ms |
コード長 | 3,208 bytes |
コンパイル時間 | 1,902 ms |
コンパイル使用メモリ | 121,560 KB |
実行使用メモリ | 35,368 KB |
最終ジャッジ日時 | 2024-07-23 03:40:09 |
合計ジャッジ時間 | 17,121 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 4 ms
5,376 KB |
testcase_05 | AC | 5 ms
5,376 KB |
testcase_06 | AC | 12 ms
5,376 KB |
testcase_07 | AC | 15 ms
5,376 KB |
testcase_08 | AC | 15 ms
5,376 KB |
testcase_09 | AC | 13 ms
5,376 KB |
testcase_10 | AC | 12 ms
5,376 KB |
testcase_11 | AC | 14 ms
5,376 KB |
testcase_12 | AC | 13 ms
5,376 KB |
testcase_13 | AC | 400 ms
31,380 KB |
testcase_14 | AC | 243 ms
22,452 KB |
testcase_15 | AC | 204 ms
14,904 KB |
testcase_16 | AC | 262 ms
17,876 KB |
testcase_17 | AC | 171 ms
13,940 KB |
testcase_18 | AC | 145 ms
12,772 KB |
testcase_19 | AC | 296 ms
22,716 KB |
testcase_20 | AC | 186 ms
15,532 KB |
testcase_21 | AC | 312 ms
27,072 KB |
testcase_22 | AC | 489 ms
35,368 KB |
testcase_23 | AC | 129 ms
6,536 KB |
testcase_24 | AC | 131 ms
6,532 KB |
testcase_25 | AC | 130 ms
6,536 KB |
testcase_26 | AC | 129 ms
6,536 KB |
testcase_27 | AC | 128 ms
6,412 KB |
testcase_28 | AC | 130 ms
6,408 KB |
testcase_29 | AC | 131 ms
6,536 KB |
testcase_30 | AC | 130 ms
6,664 KB |
testcase_31 | AC | 130 ms
6,536 KB |
testcase_32 | AC | 128 ms
6,664 KB |
testcase_33 | AC | 499 ms
31,632 KB |
testcase_34 | AC | 483 ms
31,684 KB |
testcase_35 | AC | 498 ms
31,652 KB |
testcase_36 | AC | 488 ms
31,628 KB |
testcase_37 | AC | 489 ms
31,628 KB |
testcase_38 | AC | 477 ms
31,744 KB |
testcase_39 | AC | 485 ms
31,756 KB |
testcase_40 | AC | 490 ms
31,760 KB |
testcase_41 | AC | 504 ms
31,696 KB |
testcase_42 | AC | 501 ms
31,764 KB |
testcase_43 | AC | 315 ms
17,172 KB |
testcase_44 | AC | 310 ms
17,420 KB |
testcase_45 | AC | 318 ms
17,420 KB |
testcase_46 | AC | 306 ms
17,428 KB |
testcase_47 | AC | 313 ms
17,296 KB |
testcase_48 | AC | 312 ms
17,424 KB |
testcase_49 | AC | 364 ms
22,924 KB |
testcase_50 | AC | 371 ms
22,932 KB |
testcase_51 | AC | 365 ms
22,928 KB |
testcase_52 | AC | 374 ms
22,928 KB |
testcase_53 | AC | 372 ms
23,016 KB |
ソースコード
#include <iostream> #include <vector> #include <unordered_map> #include <set> #include <algorithm> #include <utility> using namespace std; using ll=long long; struct Queries{ ll T,X,Y; }; class Mode{ private: unordered_map<ll,ll> place; vector<ll> count; vector<set<ll>> S; multiset<ll> max_S; public: Mode(ll M,unordered_map<ll,ll>& um,vector<ll>& A){ place=um; S.resize(um.size()); count.resize(M,0); for(ll i=0;i<M;i++){ // i が A[i] 個ある max_S.insert(0); add(i,A.at(i)); //max_S.insert(place.at(A.at(i))); //cerr<<"insert max_S: "<<A.at(i)<<" "<<place.at(A.at(i))<<endl; //cerr<<"init add: "<<i<<" "<<A.at(i)<<endl; } } void add(ll x,ll y){ // x:0-indexed ll now=count.at(x); //cerr<<"x: "<<x<<", y: "<<y<<", now: "<<now<<endl; S.at(place.at(now)).erase(x); max_S.erase(max_S.find(place.at(now))); //cerr<<"erase max_S: "<<now<<" "<<place.at(now)<<endl; S.at(place.at(now+y)).insert(x); max_S.insert(place.at(now+y)); //cerr<<"insert max_S: "<<now+y<<" "<<place.at(now+y)<<endl; count.at(x)+=y; } void erase(ll x,ll y){ ll now=count.at(x); S.at(place.at(now)).erase(x); max_S.erase(max_S.find(place.at(now))); //cerr<<"erase max_S: "<<now<<" "<<place.at(now)<<endl; S.at(place.at(now-y)).insert(x); max_S.insert(place.at(now-y)); //cerr<<"insert max_S: "<<now-y<<" "<<place.at(now-y)<<endl; count.at(x)-=y; } ll get(){ //cerr<<"get"<<endl; ll max_place=*max_S.rbegin(); //cerr<<"max_place: "<<max_place<<endl; return *S.at(max_place).rbegin()+1; } void debug_conut(){ for(ll i=0;i<count.size();i++){ cerr<<count.at(i)<<" "; } cerr<<endl; } void debug_max_S(){ cerr<<"max_S: "; for(ll i:max_S){ cerr<<i<<" "; } cerr<<endl; } }; int main(){ ll N,M; cin>>N>>M; vector<ll> a(M); for(ll i=0;i<M;i++){ cin>>a.at(i); } vector<ll> b=a; ll Q; cin>>Q; vector<Queries> query(Q); // クエリ先読みして座圧する for(ll i=0;i<Q;i++){ cin>>query.at(i).T>>query.at(i).X>>query.at(i).Y; if(query.at(i).T==1){ b.push_back(b.at(query.at(i).X-1)); b.at(query.at(i).X-1)+=query.at(i).Y; }else if(query.at(i).T==2){ b.push_back(b.at(query.at(i).X-1)); b.at(query.at(i).X-1)-=query.at(i).Y; } } b.push_back(0); sort(b.begin(),b.end()); //cerr<<"sort end"<<endl; unordered_map<ll,ll> place; place.insert(make_pair(b.at(0),0)); ll cnt=1; //cerr<<"place: 0 "; for(ll i=1;i<b.size();i++){ if(b.at(i-1)!=b.at(i)){ //cerr<<b.at(i)<<" "; place.insert(make_pair(b.at(i),cnt)); cnt++; } } //cerr<<endl; Mode mode(M,place,a); //cerr<<"query start"<<endl; for(ll i=0;i<Q;i++){ //mode.debug_max_S(); if(query.at(i).T==1){ mode.add(query.at(i).X-1,query.at(i).Y); }else if(query.at(i).T==2){ mode.erase(query.at(i).X-1,query.at(i).Y); }else{ cout<<mode.get()<<endl; } //cerr<<"i: "<<i<<" end"<<endl; } return 0; }