結果

問題 No.1000 Point Add and Array Add
ユーザー noriocnorioc
提出日時 2020-05-07 14:12:13
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,339 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 180,200 KB
実行使用メモリ 44,112 KB
最終ジャッジ日時 2024-06-22 06:54:58
合計ジャッジ時間 6,073 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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;
    }
}

long 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 long[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