結果

問題 No.1705 Mode of long array
ユーザー ks2mks2m
提出日時 2021-10-08 23:22:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,399 ms / 3,000 ms
コード長 1,804 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 77,284 KB
実行使用メモリ 111,892 KB
最終ジャッジ日時 2023-09-30 13:20:43
合計ジャッジ時間 43,580 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,712 KB
testcase_01 AC 44 ms
49,636 KB
testcase_02 AC 44 ms
49,692 KB
testcase_03 AC 119 ms
53,352 KB
testcase_04 AC 107 ms
51,976 KB
testcase_05 AC 126 ms
53,504 KB
testcase_06 AC 196 ms
56,912 KB
testcase_07 AC 195 ms
56,684 KB
testcase_08 AC 186 ms
56,512 KB
testcase_09 AC 190 ms
56,196 KB
testcase_10 AC 189 ms
56,584 KB
testcase_11 AC 193 ms
57,220 KB
testcase_12 AC 179 ms
56,744 KB
testcase_13 AC 1,202 ms
102,496 KB
testcase_14 AC 864 ms
81,616 KB
testcase_15 AC 657 ms
65,500 KB
testcase_16 AC 899 ms
69,116 KB
testcase_17 AC 653 ms
64,928 KB
testcase_18 AC 565 ms
64,524 KB
testcase_19 AC 1,042 ms
78,632 KB
testcase_20 AC 709 ms
68,580 KB
testcase_21 AC 959 ms
90,084 KB
testcase_22 AC 1,304 ms
106,740 KB
testcase_23 AC 503 ms
58,316 KB
testcase_24 AC 511 ms
58,448 KB
testcase_25 AC 493 ms
58,176 KB
testcase_26 AC 495 ms
59,372 KB
testcase_27 AC 499 ms
58,832 KB
testcase_28 AC 497 ms
58,252 KB
testcase_29 AC 508 ms
58,628 KB
testcase_30 AC 508 ms
59,116 KB
testcase_31 AC 515 ms
58,608 KB
testcase_32 AC 504 ms
58,308 KB
testcase_33 AC 1,372 ms
111,480 KB
testcase_34 AC 1,371 ms
110,808 KB
testcase_35 AC 1,374 ms
111,436 KB
testcase_36 AC 1,372 ms
110,792 KB
testcase_37 AC 1,376 ms
111,304 KB
testcase_38 AC 1,399 ms
111,200 KB
testcase_39 AC 1,347 ms
111,596 KB
testcase_40 AC 1,362 ms
111,124 KB
testcase_41 AC 1,359 ms
111,892 KB
testcase_42 AC 1,369 ms
111,628 KB
testcase_43 AC 702 ms
79,108 KB
testcase_44 AC 732 ms
78,792 KB
testcase_45 AC 723 ms
78,604 KB
testcase_46 AC 692 ms
78,760 KB
testcase_47 AC 718 ms
78,440 KB
testcase_48 AC 721 ms
78,980 KB
testcase_49 AC 889 ms
82,196 KB
testcase_50 AC 911 ms
82,540 KB
testcase_51 AC 915 ms
82,068 KB
testcase_52 AC 899 ms
82,384 KB
testcase_53 AC 909 ms
82,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		long n = Long.parseLong(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		long[] a = new long[m];
		for (int i = 0; i < m; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		int q = Integer.parseInt(br.readLine());
		int[] t = new int[q];
		int[] x = new int[q];
		long[] y = new long[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			t[i] = Integer.parseInt(sa[0]);
			x[i] = Integer.parseInt(sa[1]);
			y[i] = Long.parseLong(sa[2]);
		}
		br.close();

		TreeMap<Long, TreeSet<Integer>> map = new TreeMap<>();
		Map<Integer, Long> map2 = new HashMap<>();
		for (int i = 0; i < m; i++) {
			TreeSet<Integer> set = map.get(a[i]);
			if (set == null) {
				set = new TreeSet<>();
				map.put(a[i], set);
			}
			set.add(i + 1);
			map2.put(i + 1, a[i]);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			if (t[i] == 3) {
				pw.println(map.lastEntry().getValue().last());
			} else {
				long bef = map2.get(x[i]);
				long aft = bef;
				if (t[i] == 1) {
					aft += y[i];
				} else {
					aft -= y[i];
				}
				TreeSet<Integer> set1 = map.get(bef);
				TreeSet<Integer> set2 = map.get(aft);
				if (set2 == null) {
					set2 = new TreeSet<>();
					map.put(aft, set2);
				}
				set1.remove(x[i]);
				set2.add(x[i]);
				if (set1.isEmpty()) {
					map.remove(bef);
				}
				map2.put(x[i], aft);
			}
		}
		pw.flush();
	}
}
0