結果

問題 No.618 labo-index
ユーザー merom686merom686
提出日時 2017-12-19 23:28:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 6,000 ms
コード長 1,759 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 83,300 KB
実行使用メモリ 6,196 KB
最終ジャッジ日時 2023-08-22 07:13:00
合計ジャッジ時間 3,847 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 38 ms
4,888 KB
testcase_20 AC 39 ms
4,776 KB
testcase_21 AC 38 ms
4,900 KB
testcase_22 AC 39 ms
4,848 KB
testcase_23 AC 39 ms
4,772 KB
testcase_24 AC 38 ms
4,772 KB
testcase_25 AC 39 ms
4,812 KB
testcase_26 AC 39 ms
4,840 KB
testcase_27 AC 39 ms
4,892 KB
testcase_28 AC 38 ms
4,908 KB
testcase_29 AC 38 ms
4,812 KB
testcase_30 AC 38 ms
4,756 KB
testcase_31 AC 39 ms
4,812 KB
testcase_32 AC 38 ms
4,788 KB
testcase_33 AC 38 ms
4,888 KB
testcase_34 AC 43 ms
6,064 KB
testcase_35 AC 42 ms
6,196 KB
testcase_36 AC 30 ms
5,032 KB
testcase_37 AC 33 ms
5,152 KB
testcase_38 AC 1 ms
4,388 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 {
        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;
};

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 << m - bt.sum(k) << '\n';
    }

    return 0;
}
0