結果

問題 No.1705 Mode of long array
ユーザー 小野寺健小野寺健
提出日時 2021-11-30 11:14:04
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,636 bytes
コンパイル時間 3,738 ms
コンパイル使用メモリ 76,256 KB
実行使用メモリ 103,516 KB
最終ジャッジ日時 2023-09-16 03:20:46
合計ジャッジ時間 96,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,500 KB
testcase_01 AC 133 ms
55,840 KB
testcase_02 AC 130 ms
56,200 KB
testcase_03 AC 271 ms
60,312 KB
testcase_04 AC 273 ms
59,768 KB
testcase_05 AC 288 ms
60,152 KB
testcase_06 AC 397 ms
61,024 KB
testcase_07 AC 420 ms
60,620 KB
testcase_08 AC 424 ms
60,956 KB
testcase_09 AC 415 ms
61,060 KB
testcase_10 AC 396 ms
61,312 KB
testcase_11 AC 415 ms
60,748 KB
testcase_12 AC 413 ms
60,852 KB
testcase_13 AC 2,295 ms
89,932 KB
testcase_14 AC 1,907 ms
80,036 KB
testcase_15 AC 1,427 ms
73,804 KB
testcase_16 AC 1,718 ms
76,740 KB
testcase_17 AC 1,321 ms
71,080 KB
testcase_18 AC 1,224 ms
69,832 KB
testcase_19 AC 2,169 ms
78,748 KB
testcase_20 AC 1,438 ms
76,212 KB
testcase_21 AC 1,921 ms
88,504 KB
testcase_22 AC 2,577 ms
93,952 KB
testcase_23 AC 994 ms
65,244 KB
testcase_24 AC 1,004 ms
65,276 KB
testcase_25 AC 1,003 ms
65,200 KB
testcase_26 AC 1,015 ms
65,612 KB
testcase_27 AC 990 ms
65,380 KB
testcase_28 AC 1,036 ms
64,904 KB
testcase_29 AC 990 ms
65,176 KB
testcase_30 AC 1,016 ms
65,456 KB
testcase_31 AC 997 ms
65,308 KB
testcase_32 AC 1,017 ms
65,052 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 AC 1,812 ms
95,292 KB
testcase_44 AC 1,826 ms
94,104 KB
testcase_45 AC 1,809 ms
94,216 KB
testcase_46 AC 1,800 ms
96,288 KB
testcase_47 AC 1,819 ms
94,260 KB
testcase_48 AC 1,800 ms
94,376 KB
testcase_49 AC 2,745 ms
96,292 KB
testcase_50 AC 2,759 ms
96,236 KB
testcase_51 AC 2,813 ms
96,144 KB
testcase_52 AC 2,724 ms
95,880 KB
testcase_53 AC 2,772 ms
95,864 KB
権限があれば一括ダウンロードができます

ソースコード

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