結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-10-14 23:44:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 742 ms / 6,000 ms
コード長 1,737 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 213,908 KB
実行使用メモリ 31,308 KB
最終ジャッジ日時 2023-09-09 00:11:47
合計ジャッジ時間 30,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,424 KB
testcase_01 AC 2 ms
7,488 KB
testcase_02 AC 2 ms
7,532 KB
testcase_03 AC 250 ms
21,584 KB
testcase_04 AC 520 ms
22,572 KB
testcase_05 AC 254 ms
18,584 KB
testcase_06 AC 457 ms
20,688 KB
testcase_07 AC 503 ms
31,308 KB
testcase_08 AC 527 ms
23,100 KB
testcase_09 AC 207 ms
16,412 KB
testcase_10 AC 211 ms
17,600 KB
testcase_11 AC 387 ms
19,104 KB
testcase_12 AC 396 ms
19,980 KB
testcase_13 AC 254 ms
15,488 KB
testcase_14 AC 393 ms
15,376 KB
testcase_15 AC 590 ms
24,216 KB
testcase_16 AC 385 ms
22,272 KB
testcase_17 AC 253 ms
12,340 KB
testcase_18 AC 731 ms
28,832 KB
testcase_19 AC 727 ms
28,444 KB
testcase_20 AC 725 ms
28,376 KB
testcase_21 AC 721 ms
28,356 KB
testcase_22 AC 728 ms
29,012 KB
testcase_23 AC 726 ms
29,232 KB
testcase_24 AC 742 ms
27,912 KB
testcase_25 AC 719 ms
29,148 KB
testcase_26 AC 726 ms
29,040 KB
testcase_27 AC 724 ms
28,380 KB
testcase_28 AC 740 ms
28,800 KB
testcase_29 AC 727 ms
27,988 KB
testcase_30 AC 724 ms
29,600 KB
testcase_31 AC 736 ms
28,296 KB
testcase_32 AC 725 ms
28,508 KB
testcase_33 AC 688 ms
29,276 KB
testcase_34 AC 698 ms
28,716 KB
testcase_35 AC 713 ms
28,316 KB
testcase_36 AC 694 ms
28,252 KB
testcase_37 AC 700 ms
29,360 KB
testcase_38 AC 399 ms
16,688 KB
testcase_39 AC 453 ms
17,296 KB
testcase_40 AC 663 ms
28,596 KB
testcase_41 AC 2 ms
7,528 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] - 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