結果

問題 No.1705 Mode of long array
ユーザー harurunharurun
提出日時 2021-09-19 18:23:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 529 ms / 3,000 ms
コード長 2,114 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 120,968 KB
実行使用メモリ 35,328 KB
最終ジャッジ日時 2023-09-30 09:38:42
合計ジャッジ時間 18,115 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 5 ms
4,384 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 12 ms
4,384 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 412 ms
31,204 KB
testcase_14 AC 272 ms
22,304 KB
testcase_15 AC 200 ms
14,696 KB
testcase_16 AC 262 ms
17,616 KB
testcase_17 AC 175 ms
13,996 KB
testcase_18 AC 147 ms
12,668 KB
testcase_19 AC 315 ms
22,492 KB
testcase_20 AC 186 ms
15,364 KB
testcase_21 AC 319 ms
26,992 KB
testcase_22 AC 496 ms
35,328 KB
testcase_23 AC 126 ms
6,388 KB
testcase_24 AC 126 ms
6,320 KB
testcase_25 AC 126 ms
6,392 KB
testcase_26 AC 123 ms
6,380 KB
testcase_27 AC 125 ms
6,316 KB
testcase_28 AC 126 ms
6,712 KB
testcase_29 AC 126 ms
6,528 KB
testcase_30 AC 126 ms
6,320 KB
testcase_31 AC 125 ms
6,668 KB
testcase_32 AC 125 ms
6,328 KB
testcase_33 AC 529 ms
31,716 KB
testcase_34 AC 517 ms
31,732 KB
testcase_35 AC 525 ms
31,660 KB
testcase_36 AC 525 ms
31,568 KB
testcase_37 AC 524 ms
31,644 KB
testcase_38 AC 519 ms
31,512 KB
testcase_39 AC 522 ms
31,584 KB
testcase_40 AC 512 ms
31,512 KB
testcase_41 AC 524 ms
31,580 KB
testcase_42 AC 517 ms
31,724 KB
testcase_43 AC 314 ms
17,196 KB
testcase_44 AC 315 ms
17,188 KB
testcase_45 AC 310 ms
17,060 KB
testcase_46 AC 314 ms
17,112 KB
testcase_47 AC 316 ms
17,264 KB
testcase_48 AC 315 ms
17,108 KB
testcase_49 AC 365 ms
22,656 KB
testcase_50 AC 364 ms
22,660 KB
testcase_51 AC 364 ms
22,820 KB
testcase_52 AC 373 ms
22,660 KB
testcase_53 AC 382 ms
22,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++){
        max_S.insert(0);
        add(i,A.at(i));
      }
    }
    void add(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)));
      S.at(place.at(now+y)).insert(x);
      max_S.insert(place.at(now+y));
      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)));
      S.at(place.at(now-y)).insert(x);
      max_S.insert(place.at(now-y));
      count.at(x)-=y;
    }
    ll get(){
      ll max_place=*max_S.rbegin();
      return *S.at(max_place).rbegin()+1;
    }
};


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());
  unordered_map<ll,ll> place;
  place.insert(make_pair(b.at(0),0));
  ll cnt=1;
  for(ll i=1;i<b.size();i++){
    if(b.at(i-1)!=b.at(i)){
      place.insert(make_pair(b.at(i),cnt));
      cnt++;
    }
  }
  Mode mode(M,place,a);
  for(ll i=0;i<Q;i++){
    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;
    }
  }
  return 0;
}
0