結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-10-14 23:42:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,744 bytes
コンパイル時間 3,117 ms
コンパイル使用メモリ 215,092 KB
実行使用メモリ 31,880 KB
最終ジャッジ日時 2023-09-09 00:10:56
合計ジャッジ時間 30,160 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
7,276 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 3 ms
7,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll bit[200020];
ll bi2[200020];
int N;
ll A[200020];
ll T[200020];
void add(int i, ll x, int t) {
    while (i <= N) {
        if (t) {
            bi2[i] += x;
        } else {
            bit[i] += x;
        }
        i += (i & (-i));
    }
}
ll sum(int i, int t) {
    ll ret = 0;
    while (i) {
        if (t) {
            ret += bi2[i];
        } else {
            ret += bit[i];
        }
        i -= (i & (-i));
    }
    return ret;
}
void sw(int i, int t) {
    if (t == 0) {
        add(i, T[i] + A[i] - 1, 0);
        add(i, -1, 1);
    } else {
        add(i, 1 - A[i] - T[i], 0);
        add(i, 1, 1);
    }
}
int main () {
    cin >> N;
    for (int i = 1; i <= N; i ++) {
        cin >> A[i] >> T[i];
    }
    for (int i = 0; i <= N; i ++) {
        bit[i] = bi2[i] = 0;
    }
    for (int i = 1; i <= N; i ++) {
        add(i, A[i], 0);
    }
    int Q;
    cin >> Q;
    vector<tuple<ll, int, int, int>> X(Q);
    int sss = 0;
    for (auto& [a, b, c, d] : X) {
        cin >> a >> b >> c;
        d = sss;
        sss ++;
    }
    for (int i = 1; i <= N; i ++) {
        if (A[i] == 0) {
            continue;
        }
        X.emplace_back(T[i], -1, -1, i);
        X.emplace_back(T[i] + A[i] - 1, -2, -1, i);
    }
    vector<ll> ans(Q);
    sort(X.begin(), X.end());
    for (auto [a, b, c, d] : X) {
        if (b > 0) {
            ans[d] = sum(c, 0) - sum(b - 1, 0);
            ans[d] += (sum(c, 1) - sum(b - 1, 1)) * a;
        } else if (b == -1) {
            sw(d, 0);
        } else {
            sw(d, 1);
        }
    }
    for (auto a : ans) {
        cout << a << endl;
        if (a < 0) {
            return 139;
        }
    }
}
0