結果

問題 No.1000 Point Add and Array Add
ユーザー Ricky_ponRicky_pon
提出日時 2020-02-28 23:20:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,704 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 182,060 KB
実行使用メモリ 46,700 KB
最終ジャッジ日時 2024-04-21 20:48:05
合計ジャッジ時間 6,717 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
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 227 ms
34,852 KB
testcase_21 AC 316 ms
46,700 KB
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

struct SegTree_dual{
    int sz = 1;
    vector<vector<int>> node;

    SegTree_dual(int sz_){
        while(sz < sz_) sz *= 2;
        node.resize(sz*2-1, {});
    }

    void update(int a, int b, int x, int i, int l, int r){
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            node[i].push_back(x);
            return;
        }
        update(a, b, x, i*2+1, l, (l+r)/2);
        update(a, b, x, i*2+2, (l+r)/2, r);
    }

    inline void f(int i, vector<int> &b, vector<int> &cnt){
        if(node[i].empty()) return;
        rep(j, b.size()){
            int tmp = node[i].end() - lower_bound(node[i].begin(), node[i].end(), b[j]);
            cnt[0] += tmp;
            cnt[j+1] -= tmp;
        }
    }

    lint query(int i, lint a, vector<int> &b, vector<lint> &v){
        lint ret = 0;
        vector<int> cnt(b.size()+1, 0);
        i += sz - 1;
        f(i, b, cnt);
        ret += a * node[i].size();
        while(i){
            i = (i-1) / 2;
            f(i, b, cnt);
            ret += a * node[i].size();
        }
        partial_sum(cnt.begin(), cnt.end(), cnt.begin());
        rep(j, b.size()) ret += v[j] * cnt[j];
        return ret;
    }
};

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    lint a[n];
    rep(i, n) scanf("%lld", &a[i]);
    SegTree_dual st(n);
    vector<vector<int>> b(n, vector<int>(0));
    vector<vector<lint>> v(n, vector<lint>(0));

    rep(i, q){
        char c;
        int x;
        lint y;
        scanf(" %c%d%lld", &c, &x, &y);
        --x;
        if(c == 'A'){
            b[x].push_back(i);
            v[x].push_back(y);
        }
        else{
            st.update(x, y, i, 0, 0, st.sz);
        }
    }

    rep(i, n) printf("%lld ", st.query(i, a[i], b[i], v[i]));
}
0