結果

問題 No.1000 Point Add and Array Add
ユーザー kyort0nkyort0n
提出日時 2020-02-28 21:34:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 2,204 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 169,516 KB
実行使用メモリ 11,788 KB
最終ジャッジ日時 2024-04-21 18:03:34
合計ジャッジ時間 5,280 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,376 KB
testcase_01 AC 5 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 6 ms
5,504 KB
testcase_16 AC 112 ms
10,240 KB
testcase_17 AC 91 ms
9,216 KB
testcase_18 AC 150 ms
11,776 KB
testcase_19 AC 155 ms
11,564 KB
testcase_20 AC 157 ms
11,784 KB
testcase_21 AC 131 ms
11,788 KB
testcase_22 AC 161 ms
11,776 KB
testcase_23 AC 135 ms
11,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N, Q;
ll A[200000];
ll B[200000];
char c[200000];
ll x[200000], y[200000];
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree() {
        int sz = 200001;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = 0;
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
 
    void add(int x, int val) {
        x += (n - 1);
        node[x] += val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]);
        }
    }
    // hannkaikukann 
    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr);
    }
};


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Q;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < Q; i++) {
        cin >> c[i] >> x[i] >> y[i];
    }
    SegmentTree seg;
    for(int i = Q - 1; i >= 0; i--) {
        if(c[i] == 'A') {
            x[i]--;
            ll num = seg.getsum(0, x[i] + 1);
            B[x[i]] += num * y[i];
        } else {
            x[i]--;
            y[i]--;
            seg.add(x[i], 1);
            seg.add(y[i]+1, -1);
        }
    }
    for(int i = 0; i < N; i++) {
        ll num = seg.getsum(0, i + 1);
        B[i] += num * A[i];
    }
    for(int i = 0; i < N; i++) {
        if(i != 0) cout << " ";
        cout << B[i];
    }
    cout << endl;
    return 0;
}
0