結果
問題 | No.1705 Mode of long array |
ユーザー | tenten |
提出日時 | 2021-10-11 16:00:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 970 ms / 3,000 ms |
コード長 | 2,384 bytes |
コンパイル時間 | 2,501 ms |
コンパイル使用メモリ | 78,876 KB |
実行使用メモリ | 60,572 KB |
最終ジャッジ日時 | 2024-09-15 16:37:06 |
合計ジャッジ時間 | 35,370 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
36,976 KB |
testcase_01 | AC | 54 ms
36,664 KB |
testcase_02 | AC | 53 ms
37,044 KB |
testcase_03 | AC | 132 ms
40,128 KB |
testcase_04 | AC | 116 ms
39,196 KB |
testcase_05 | AC | 137 ms
40,560 KB |
testcase_06 | AC | 175 ms
43,032 KB |
testcase_07 | AC | 190 ms
44,940 KB |
testcase_08 | AC | 186 ms
44,948 KB |
testcase_09 | AC | 178 ms
44,536 KB |
testcase_10 | AC | 178 ms
44,696 KB |
testcase_11 | AC | 179 ms
42,840 KB |
testcase_12 | AC | 176 ms
43,124 KB |
testcase_13 | AC | 767 ms
56,736 KB |
testcase_14 | AC | 550 ms
51,788 KB |
testcase_15 | AC | 460 ms
48,640 KB |
testcase_16 | AC | 550 ms
49,492 KB |
testcase_17 | AC | 421 ms
48,584 KB |
testcase_18 | AC | 412 ms
48,380 KB |
testcase_19 | AC | 627 ms
51,112 KB |
testcase_20 | AC | 478 ms
50,640 KB |
testcase_21 | AC | 633 ms
55,700 KB |
testcase_22 | AC | 807 ms
59,404 KB |
testcase_23 | AC | 403 ms
47,812 KB |
testcase_24 | AC | 407 ms
46,788 KB |
testcase_25 | AC | 400 ms
46,952 KB |
testcase_26 | AC | 405 ms
46,792 KB |
testcase_27 | AC | 406 ms
47,288 KB |
testcase_28 | AC | 397 ms
47,680 KB |
testcase_29 | AC | 407 ms
46,556 KB |
testcase_30 | AC | 409 ms
48,280 KB |
testcase_31 | AC | 407 ms
48,220 KB |
testcase_32 | AC | 401 ms
47,244 KB |
testcase_33 | AC | 952 ms
60,408 KB |
testcase_34 | AC | 959 ms
60,276 KB |
testcase_35 | AC | 955 ms
60,452 KB |
testcase_36 | AC | 957 ms
60,336 KB |
testcase_37 | AC | 967 ms
60,572 KB |
testcase_38 | AC | 970 ms
60,484 KB |
testcase_39 | AC | 969 ms
60,220 KB |
testcase_40 | AC | 960 ms
60,360 KB |
testcase_41 | AC | 951 ms
60,336 KB |
testcase_42 | AC | 917 ms
60,412 KB |
testcase_43 | AC | 554 ms
57,756 KB |
testcase_44 | AC | 544 ms
57,760 KB |
testcase_45 | AC | 569 ms
57,604 KB |
testcase_46 | AC | 551 ms
57,772 KB |
testcase_47 | AC | 568 ms
57,488 KB |
testcase_48 | AC | 560 ms
57,516 KB |
testcase_49 | AC | 733 ms
58,072 KB |
testcase_50 | AC | 690 ms
58,620 KB |
testcase_51 | AC | 733 ms
58,000 KB |
testcase_52 | AC | 721 ms
58,128 KB |
testcase_53 | AC | 729 ms
58,288 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(); } }