結果

問題 No.1705 Mode of long array
ユーザー tentententen
提出日時 2023-04-26 09:04:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 871 ms / 3,000 ms
コード長 3,231 bytes
コンパイル時間 2,760 ms
コンパイル使用メモリ 92,020 KB
実行使用メモリ 70,036 KB
最終ジャッジ日時 2024-04-27 14:46:52
合計ジャッジ時間 31,258 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
50,424 KB
testcase_01 AC 51 ms
49,912 KB
testcase_02 AC 53 ms
50,248 KB
testcase_03 AC 119 ms
53,052 KB
testcase_04 AC 100 ms
52,020 KB
testcase_05 AC 136 ms
53,620 KB
testcase_06 AC 169 ms
56,224 KB
testcase_07 AC 185 ms
57,808 KB
testcase_08 AC 183 ms
57,724 KB
testcase_09 AC 166 ms
57,696 KB
testcase_10 AC 172 ms
57,668 KB
testcase_11 AC 168 ms
57,488 KB
testcase_12 AC 175 ms
57,808 KB
testcase_13 AC 649 ms
64,352 KB
testcase_14 AC 540 ms
63,456 KB
testcase_15 AC 412 ms
58,892 KB
testcase_16 AC 519 ms
61,072 KB
testcase_17 AC 436 ms
58,896 KB
testcase_18 AC 409 ms
59,024 KB
testcase_19 AC 585 ms
61,308 KB
testcase_20 AC 466 ms
60,996 KB
testcase_21 AC 574 ms
65,072 KB
testcase_22 AC 703 ms
67,376 KB
testcase_23 AC 374 ms
58,364 KB
testcase_24 AC 390 ms
58,344 KB
testcase_25 AC 371 ms
58,528 KB
testcase_26 AC 388 ms
58,680 KB
testcase_27 AC 379 ms
58,412 KB
testcase_28 AC 374 ms
58,384 KB
testcase_29 AC 375 ms
58,788 KB
testcase_30 AC 397 ms
58,604 KB
testcase_31 AC 380 ms
58,556 KB
testcase_32 AC 389 ms
58,488 KB
testcase_33 AC 871 ms
69,868 KB
testcase_34 AC 838 ms
69,968 KB
testcase_35 AC 851 ms
69,860 KB
testcase_36 AC 854 ms
69,880 KB
testcase_37 AC 834 ms
69,964 KB
testcase_38 AC 851 ms
70,036 KB
testcase_39 AC 856 ms
69,956 KB
testcase_40 AC 817 ms
69,920 KB
testcase_41 AC 834 ms
69,780 KB
testcase_42 AC 857 ms
69,988 KB
testcase_43 AC 529 ms
67,360 KB
testcase_44 AC 546 ms
67,548 KB
testcase_45 AC 534 ms
67,732 KB
testcase_46 AC 518 ms
67,964 KB
testcase_47 AC 550 ms
67,968 KB
testcase_48 AC 544 ms
67,916 KB
testcase_49 AC 665 ms
67,480 KB
testcase_50 AC 653 ms
67,856 KB
testcase_51 AC 739 ms
68,264 KB
testcase_52 AC 689 ms
67,072 KB
testcase_53 AC 671 ms
67,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0