結果

問題 No.1705 Mode of long array
ユーザー tentententen
提出日時 2023-03-27 14:29:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,040 ms / 3,000 ms
コード長 3,214 bytes
コンパイル時間 2,968 ms
コンパイル使用メモリ 96,240 KB
実行使用メモリ 73,412 KB
最終ジャッジ日時 2023-10-19 14:16:20
合計ジャッジ時間 38,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,592 KB
testcase_01 AC 55 ms
53,596 KB
testcase_02 AC 58 ms
53,596 KB
testcase_03 AC 130 ms
56,476 KB
testcase_04 AC 118 ms
55,092 KB
testcase_05 AC 139 ms
56,104 KB
testcase_06 AC 179 ms
58,892 KB
testcase_07 AC 191 ms
60,912 KB
testcase_08 AC 195 ms
60,276 KB
testcase_09 AC 189 ms
60,312 KB
testcase_10 AC 181 ms
58,960 KB
testcase_11 AC 186 ms
60,300 KB
testcase_12 AC 202 ms
60,128 KB
testcase_13 AC 798 ms
67,604 KB
testcase_14 AC 620 ms
66,248 KB
testcase_15 AC 467 ms
62,304 KB
testcase_16 AC 618 ms
63,832 KB
testcase_17 AC 511 ms
61,988 KB
testcase_18 AC 461 ms
62,188 KB
testcase_19 AC 676 ms
65,064 KB
testcase_20 AC 516 ms
63,624 KB
testcase_21 AC 700 ms
68,500 KB
testcase_22 AC 930 ms
73,328 KB
testcase_23 AC 423 ms
61,568 KB
testcase_24 AC 427 ms
61,572 KB
testcase_25 AC 425 ms
61,572 KB
testcase_26 AC 430 ms
59,540 KB
testcase_27 AC 419 ms
61,556 KB
testcase_28 AC 415 ms
61,584 KB
testcase_29 AC 425 ms
61,720 KB
testcase_30 AC 429 ms
61,704 KB
testcase_31 AC 418 ms
61,428 KB
testcase_32 AC 423 ms
61,664 KB
testcase_33 AC 1,006 ms
71,328 KB
testcase_34 AC 989 ms
73,160 KB
testcase_35 AC 1,030 ms
73,232 KB
testcase_36 AC 996 ms
73,244 KB
testcase_37 AC 1,037 ms
73,332 KB
testcase_38 AC 998 ms
73,236 KB
testcase_39 AC 1,037 ms
73,188 KB
testcase_40 AC 1,040 ms
73,152 KB
testcase_41 AC 1,024 ms
73,412 KB
testcase_42 AC 988 ms
73,208 KB
testcase_43 AC 573 ms
70,900 KB
testcase_44 AC 590 ms
70,780 KB
testcase_45 AC 581 ms
70,660 KB
testcase_46 AC 617 ms
70,812 KB
testcase_47 AC 604 ms
68,988 KB
testcase_48 AC 582 ms
71,180 KB
testcase_49 AC 755 ms
72,632 KB
testcase_50 AC 752 ms
71,476 KB
testcase_51 AC 786 ms
71,616 KB
testcase_52 AC 769 ms
71,548 KB
testcase_53 AC 749 ms
72,456 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> orders = new TreeSet<>();
        for (int i = 0; i < m; i++) {
            units[i] = new Unit(i, sc.nextLong());
            orders.add(units[i]);
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int t = sc.nextInt();
            int x = sc.nextInt() - 1;
            long y = sc.nextLong();
            if (t == 1) {
                orders.remove(units[x]);
                units[x].add(y);
                orders.add(units[x]);
            } else if (t == 2) {
                orders.remove(units[x]);
                units[x].add(-y);
                orders.add(units[x]);
            } else {
                sb.append(orders.first().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 another.idx - idx;
            } else if (value < another.value) {
                return 1;
            } else {
                return -1;
            }
        }
        
        public int hashCode() {
            return idx;
        }
        
        public boolean equals(Object o) {
            Unit x = (Unit)o;
            return idx == x.idx;
        }
        
        public void add(long x) {
            value += x;
        }
        
        public String toString() {
            return "{" + idx + "," + value + "}";
        }
    }
}
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