結果

問題 No.1000 Point Add and Array Add
ユーザー ゆきのんゆきのん
提出日時 2020-02-28 21:47:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 623 ms / 2,000 ms
コード長 2,185 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 176,424 KB
実行使用メモリ 39,708 KB
最終ジャッジ日時 2024-04-21 18:17:21
合計ジャッジ時間 7,903 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,768 KB
testcase_01 AC 3 ms
7,760 KB
testcase_02 AC 3 ms
11,716 KB
testcase_03 AC 3 ms
9,680 KB
testcase_04 AC 3 ms
11,844 KB
testcase_05 AC 3 ms
7,888 KB
testcase_06 AC 4 ms
13,768 KB
testcase_07 AC 2 ms
7,764 KB
testcase_08 AC 3 ms
9,680 KB
testcase_09 AC 4 ms
9,680 KB
testcase_10 AC 4 ms
9,676 KB
testcase_11 AC 3 ms
9,812 KB
testcase_12 AC 6 ms
7,656 KB
testcase_13 AC 6 ms
13,768 KB
testcase_14 AC 7 ms
7,916 KB
testcase_15 AC 7 ms
16,104 KB
testcase_16 AC 405 ms
35,056 KB
testcase_17 AC 351 ms
19,068 KB
testcase_18 AC 580 ms
39,708 KB
testcase_19 AC 577 ms
35,840 KB
testcase_20 AC 623 ms
27,264 KB
testcase_21 AC 451 ms
32,644 KB
testcase_22 AC 623 ms
31,752 KB
testcase_23 AC 467 ms
33,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


static const int MAX_SIZE = 1 << 20; 

LL segMax[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

//区間[a, b)に値xを加算する.
void add(int a, int b, LL x, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (r <= a || b <= l) return;

    if (a <= l && r <= b){
        segAdd[k] += x;
        return;
    }

    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);

    segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
}

LL getMax(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (r <= a || b <= l) return 0;

    if (a <= l && r <= b) return (segMax[k] + segAdd[k]);

    LL left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
    LL right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);

    return (max(left, right) + segAdd[k]);
}


int main(){
    int n,q;cin >> n >> q;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<LL> ans(n,0);
    map<int,vector<P>> m;
    while(q--){
        char c;cin >> c;
        LL x,y;cin >> x >> y;
        x--;
        if(c=='A'){
            auto t = getMax(x,x+1);
            m[x].pb(mp(t,y));
        }
        else{
            add(x,y,1);
        }
    }
    for (int i = 0; i < n; i++) {
        auto t = getMax(i,i+1);
        ans[i] = t * a[i];
        for (int j = 0; j < m[i].size(); j++) {
            ans[i] += (t - m[i][j].fs) * m[i][j].sc;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << (i == n-1?"\n":" ");
    }
    return 0;
}
0