結果

問題 No.1705 Mode of long array
ユーザー tentententen
提出日時 2021-11-29 17:47:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 863 ms / 3,000 ms
コード長 2,681 bytes
コンパイル時間 5,074 ms
コンパイル使用メモリ 75,068 KB
実行使用メモリ 70,604 KB
最終ジャッジ日時 2023-09-15 08:53:18
合計ジャッジ時間 34,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
47,616 KB
testcase_01 AC 43 ms
49,524 KB
testcase_02 AC 42 ms
49,504 KB
testcase_03 AC 121 ms
54,068 KB
testcase_04 AC 91 ms
52,956 KB
testcase_05 AC 126 ms
54,008 KB
testcase_06 AC 163 ms
56,428 KB
testcase_07 AC 171 ms
58,856 KB
testcase_08 AC 170 ms
58,592 KB
testcase_09 AC 164 ms
58,160 KB
testcase_10 AC 162 ms
57,924 KB
testcase_11 AC 168 ms
58,728 KB
testcase_12 AC 164 ms
58,412 KB
testcase_13 AC 655 ms
65,708 KB
testcase_14 AC 500 ms
63,168 KB
testcase_15 AC 438 ms
59,584 KB
testcase_16 AC 519 ms
61,368 KB
testcase_17 AC 418 ms
59,040 KB
testcase_18 AC 376 ms
58,764 KB
testcase_19 AC 565 ms
60,708 KB
testcase_20 AC 446 ms
61,256 KB
testcase_21 AC 565 ms
65,104 KB
testcase_22 AC 746 ms
68,568 KB
testcase_23 AC 375 ms
58,740 KB
testcase_24 AC 372 ms
58,668 KB
testcase_25 AC 375 ms
56,976 KB
testcase_26 AC 376 ms
58,364 KB
testcase_27 AC 372 ms
58,708 KB
testcase_28 AC 378 ms
57,512 KB
testcase_29 AC 374 ms
58,736 KB
testcase_30 AC 376 ms
58,580 KB
testcase_31 AC 362 ms
59,036 KB
testcase_32 AC 369 ms
58,900 KB
testcase_33 AC 828 ms
70,264 KB
testcase_34 AC 839 ms
70,584 KB
testcase_35 AC 847 ms
70,544 KB
testcase_36 AC 839 ms
70,588 KB
testcase_37 AC 848 ms
70,248 KB
testcase_38 AC 863 ms
70,428 KB
testcase_39 AC 841 ms
70,604 KB
testcase_40 AC 852 ms
70,508 KB
testcase_41 AC 812 ms
70,584 KB
testcase_42 AC 820 ms
70,292 KB
testcase_43 AC 524 ms
67,820 KB
testcase_44 AC 536 ms
68,172 KB
testcase_45 AC 525 ms
68,424 KB
testcase_46 AC 528 ms
68,432 KB
testcase_47 AC 535 ms
68,168 KB
testcase_48 AC 539 ms
67,940 KB
testcase_49 AC 671 ms
68,708 KB
testcase_50 AC 676 ms
68,204 KB
testcase_51 AC 675 ms
68,768 KB
testcase_52 AC 679 ms
68,584 KB
testcase_53 AC 662 ms
68,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        int m = sc.nextInt();
        Numbers[] numbers = new Numbers[m + 1];
        TreeSet<Numbers> set = new TreeSet<>();
        for (int i = 1; i <= m; i++) {
            numbers[i] = new Numbers(i, sc.nextLong());
            set.add(numbers[i]);
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int type = sc.nextInt();
            int x = sc.nextInt();
            long y = sc.nextLong();
            if (type == 1) {
                set.remove(numbers[x]);
                numbers[x].add(y);
                set.add(numbers[x]);
            } else if (type == 2) {
                set.remove(numbers[x]);
                numbers[x].add(-y);
                set.add(numbers[x]);
            } else {
                sb.append(set.last()).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Numbers implements Comparable<Numbers> {
        int num;
        long value;
        
        public Numbers(int num, long value) {
            this.num = num;
            this.value = value;
        }
        
        public int hashCode() {
            return num;
        }
        
        public boolean equals(Object o) {
            Numbers x = (Numbers)o;
            return x.num == num;
        }
        
        public int compareTo(Numbers another) {
            if (value == another.value) {
                return num - another.num;
            } else if (value < another.value) {
                return -1;
            } else {
                return 1;
            }
        }
        
        public String toString() {
            return String.valueOf(num);
        }
        
        public void add(long x) {
            value += x;
        }
    }
}

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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0