結果

問題 No.618 labo-index
ユーザー merom686merom686
提出日時 2017-12-19 22:51:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,037 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 83,456 KB
実行使用メモリ 6,392 KB
最終ジャッジ日時 2024-05-09 13:02:03
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 41 ms
5,376 KB
testcase_20 AC 40 ms
5,376 KB
testcase_21 AC 40 ms
5,376 KB
testcase_22 AC 41 ms
5,376 KB
testcase_23 AC 41 ms
5,376 KB
testcase_24 AC 41 ms
5,376 KB
testcase_25 AC 41 ms
5,376 KB
testcase_26 AC 41 ms
5,376 KB
testcase_27 AC 42 ms
5,376 KB
testcase_28 AC 41 ms
5,376 KB
testcase_29 WA -
testcase_30 AC 42 ms
5,376 KB
testcase_31 AC 42 ms
5,376 KB
testcase_32 AC 41 ms
5,376 KB
testcase_33 AC 41 ms
5,376 KB
testcase_34 AC 46 ms
6,392 KB
testcase_35 AC 45 ms
6,388 KB
testcase_36 AC 32 ms
5,376 KB
testcase_37 AC 36 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) const {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    int lower_bound(int64_t s, const vector<pair<int64_t, int>>& a) const {
        //0 <= a[k].first + d + bt.sum(k) - m;
        //0 <= bt.sum(k) - s;
        if (s - a[0].first <= 0) return 0;
        int x = 0, w = 1;
        while (w << 1 <= n) w <<= 1;
        do {
            int k = x + w;
            if (k <= n && b[k] < s - a[k].first) {
                s -= b[k];
                x += w;
            }
        } while (w >>= 1);
        return x + 1;
    }
    vector<int> b;
    int n;
};

using I = int;
template <class F>
I lower_bound(I i0, I i1, F f) {
    while (i0 < i1) {
        I i = (i0 + i1) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int q;
    cin >> q;

    vector<int> t(q), x(q);
    vector<pair<int64_t, int>> a;
    int64_t d = 0;
    for (int i = 0; i < q; i++) {
        cin >> t[i] >> x[i];
        if (t[i] == 1) a.push_back(pair<int64_t, int>(x[i] - d, i));
        if (t[i] == 2) x[i] = a[x[i] - 1].second;
        if (t[i] == 3) d += x[i];
    }
    int n = a.size();

    sort(a.begin(), a.end());

    vector<int> p(q, -1);
    for (int j = 0; j < n; j++) {
        p[a[j].second] = j;
    }

    BIT bt(n);
    d = 0;
    int m = 0;
    for (int i = 0; i < q; i++) {
        if (t[i] == 1) {
            bt.add(p[i], 1);
            m++;
        } else if (t[i] == 2) {
            bt.add(p[x[i]], -1);
            m--;
        } else {
            d += x[i];
        }
        int k = bt.lower_bound(m - d, a);
        cout << (k < n ? m - bt.sum(k) : 0) << '\n';
    }

    return 0;
}
0