結果

問題 No.1705 Mode of long array
ユーザー 小野寺健
提出日時 2021-11-30 11:14:04
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,636 bytes
コンパイル時間 5,041 ms
コンパイル使用メモリ 85,876 KB
実行使用メモリ 102,028 KB
最終ジャッジ日時 2024-07-03 04:39:52
合計ジャッジ時間 106,128 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 TLE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class No1705 {
	
	private static class KeyValue implements Comparable<KeyValue> {
		public Integer key;
		public Long value;
		KeyValue(int key, long value) {
			this.key = key;
			this.value = value;
		}
		public int compareTo(KeyValue kv) {
			int n = value.compareTo(kv.value);
			if (n == 0) {
				return -key.compareTo(kv.key);
			} else {
				return -n;
			}
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		int M = scan.nextInt();
		HashMap<Integer, Long> hash = new HashMap<Integer, Long>();
		List<KeyValue> ary = new ArrayList<KeyValue>();
		for (int i=0; i < M; i++) {
			long a = scan.nextLong();
			hash.put(i+1, a);
			ary.add(new KeyValue(i+1, a));
		}
		Collections.sort(ary);
		int Q = scan.nextInt();
		for (int i=0; i < Q; i++) {
			int t = scan.nextInt();
			int x = scan.nextInt();
			long y = scan.nextLong();
			if (t == 1) {
				long v = hash.get(x);
				hash.put(x, v + y);
				int j = Collections.binarySearch(ary, new KeyValue(x, v));
				ary.remove(j);
				KeyValue kv = new KeyValue(x, v + y);
				j = Collections.binarySearch(ary, kv);
				ary.add(-j-1, kv);
			} else if (t == 2) {
				long v = hash.get(x);
				hash.put(x, v - y);
				int j = Collections.binarySearch(ary, new KeyValue(x, v));
				ary.remove(j);
				KeyValue kv = new KeyValue(x, v - y);
				j = Collections.binarySearch(ary, kv);
				ary.add(-j-1, kv);				
			} else {
				System.out.println(ary.get(0).key);
			}
		}
	}

}
0