結果

問題 No.1705 Mode of long array
ユーザー tentententen
提出日時 2023-11-30 17:12:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 969 ms / 3,000 ms
コード長 3,066 bytes
コンパイル時間 4,076 ms
コンパイル使用メモリ 92,256 KB
実行使用メモリ 73,576 KB
最終ジャッジ日時 2023-11-30 17:13:14
合計ジャッジ時間 35,404 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,996 KB
testcase_01 AC 54 ms
54,008 KB
testcase_02 AC 54 ms
53,996 KB
testcase_03 AC 132 ms
56,704 KB
testcase_04 AC 104 ms
55,788 KB
testcase_05 AC 135 ms
56,828 KB
testcase_06 AC 173 ms
60,136 KB
testcase_07 AC 177 ms
60,696 KB
testcase_08 AC 190 ms
61,372 KB
testcase_09 AC 175 ms
61,412 KB
testcase_10 AC 176 ms
61,320 KB
testcase_11 AC 185 ms
60,556 KB
testcase_12 AC 176 ms
61,492 KB
testcase_13 AC 712 ms
69,232 KB
testcase_14 AC 598 ms
66,964 KB
testcase_15 AC 425 ms
62,632 KB
testcase_16 AC 578 ms
64,792 KB
testcase_17 AC 427 ms
62,596 KB
testcase_18 AC 412 ms
62,556 KB
testcase_19 AC 635 ms
64,932 KB
testcase_20 AC 483 ms
64,928 KB
testcase_21 AC 636 ms
69,080 KB
testcase_22 AC 855 ms
73,504 KB
testcase_23 AC 422 ms
62,192 KB
testcase_24 AC 409 ms
62,300 KB
testcase_25 AC 389 ms
62,304 KB
testcase_26 AC 392 ms
62,316 KB
testcase_27 AC 402 ms
62,168 KB
testcase_28 AC 400 ms
62,096 KB
testcase_29 AC 404 ms
62,276 KB
testcase_30 AC 387 ms
62,264 KB
testcase_31 AC 397 ms
62,260 KB
testcase_32 AC 410 ms
62,324 KB
testcase_33 AC 928 ms
73,504 KB
testcase_34 AC 940 ms
73,432 KB
testcase_35 AC 936 ms
73,380 KB
testcase_36 AC 935 ms
73,456 KB
testcase_37 AC 944 ms
73,556 KB
testcase_38 AC 933 ms
73,524 KB
testcase_39 AC 969 ms
73,576 KB
testcase_40 AC 911 ms
73,392 KB
testcase_41 AC 960 ms
73,552 KB
testcase_42 AC 928 ms
73,548 KB
testcase_43 AC 565 ms
71,384 KB
testcase_44 AC 542 ms
71,500 KB
testcase_45 AC 575 ms
71,208 KB
testcase_46 AC 541 ms
71,272 KB
testcase_47 AC 574 ms
71,252 KB
testcase_48 AC 540 ms
70,624 KB
testcase_49 AC 763 ms
71,676 KB
testcase_50 AC 723 ms
71,908 KB
testcase_51 AC 733 ms
72,148 KB
testcase_52 AC 712 ms
71,748 KB
testcase_53 AC 717 ms
70,992 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();
        Count[] counts = new Count[m];
        TreeSet<Count> all = new TreeSet<>();
        for (int i = 0; i < m; i++) {
            counts[i] = new Count(i, sc.nextLong());
            all.add(counts[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) {
                all.remove(counts[idx]);
                counts[idx].value += value;
                all.add(counts[idx]);
            } else if (type == 2) {
                all.remove(counts[idx]);
                counts[idx].value -= value;
                all.add(counts[idx]);
            } else {
                sb.append(all.last().idx + 1).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Count implements Comparable<Count> {
        int idx;
        long value;
        
        public Count(int idx, long value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int hashCode() {
            return idx;
        }
        
        public int compareTo(Count another) {
            if (value == another.value) {
                return idx - another.idx;
            } else if (value < another.value) {
                return -1;
            } else {
                return 1;
            }
        }
        
        public boolean equals(Object another) {
            return hashCode() == another.hashCode();
        }
    }
}
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