結果
問題 | No.1705 Mode of long array |
ユーザー | tenten |
提出日時 | 2023-04-26 09:04:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 939 ms / 3,000 ms |
コード長 | 3,231 bytes |
コンパイル時間 | 2,617 ms |
コンパイル使用メモリ | 85,000 KB |
実行使用メモリ | 60,352 KB |
最終ジャッジ日時 | 2024-11-15 17:34:46 |
合計ジャッジ時間 | 32,807 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
37,008 KB |
testcase_01 | AC | 52 ms
36,724 KB |
testcase_02 | AC | 52 ms
36,900 KB |
testcase_03 | AC | 124 ms
39,880 KB |
testcase_04 | AC | 105 ms
39,336 KB |
testcase_05 | AC | 136 ms
41,092 KB |
testcase_06 | AC | 175 ms
42,876 KB |
testcase_07 | AC | 189 ms
45,260 KB |
testcase_08 | AC | 184 ms
45,160 KB |
testcase_09 | AC | 178 ms
44,808 KB |
testcase_10 | AC | 171 ms
44,420 KB |
testcase_11 | AC | 178 ms
43,712 KB |
testcase_12 | AC | 179 ms
43,984 KB |
testcase_13 | AC | 733 ms
55,504 KB |
testcase_14 | AC | 575 ms
51,968 KB |
testcase_15 | AC | 448 ms
48,628 KB |
testcase_16 | AC | 525 ms
49,556 KB |
testcase_17 | AC | 432 ms
49,092 KB |
testcase_18 | AC | 399 ms
48,704 KB |
testcase_19 | AC | 613 ms
50,916 KB |
testcase_20 | AC | 479 ms
49,996 KB |
testcase_21 | AC | 616 ms
54,152 KB |
testcase_22 | AC | 774 ms
57,036 KB |
testcase_23 | AC | 391 ms
46,968 KB |
testcase_24 | AC | 393 ms
46,888 KB |
testcase_25 | AC | 390 ms
46,896 KB |
testcase_26 | AC | 394 ms
46,604 KB |
testcase_27 | AC | 392 ms
47,056 KB |
testcase_28 | AC | 383 ms
46,964 KB |
testcase_29 | AC | 400 ms
46,800 KB |
testcase_30 | AC | 398 ms
46,800 KB |
testcase_31 | AC | 397 ms
46,836 KB |
testcase_32 | AC | 404 ms
46,828 KB |
testcase_33 | AC | 876 ms
60,184 KB |
testcase_34 | AC | 914 ms
60,352 KB |
testcase_35 | AC | 886 ms
60,060 KB |
testcase_36 | AC | 911 ms
60,312 KB |
testcase_37 | AC | 904 ms
60,136 KB |
testcase_38 | AC | 939 ms
60,152 KB |
testcase_39 | AC | 919 ms
60,212 KB |
testcase_40 | AC | 896 ms
60,312 KB |
testcase_41 | AC | 916 ms
60,080 KB |
testcase_42 | AC | 895 ms
60,260 KB |
testcase_43 | AC | 548 ms
56,880 KB |
testcase_44 | AC | 554 ms
57,888 KB |
testcase_45 | AC | 565 ms
57,748 KB |
testcase_46 | AC | 571 ms
58,160 KB |
testcase_47 | AC | 546 ms
57,888 KB |
testcase_48 | AC | 568 ms
57,588 KB |
testcase_49 | AC | 716 ms
58,240 KB |
testcase_50 | AC | 760 ms
58,636 KB |
testcase_51 | AC | 730 ms
58,316 KB |
testcase_52 | AC | 761 ms
58,632 KB |
testcase_53 | AC | 749 ms
57,952 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); int m = sc.nextInt(); Num[] nums = new Num[m]; TreeSet<Num> tree = new TreeSet<>(); for (int i = 0; i < m; i++) { nums[i] = new Num(i, sc.nextLong()); tree.add(nums[i]); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { int type = sc.nextInt(); int idx = sc.nextInt() - 1; long value = sc.nextLong(); if (type == 1) { tree.remove(nums[idx]); nums[idx].add(value); tree.add(nums[idx]); } else if (type == 2) { tree.remove(nums[idx]); nums[idx].add(-value); tree.add(nums[idx]); } else { sb.append(tree.last()).append("\n"); } } System.out.print(sb); } static class Num implements Comparable<Num> { int idx; long value; public Num(int idx, long value) { this.idx = idx; this.value = value; } public void add(long v) { value += v; } public int hashCode() { return idx; } public int compareTo(Num another) { if (value == another.value) { return idx - another.idx; } else { if (value < another.value) { return -1; } else { return 1; } } } public boolean equals(Object o) { return hashCode() == o.hashCode(); } public String toString() { return String.valueOf(idx + 1); } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }