結果
問題 |
No.1705 Mode of long array
|
ユーザー |
![]() |
提出日時 | 2021-09-22 13:01:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,317 bytes |
コンパイル時間 | 1,191 ms |
コンパイル使用メモリ | 84,940 KB |
最終ジャッジ日時 | 2025-01-24 16:13:44 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 TLE * 11 |
ソースコード
#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; for(ll i=0;i<Q;i++){ //cerr<<"i:"<<i<<endl; ll T,X,Y; cin>>T>>X>>Y; if(T==1){ 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){ 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{ 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; } } return 0; }