結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
testcase_04 RE -
testcase_05 AC 307 ms
14,460 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 241 ms
13,840 KB
testcase_10 AC 228 ms
13,588 KB
testcase_11 AC 414 ms
15,552 KB
testcase_12 AC 436 ms
15,680 KB
testcase_13 AC 280 ms
14,200 KB
testcase_14 AC 405 ms
8,320 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 264 ms
8,120 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 368 ms
8,320 KB
testcase_39 AC 436 ms
10,112 KB
testcase_40 RE -
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[200005];
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