結果

問題 No.1705 Mode of long array
ユーザー harurunharurun
提出日時 2021-09-22 19:43:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,490 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 87,376 KB
実行使用メモリ 10,256 KB
最終ジャッジ日時 2023-09-30 09:40:30
合計ジャッジ時間 16,200 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 12 ms
4,384 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 14 ms
4,376 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 183 ms
8,472 KB
testcase_14 AC 126 ms
6,188 KB
testcase_15 AC 122 ms
4,376 KB
testcase_16 AC 150 ms
4,432 KB
testcase_17 AC 108 ms
4,380 KB
testcase_18 AC 91 ms
4,396 KB
testcase_19 AC 170 ms
5,284 KB
testcase_20 AC 107 ms
4,800 KB
testcase_21 AC 148 ms
7,928 KB
testcase_22 AC 216 ms
9,824 KB
testcase_23 AC 111 ms
4,376 KB
testcase_24 AC 109 ms
4,376 KB
testcase_25 AC 105 ms
4,376 KB
testcase_26 AC 105 ms
4,376 KB
testcase_27 AC 112 ms
4,376 KB
testcase_28 AC 113 ms
4,376 KB
testcase_29 AC 107 ms
4,380 KB
testcase_30 AC 108 ms
4,384 KB
testcase_31 AC 111 ms
4,376 KB
testcase_32 AC 109 ms
4,376 KB
testcase_33 AC 235 ms
10,056 KB
testcase_34 AC 237 ms
10,256 KB
testcase_35 AC 237 ms
10,180 KB
testcase_36 AC 239 ms
10,120 KB
testcase_37 AC 240 ms
10,108 KB
testcase_38 AC 233 ms
10,224 KB
testcase_39 AC 242 ms
10,056 KB
testcase_40 AC 243 ms
10,196 KB
testcase_41 AC 241 ms
10,064 KB
testcase_42 AC 236 ms
10,224 KB
testcase_43 AC 235 ms
10,228 KB
testcase_44 AC 351 ms
10,176 KB
testcase_45 AC 378 ms
10,164 KB
testcase_46 AC 362 ms
10,220 KB
testcase_47 AC 342 ms
10,168 KB
testcase_48 AC 350 ms
10,188 KB
testcase_49 TLE -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
using ll=long long;
using Pll=pair<ll,ll>;

int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll> a(M);
  for(ll i=0;i<M;i++){
    cin>>a.at(i);
  }
  multiset<Pll> ms;
  for(ll i=0;i<M;i++){
    ms.insert(make_pair(a.at(i),i+1));
  }
  ll Q;
  cin>>Q;
  bool flag=false;
  ll before;
  for(ll i=0;i<Q;i++){
    //cerr<<"i:"<<i<<endl;
    ll T,X,Y;
    cin>>T>>X>>Y;
    if(T==1){
      flag=false;
      auto it=ms.lower_bound(make_pair(a.at(X-1),-1));
      auto last=ms.upper_bound(make_pair(a.at(X-1)+1,-1));
      for(;it!=last;it++){
        if((*it).second==X){
          ms.erase(it);
          break;
        }
      }
      a.at(X-1)+=Y;
      ms.insert(make_pair(a.at(X-1),X));
    }else if(T==2){
      flag=false;
      auto it=ms.lower_bound(make_pair(a.at(X-1),-1));
      auto last=ms.upper_bound(make_pair(a.at(X-1)+1,-1));
      for(;it!=last;it++){
        if((*it).second==X){
          ms.erase(it);
          break;
        }
      }
      a.at(X-1)-=Y;
      ms.insert(make_pair(a.at(X-1),X));
    }else{
      if(flag){
        cout<<before<<endl;
        continue;
      }
      flag=true;
      auto it=ms.lower_bound(make_pair((*ms.rbegin()).first,-1));
      auto last=ms.upper_bound(make_pair((*ms.rbegin()).first+1,-1));
      ll ans=0;
      for(;it!=last;it++){
        ans=max(ans,(*it).second);
      }
      cout<<ans<<endl;
      before=ans;
    }
  }
  return 0;
}
0