結果

問題 No.1705 Mode of long array
ユーザー 沙耶花
提出日時 2021-10-08 22:20:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 554 ms / 3,000 ms
コード長 986 bytes
コンパイル時間 5,078 ms
コンパイル使用メモリ 269,128 KB
最終ジャッジ日時 2025-01-24 22:29:25
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |                 scanf("%lld",&a);
      |                 ~~~~~^~~~~~~~~~~
main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |                 scanf("%d %lld %lld",&t,&x,&y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000


int main(){
	
	long long n,m;
	cin>>n>>m;
	
	map<long long,set<long long>> mp;
	
	map<long long,long long> mp2;
	
	rep(i,m){
		long long a;
		scanf("%lld",&a);
		mp2[i+1] = a;
		mp[a].insert(i+1);
	}
	int q;
	cin>>q;
	rep(i,q){
		int t;
		long long x,y;
		scanf("%d %lld %lld",&t,&x,&y);
		
		if(t==1){
			if(mp2.count(x)){
				mp[mp2[x]].erase(x);
				if(mp[mp2[x]].size()==0)mp.erase(mp2[x]);
				mp2[x] += y;
				mp[mp2[x]].insert(x);
				
			}
			else{
				mp2[x] = y;
				mp[y].insert(x);
			}
		}
		if(t==2){
			mp[mp2[x]].erase(x);
			if(mp[mp2[x]].size()==0)mp.erase(mp2[x]);
			mp2[x] -= y;
			mp[mp2[x]].insert(x);
		}
		if(t==3){
			auto it = mp.end();
			it--;
			auto it2=  it->second.end();
			it2--;
			printf("%lld\n",(*it2));
		}
		
		
	}
	
	return 0;
}
0