結果
問題 | No.1705 Mode of long array |
ユーザー | tenten |
提出日時 | 2021-10-11 16:00:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 971 ms / 3,000 ms |
コード長 | 2,384 bytes |
コンパイル時間 | 2,324 ms |
コンパイル使用メモリ | 74,920 KB |
実行使用メモリ | 72,168 KB |
最終ジャッジ日時 | 2023-10-13 21:07:13 |
合計ジャッジ時間 | 37,802 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,384 KB |
testcase_01 | AC | 46 ms
49,480 KB |
testcase_02 | AC | 48 ms
49,508 KB |
testcase_03 | AC | 124 ms
53,756 KB |
testcase_04 | AC | 101 ms
52,152 KB |
testcase_05 | AC | 127 ms
53,004 KB |
testcase_06 | AC | 165 ms
55,896 KB |
testcase_07 | AC | 176 ms
56,004 KB |
testcase_08 | AC | 181 ms
58,372 KB |
testcase_09 | AC | 172 ms
58,724 KB |
testcase_10 | AC | 167 ms
58,476 KB |
testcase_11 | AC | 170 ms
57,856 KB |
testcase_12 | AC | 168 ms
58,276 KB |
testcase_13 | AC | 800 ms
67,332 KB |
testcase_14 | AC | 606 ms
62,936 KB |
testcase_15 | AC | 484 ms
60,408 KB |
testcase_16 | AC | 570 ms
61,384 KB |
testcase_17 | AC | 458 ms
58,880 KB |
testcase_18 | AC | 425 ms
58,828 KB |
testcase_19 | AC | 621 ms
60,640 KB |
testcase_20 | AC | 485 ms
61,376 KB |
testcase_21 | AC | 679 ms
65,300 KB |
testcase_22 | AC | 868 ms
72,168 KB |
testcase_23 | AC | 388 ms
58,488 KB |
testcase_24 | AC | 381 ms
58,764 KB |
testcase_25 | AC | 383 ms
59,196 KB |
testcase_26 | AC | 379 ms
58,424 KB |
testcase_27 | AC | 395 ms
58,900 KB |
testcase_28 | AC | 389 ms
59,424 KB |
testcase_29 | AC | 395 ms
58,436 KB |
testcase_30 | AC | 391 ms
58,108 KB |
testcase_31 | AC | 394 ms
58,308 KB |
testcase_32 | AC | 392 ms
59,668 KB |
testcase_33 | AC | 970 ms
70,772 KB |
testcase_34 | AC | 964 ms
70,816 KB |
testcase_35 | AC | 965 ms
70,524 KB |
testcase_36 | AC | 942 ms
70,772 KB |
testcase_37 | AC | 940 ms
70,884 KB |
testcase_38 | AC | 961 ms
70,872 KB |
testcase_39 | AC | 957 ms
70,980 KB |
testcase_40 | AC | 963 ms
70,560 KB |
testcase_41 | AC | 971 ms
70,492 KB |
testcase_42 | AC | 955 ms
70,776 KB |
testcase_43 | AC | 549 ms
68,500 KB |
testcase_44 | AC | 553 ms
67,720 KB |
testcase_45 | AC | 558 ms
68,000 KB |
testcase_46 | AC | 556 ms
68,088 KB |
testcase_47 | AC | 545 ms
68,220 KB |
testcase_48 | AC | 548 ms
68,048 KB |
testcase_49 | AC | 731 ms
68,828 KB |
testcase_50 | AC | 727 ms
69,552 KB |
testcase_51 | AC | 732 ms
68,476 KB |
testcase_52 | AC | 724 ms
69,944 KB |
testcase_53 | AC | 737 ms
68,500 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static long[] counts; static Num[] nums; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); int m = sc.nextInt(); TreeSet<Num> stock = new TreeSet<>(); counts = new long[m]; nums = new Num[m]; for (int i = 0; i < m; i++) { nums[i] = new Num(i); counts[i] = sc.nextLong(); stock.add(nums[i]); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int type = sc.nextInt(); int x = sc.nextInt() - 1; long y = sc.nextLong(); if (type == 1) { stock.remove(nums[x]); counts[x] += y; stock.add(nums[x]); } else if (type == 2) { stock.remove(nums[x]); counts[x] -= y; stock.add(nums[x]); } else { sb.append(stock.last()).append("\n"); } } System.out.print(sb); } static class Num implements Comparable<Num> { int idx; public Num(int idx) { this.idx = idx; } public int compareTo(Num another) { if (counts[idx] == counts[another.idx]) { return idx - another.idx; } else if (counts[idx] > counts[another.idx]) { return 1; } else { return -1; } } public int hashCode() { return idx; } public String toString() { return String.valueOf(idx + 1); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }