結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー みここみここ
提出日時 2022-12-12 06:02:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 996 ms / 6,000 ms
コード長 1,709 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 99,756 KB
実行使用メモリ 27,312 KB
最終ジャッジ日時 2024-04-23 23:33:17
合計ジャッジ時間 31,150 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 281 ms
21,480 KB
testcase_04 AC 565 ms
24,152 KB
testcase_05 AC 292 ms
14,808 KB
testcase_06 AC 505 ms
23,532 KB
testcase_07 AC 566 ms
24,668 KB
testcase_08 AC 585 ms
24,004 KB
testcase_09 AC 236 ms
14,040 KB
testcase_10 AC 225 ms
13,584 KB
testcase_11 AC 423 ms
15,644 KB
testcase_12 AC 430 ms
15,900 KB
testcase_13 AC 283 ms
14,072 KB
testcase_14 AC 410 ms
8,320 KB
testcase_15 AC 701 ms
25,364 KB
testcase_16 AC 464 ms
24,012 KB
testcase_17 AC 272 ms
8,000 KB
testcase_18 AC 803 ms
27,180 KB
testcase_19 AC 807 ms
27,180 KB
testcase_20 AC 805 ms
27,180 KB
testcase_21 AC 827 ms
27,252 KB
testcase_22 AC 820 ms
27,184 KB
testcase_23 AC 856 ms
27,308 KB
testcase_24 AC 819 ms
27,164 KB
testcase_25 AC 996 ms
27,308 KB
testcase_26 AC 839 ms
27,304 KB
testcase_27 AC 814 ms
27,160 KB
testcase_28 AC 837 ms
27,304 KB
testcase_29 AC 806 ms
27,184 KB
testcase_30 AC 840 ms
27,296 KB
testcase_31 AC 823 ms
27,312 KB
testcase_32 AC 831 ms
27,312 KB
testcase_33 AC 727 ms
27,180 KB
testcase_34 AC 730 ms
27,192 KB
testcase_35 AC 728 ms
27,180 KB
testcase_36 AC 759 ms
27,304 KB
testcase_37 AC 752 ms
27,308 KB
testcase_38 AC 356 ms
8,320 KB
testcase_39 AC 423 ms
9,984 KB
testcase_40 AC 654 ms
27,304 KB
testcase_41 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/segtree>
#include <iostream>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

using S = ll;

S op(S a, S b)
{
    return a + b;
}

S e()
{
    return 0;
}

struct query
{
    int d, l, r;
    int id;

    bool operator<(const query &q) const
    {
        return (d != q.d ? d < q.d : id < q.id);
    }
};

ll a[200005];
int t[200005];
P p[400005];
query qr[200005];
ll ans[200005];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> t[i];
        p[i] = P(t[i] - 1, i);
        p[i + n] = P(t[i] + a[i] - 1, i + n);
    }
    sort(p, p + n * 2);
    segtree<S, op, e> asum(n), start(n), dcount(n);
    for (int i = 0; i < n; i++)
    {
        asum.set(i, a[i]);
        start.set(i, 0);
        dcount.set(i, 0);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> qr[i].d >> qr[i].l >> qr[i].r;
        qr[i].l--;
        qr[i].id = i;
    }
    sort(qr, qr + q);
    int j = 0;
    for (int i = 0; i < q; i++)
    {
        while (j < n * 2 && p[j].first < qr[i].d)
        {
            if (p[j].second < n)
            {
                start.set(p[j].second, p[j].first);
                dcount.set(p[j].second, 1);
            }
            else
            {
                asum.set(p[j].second - n, 0);
                start.set(p[j].second - n, 0);
                dcount.set(p[j].second - n, 0);
            }
            j++;
        }
        int l = qr[i].l, r = qr[i].r;
        ans[qr[i].id] = asum.prod(l, r) - (qr[i].d * dcount.prod(l, r) - start.prod(l, r));
    }
    for (int i = 0; i < q; i++)
    {
        cout << ans[i] << endl;
    }
}
0