結果

問題 No.1705 Mode of long array
ユーザー tentententen
提出日時 2023-01-13 18:21:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 933 ms / 3,000 ms
コード長 2,925 bytes
コンパイル時間 2,829 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 71,016 KB
最終ジャッジ日時 2023-08-26 00:40:05
合計ジャッジ時間 36,691 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,700 KB
testcase_01 AC 45 ms
49,760 KB
testcase_02 AC 46 ms
50,172 KB
testcase_03 AC 126 ms
53,868 KB
testcase_04 AC 93 ms
52,424 KB
testcase_05 AC 119 ms
55,520 KB
testcase_06 AC 165 ms
56,800 KB
testcase_07 AC 174 ms
58,408 KB
testcase_08 AC 174 ms
58,664 KB
testcase_09 AC 167 ms
58,752 KB
testcase_10 AC 168 ms
58,280 KB
testcase_11 AC 171 ms
58,240 KB
testcase_12 AC 168 ms
58,944 KB
testcase_13 AC 734 ms
66,140 KB
testcase_14 AC 573 ms
63,580 KB
testcase_15 AC 458 ms
59,036 KB
testcase_16 AC 541 ms
59,152 KB
testcase_17 AC 452 ms
58,808 KB
testcase_18 AC 433 ms
59,512 KB
testcase_19 AC 625 ms
61,696 KB
testcase_20 AC 487 ms
60,840 KB
testcase_21 AC 607 ms
65,560 KB
testcase_22 AC 816 ms
71,016 KB
testcase_23 AC 393 ms
58,740 KB
testcase_24 AC 391 ms
58,532 KB
testcase_25 AC 393 ms
58,328 KB
testcase_26 AC 395 ms
58,604 KB
testcase_27 AC 403 ms
58,292 KB
testcase_28 AC 382 ms
59,016 KB
testcase_29 AC 381 ms
58,732 KB
testcase_30 AC 384 ms
58,912 KB
testcase_31 AC 391 ms
58,624 KB
testcase_32 AC 390 ms
58,528 KB
testcase_33 AC 906 ms
70,548 KB
testcase_34 AC 891 ms
70,496 KB
testcase_35 AC 912 ms
70,272 KB
testcase_36 AC 909 ms
70,572 KB
testcase_37 AC 928 ms
70,296 KB
testcase_38 AC 911 ms
68,968 KB
testcase_39 AC 917 ms
70,728 KB
testcase_40 AC 902 ms
70,660 KB
testcase_41 AC 933 ms
70,960 KB
testcase_42 AC 925 ms
71,012 KB
testcase_43 AC 537 ms
68,416 KB
testcase_44 AC 536 ms
69,196 KB
testcase_45 AC 538 ms
68,524 KB
testcase_46 AC 546 ms
68,396 KB
testcase_47 AC 536 ms
68,760 KB
testcase_48 AC 540 ms
68,020 KB
testcase_49 AC 702 ms
69,680 KB
testcase_50 AC 688 ms
69,764 KB
testcase_51 AC 699 ms
69,092 KB
testcase_52 AC 720 ms
69,032 KB
testcase_53 AC 701 ms
70,304 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();
        Unit[] units = new Unit[m];
        TreeSet<Unit> all = new TreeSet<>();
        for (int i = 0; i < m; i++) {
            units[i] = new Unit(i, sc.nextLong());
            all.add(units[i]);
        }
        StringBuilder sb = new StringBuilder();
        int q = sc.nextInt();
        while (q-- > 0) {
            int type = sc.nextInt();
            int idx = sc.nextInt() - 1;
            long value = sc.nextLong();
            if (type == 1) {
                all.remove(units[idx]);
                units[idx].add(value);
                all.add(units[idx]);
            } else if (type == 2) {
                all.remove(units[idx]);
                units[idx].add(-value);
                all.add(units[idx]);
            } else {
                sb.append(all.last().idx + 1).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Unit implements Comparable<Unit> {
        int idx;
        long value;
        
        public Unit(int idx, long value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Unit another) {
            if (value == another.value) {
                return idx - another.idx;
            } else if (value < another.value) {
                return -1;
            } else {
                return 1;
            }
        }
        
        public void add(long v) {
            value += v;
        }
    }
}

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