結果

問題 No.1705 Mode of long array
ユーザー Drice27149
提出日時 2021-10-08 23:01:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 63 ms / 3,000 ms
コード長 811 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 53,500 KB
実行使用メモリ 9,432 KB
最終ジャッジ日時 2024-07-23 06:22:04
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <queue>
struct Element{
	int val;
	long long cnt;
	bool operator < (const Element& other)const{
		if(cnt!=other.cnt) return cnt < other.cnt;
		else return val < other.val;
	}
};
long long time[100005];

int main(){
	long long m;
	int n;
	scanf("%lld%d",&m,&n);
	std::priority_queue<Element> Q;
	for(int i = 1; i <= n; i++){
		long long cnt;
		scanf("%lld",&cnt);
		time[i] = cnt;
		Q.push(Element{i,cnt});
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int op;
		long long x,y;
		scanf("%d%lld%lld",&op,&x,&y);
		if(op == 1){
			time[x] += y;
			Q.push(Element{(int)x,time[x]});
		}
		else if(op == 2){
			time[x] -= y;
			Q.push(Element{(int)x,time[x]});
		}
		else{
			while(Q.size()!=0 && Q.top().cnt!=time[Q.top().val]) Q.pop();
			printf("%d\n",Q.top().val);
		}
	}
	
	
	return 0;
}
0