結果

問題 No.1000 Point Add and Array Add
ユーザー sugarrrsugarrr
提出日時 2020-02-28 21:41:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 2,979 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 171,492 KB
実行使用メモリ 20,944 KB
最終ジャッジ日時 2024-04-21 18:10:00
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
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 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 164 ms
18,428 KB
testcase_17 AC 141 ms
13,172 KB
testcase_18 AC 241 ms
20,892 KB
testcase_19 AC 240 ms
20,780 KB
testcase_20 AC 158 ms
20,796 KB
testcase_21 AC 249 ms
20,844 KB
testcase_22 AC 203 ms
20,792 KB
testcase_23 AC 248 ms
20,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////
// 区間加算区間和
struct RSQRAQ {
    ll n;
    vector<ll> dat, lazy;
    RSQRAQ(){}
    RSQRAQ(ll n_) {
        n = 1; while(n < n_) n *= 2;
        dat.assign(n*2, 0);
        lazy.assign(n*2, 0);
    }
    void eval(ll len, ll k) {
        if(lazy[k] == 0) return;
        if(k*2+1 < n*2-1) {
            lazy[2*k+1] += lazy[k];
            lazy[2*k+2] += lazy[k];
        }
        dat[k] += lazy[k]*len;
        lazy[k] = 0;
    }
    // [a, b)にxを加える
    ll update(ll a, ll b, ll x, ll k, ll l, ll r) {
        eval(r-l, k);
        if(b <= l || r <= a) return dat[k];
        if(a <= l && r <= b) {
            lazy[k] += x;
            return dat[k] + lazy[k]*(r-l);
        }
        return dat[k] = update(a, b, x, 2*k+1, l, (l+r)/2) + update(a, b, x, 2*k+2, (l+r)/2, r);
    }
    ll update(ll a, ll b, ll x) { return update(a, b, x, 0, 0, n); }
    // [a, b)の和を求める
    ll query(ll a, ll b, ll k, ll l, ll r) {
        eval(r-l, k);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return dat[k];
        ll vl = query(a, b, 2*k+1, l, (l+r)/2);
        ll vr = query(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
    ll query(ll a, ll b) { return query(a, b, 0, 0, n); }
};
//セグ木なので番号は0~n-1
/////////////////////////////////////////


int main(){fastio
    ll n,q;cin>>n>>q;
    ll a[n+1];rep(i,1,n)cin>>a[i];
    ll z[q],x[q],y[q];
    rep(i,0,q-1){
        string s;cin>>s;
        if(s[0]=='A')z[i]=0;
        else z[i]=1;
        cin>>x[i]>>y[i];
    }
    
    ll ans[n+1];
    ll imos[n+2];memset(imos,0,sizeof(imos));
    rep(i,0,q-1){
        if(z[i]==1){
            imos[x[i]]++;
            imos[y[i]+1]--;
        }
    }
    rep(i,0,n)imos[i+1]+=imos[i];
    rep(i,1,n)ans[i]=imos[i]*a[i];
    //rep(i,1,n)cout<<ans[i]<<" ";cout<<endl;
    
    RSQRAQ u(n+2);
    for(ll i=q-1;i>=0;i--){
        if(z[i]==0){
            ll kai=u.query(x[i],x[i]+1);
            ans[x[i]]+=kai*y[i];
        }else{
            u.update(x[i],y[i]+1,1);
        }
    }
    rep(i,1,n)cout<<ans[i]<<" ";
    
    return 0;
}
0