結果

問題 No.1705 Mode of long array
ユーザー tentententen
提出日時 2023-11-30 17:05:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 576 ms / 3,000 ms
コード長 3,198 bytes
コンパイル時間 3,064 ms
コンパイル使用メモリ 91,384 KB
実行使用メモリ 69,268 KB
最終ジャッジ日時 2023-11-30 17:06:29
合計ジャッジ時間 28,648 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,984 KB
testcase_01 AC 57 ms
53,988 KB
testcase_02 AC 59 ms
53,992 KB
testcase_03 AC 119 ms
55,788 KB
testcase_04 AC 110 ms
55,932 KB
testcase_05 AC 116 ms
55,688 KB
testcase_06 AC 151 ms
59,648 KB
testcase_07 AC 156 ms
59,260 KB
testcase_08 AC 157 ms
60,288 KB
testcase_09 AC 146 ms
58,292 KB
testcase_10 AC 149 ms
59,860 KB
testcase_11 AC 153 ms
59,508 KB
testcase_12 AC 154 ms
59,684 KB
testcase_13 AC 475 ms
66,496 KB
testcase_14 AC 419 ms
63,476 KB
testcase_15 AC 353 ms
62,328 KB
testcase_16 AC 409 ms
62,900 KB
testcase_17 AC 336 ms
62,376 KB
testcase_18 AC 324 ms
61,464 KB
testcase_19 AC 457 ms
62,544 KB
testcase_20 AC 385 ms
62,244 KB
testcase_21 AC 437 ms
66,384 KB
testcase_22 AC 497 ms
66,888 KB
testcase_23 AC 330 ms
62,180 KB
testcase_24 AC 362 ms
62,232 KB
testcase_25 AC 334 ms
62,080 KB
testcase_26 AC 323 ms
62,292 KB
testcase_27 AC 320 ms
62,108 KB
testcase_28 AC 359 ms
62,088 KB
testcase_29 AC 326 ms
62,068 KB
testcase_30 AC 323 ms
62,140 KB
testcase_31 AC 345 ms
62,100 KB
testcase_32 AC 320 ms
62,204 KB
testcase_33 AC 510 ms
66,532 KB
testcase_34 AC 520 ms
65,424 KB
testcase_35 AC 511 ms
66,528 KB
testcase_36 AC 539 ms
66,536 KB
testcase_37 AC 515 ms
66,488 KB
testcase_38 AC 525 ms
66,580 KB
testcase_39 AC 481 ms
65,460 KB
testcase_40 AC 487 ms
65,388 KB
testcase_41 AC 515 ms
66,472 KB
testcase_42 AC 514 ms
66,536 KB
testcase_43 AC 523 ms
68,860 KB
testcase_44 AC 483 ms
68,860 KB
testcase_45 AC 486 ms
69,208 KB
testcase_46 AC 554 ms
68,952 KB
testcase_47 AC 501 ms
69,268 KB
testcase_48 AC 508 ms
68,964 KB
testcase_49 AC 528 ms
66,512 KB
testcase_50 AC 551 ms
66,572 KB
testcase_51 AC 532 ms
66,528 KB
testcase_52 AC 576 ms
66,528 KB
testcase_53 AC 521 ms
66,548 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();
        SegmentTree st = new SegmentTree(m);
        for (int i = 0; i < m; i++) {
            st.add(i, sc.nextLong());
        }
        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) {
                st.add(idx, value);
            } else if (type == 2) {
                st.add(idx, -value);
            } else {
                sb.append(st.getIdx() + 1).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class SegmentTree {
        int size;
        long[] values;
        int[] idxes;
        
        public SegmentTree(int x) {
            size = 1;
            while (x > size) {
                size <<= 1;
            }
            values = new long[size * 2 - 1];
            idxes = new int[size * 2 - 1];
            for (int i = 0; i < size; i++) {
                idxes[size - 1 + i] = i;
            }
        }
        
        public void add(int idx, long v) {
            values[idx + size - 1] += v;
            update((idx + size - 2) / 2);
        }
        
        private void update(int idx) {
            if (values[idx * 2 + 1] <= values[idx * 2 + 2]) {
                values[idx] = values[idx * 2 + 2];
                idxes[idx] = idxes[idx * 2 + 2];
            } else {
                values[idx] = values[idx * 2 + 1];
                idxes[idx] = idxes[idx * 2 + 1];
            }
            if (idx > 0) {
                update((idx - 1) / 2);
            }
        }
        
        public int getIdx() {
            return idxes[0];
        }
    }
}
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