結果

問題 No.1000 Point Add and Array Add
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-02-29 01:49:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 3,392 bytes
コンパイル時間 2,991 ms
コンパイル使用メモリ 205,780 KB
実行使用メモリ 15,664 KB
最終ジャッジ日時 2023-08-03 22:29:47
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,236 KB
testcase_01 AC 6 ms
13,276 KB
testcase_02 AC 6 ms
13,400 KB
testcase_03 AC 6 ms
13,404 KB
testcase_04 AC 6 ms
13,240 KB
testcase_05 AC 6 ms
13,336 KB
testcase_06 AC 6 ms
13,476 KB
testcase_07 AC 6 ms
13,232 KB
testcase_08 AC 6 ms
13,432 KB
testcase_09 AC 6 ms
13,228 KB
testcase_10 AC 7 ms
13,344 KB
testcase_11 AC 6 ms
13,396 KB
testcase_12 AC 9 ms
13,236 KB
testcase_13 AC 8 ms
13,460 KB
testcase_14 AC 9 ms
13,240 KB
testcase_15 AC 8 ms
13,368 KB
testcase_16 AC 265 ms
15,004 KB
testcase_17 AC 229 ms
14,612 KB
testcase_18 AC 391 ms
15,184 KB
testcase_19 AC 388 ms
15,592 KB
testcase_20 AC 226 ms
15,620 KB
testcase_21 AC 441 ms
15,196 KB
testcase_22 AC 262 ms
15,664 KB
testcase_23 AC 431 ms
15,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V, int NV> struct LazySegTree { // [L,R)
    vector<V> dat, lazy; LazySegTree() { dat.resize(NV * 2, def); lazy.resize(NV * 2, ldef); }
    void update(int a, int b, V v, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return;
        if (a <= l && r <= b) { setLazy(k, v); push(k, l, r); } else {
        update(a, b, v, k * 2 + 1, l, (l + r) / 2); update(a, b, v, k * 2 + 2, (l + r) / 2, r);
        dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]);}}
    V get(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return dat[k]; auto x = get(a, b, k * 2 + 1, l, (l + r) / 2);
        auto y = get(a, b, k * 2 + 2, (l + r) / 2, r); return comp(x, y);}
    void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); }
    V get(int a, int b) { return get(a, b, 0, 0, NV); }
    // ---- Template ---------------------------------------------------------------------------------
    // 区間add, 区間総和
    const V def = 0, ldef = 0;
    V comp(V l, V r) { return l + r; }
    void setLazy(int i, V v) { lazy[i] += v; }
    void push(int k, int l, int r) {
        dat[k] += lazy[k] * (r - l);
        if (r - l > 1) { setLazy(k * 2 + 1, lazy[k]); setLazy(k * 2 + 2, lazy[k]); }
        lazy[k] = ldef;
    }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, Q, A[201010];
char C[201010]; int X[201010], Y[201010];
LazySegTree<ll, 1 << 18> cnt;
ll ans[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;
	rep(i, 0, N) cin >> A[i];
	rep(q, 0, Q) cin >> C[q] >> X[q] >> Y[q];

    rep(q, 0, Q) if (C[q] == 'B') cnt.update(X[q] - 1, Y[q], 1);
    rep(i, 0, N) ans[i] = 1LL * A[i] * cnt.get(i, i + 1);

    rep(q, 0, Q) {
        if (C[q] == 'A') {
            int i = X[q] - 1;
            ans[i] += 1LL * Y[q] * cnt.get(i, i + 1);
        } else {
            cnt.update(X[q] - 1, Y[q], -1);
        }
    }

    rep(i, 0, N) {
        if(i) printf(" ");
        printf("%lld", ans[i]);
    }
    printf("\n");
}





0