結果

問題 No.1000 Point Add and Array Add
ユーザー noriocnorioc
提出日時 2020-05-07 14:09:17
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,337 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 169,924 KB
実行使用メモリ 44,040 KB
最終ジャッジ日時 2023-09-04 07:40:55
合計ジャッジ時間 6,926 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,796 KB
testcase_01 AC 5 ms
11,784 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 4 ms
11,804 KB
testcase_05 AC 5 ms
11,732 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 263 ms
40,904 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

const segSize = 1 << 20;
int[segSize * 2] seg;

void update(int l, int r, int v) {
    l += segSize;
    r += segSize;
    while (l < r) {
        if (l % 2 == 1) {
            seg[l] += v;
            l++;
        }
        l /= 2;
        if (r % 2 == 1) {
            seg[r - 1] += v;
            r--;
        }
        r /= 2;
    }
}

int get(int ind) {
    ind += segSize;
    int v = seg[ind];
    while (true) {
        ind /= 2; // 上にのぼる
        if (ind == 0) break;
        v += seg[ind];
    }
    return v;
}

alias Q = Tuple!(string, "c", int, "x", int, "y");

void main() {
    int n, q; scan(n, q);
    auto a = readints;
    Q[] qs;
    foreach (_; 0..q) {
        string c; int x, y; scan(c, x, y);
        qs ~= Q(c, x, y);
    }

    auto ans = new int[n + 1];
    foreach_reverse (e; qs) {
        if (e.c == "A") {
            ans[e.x] += e.y * get(e.x);
        }
        if (e.c == "B") {
            update(e.x, e.y + 1, 1);
        }
    }

    foreach (i; 1..n+1) {
        ans[i] += a[i-1] * (get(i) + 0);
    }

    writeln(ans[1..$].map!text.join(' '));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;
0