結果

問題 No.1705 Mode of long array
ユーザー nebukuro09nebukuro09
提出日時 2021-10-08 23:06:36
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 215 ms / 3,000 ms
コード長 1,880 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 107,608 KB
実行使用メモリ 13,300 KB
最終ジャッジ日時 2023-09-04 14:25:02
合計ジャッジ時間 14,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 12 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 154 ms
12,104 KB
testcase_14 AC 109 ms
7,448 KB
testcase_15 AC 109 ms
4,504 KB
testcase_16 AC 129 ms
4,772 KB
testcase_17 AC 92 ms
4,636 KB
testcase_18 AC 74 ms
5,848 KB
testcase_19 AC 147 ms
6,804 KB
testcase_20 AC 90 ms
6,940 KB
testcase_21 AC 116 ms
12,268 KB
testcase_22 AC 177 ms
11,912 KB
testcase_23 AC 99 ms
4,376 KB
testcase_24 AC 99 ms
4,380 KB
testcase_25 AC 99 ms
4,380 KB
testcase_26 AC 99 ms
4,376 KB
testcase_27 AC 100 ms
4,380 KB
testcase_28 AC 99 ms
4,380 KB
testcase_29 AC 99 ms
4,376 KB
testcase_30 AC 98 ms
4,380 KB
testcase_31 AC 99 ms
4,380 KB
testcase_32 AC 99 ms
4,376 KB
testcase_33 AC 210 ms
11,780 KB
testcase_34 AC 209 ms
12,596 KB
testcase_35 AC 209 ms
12,068 KB
testcase_36 AC 209 ms
11,624 KB
testcase_37 AC 209 ms
11,936 KB
testcase_38 AC 210 ms
12,648 KB
testcase_39 AC 215 ms
12,136 KB
testcase_40 AC 214 ms
12,644 KB
testcase_41 AC 213 ms
12,140 KB
testcase_42 AC 213 ms
13,248 KB
testcase_43 AC 164 ms
12,700 KB
testcase_44 AC 165 ms
12,632 KB
testcase_45 AC 164 ms
13,012 KB
testcase_46 AC 164 ms
12,884 KB
testcase_47 AC 165 ms
12,860 KB
testcase_48 AC 164 ms
12,664 KB
testcase_49 AC 207 ms
13,300 KB
testcase_50 AC 208 ms
11,948 KB
testcase_51 AC 204 ms
11,568 KB
testcase_52 AC 204 ms
12,452 KB
testcase_53 AC 206 ms
12,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto M = s[1].to!int;
    auto A = readln.split.map!(to!long).array;

    auto st = new SegmentTree!(Tuple!(long, int), max, tuple(-1L, 0))(M);
    foreach (i, a; A) st.assign(i.to!int, tuple(a, i.to!int));

    auto Q = readln.chomp.to!int;

    foreach (_; 0..Q) {
        s = readln.split.map!(to!long);
        if (s[0] == 1) {
            auto x = s[1].to!int - 1;
            auto y = s[2];
            auto v = st.query(x, x);
            st.assign(x, tuple(v[0]+y, v[1]));
        } else if (s[0] == 2) {
            auto x = s[1].to!int - 1;
            auto y = s[2];
            auto v = st.query(x, x);
            st.assign(x, tuple(v[0]-y, v[1]));
        } else {
            (st.query(0, M-1)[1] + 1).writeln;
        }
    }
}

class SegmentTree(T, alias op, T e) {
    T[] table;
    int size;
    int offset;

    this(int n) {
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        fill(table, e);
        offset = size / 2;
    }

    void assign(int pos, T val) {
        pos += offset;
        table[pos] = val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    T query(int l, int r) {
        return query(l, r, 1, 0, offset-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) {
            return e;
        } else if (l <= a && b <= r) {
            return table[i];
        } else {
            return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }
}
0