結果

問題 No.618 labo-index
ユーザー merom686merom686
提出日時 2017-12-18 01:23:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 6,000 ms
コード長 1,735 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 83,412 KB
実行使用メモリ 6,680 KB
最終ジャッジ日時 2023-08-22 05:17:45
合計ジャッジ時間 4,104 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 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 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 46 ms
5,128 KB
testcase_20 AC 47 ms
5,120 KB
testcase_21 AC 47 ms
5,064 KB
testcase_22 AC 48 ms
5,060 KB
testcase_23 AC 47 ms
5,072 KB
testcase_24 AC 46 ms
5,200 KB
testcase_25 AC 47 ms
5,056 KB
testcase_26 AC 47 ms
5,128 KB
testcase_27 AC 48 ms
5,124 KB
testcase_28 AC 45 ms
5,072 KB
testcase_29 AC 46 ms
5,136 KB
testcase_30 AC 48 ms
5,124 KB
testcase_31 AC 47 ms
5,064 KB
testcase_32 AC 46 ms
5,204 KB
testcase_33 AC 46 ms
5,080 KB
testcase_34 AC 49 ms
6,652 KB
testcase_35 AC 49 ms
6,680 KB
testcase_36 AC 35 ms
5,348 KB
testcase_37 AC 38 ms
5,488 KB
testcase_38 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct BIT {
    BIT(int n) : s(n + 1), n(n) {}
    int sum(int k) {
        int r = 0;
        for (; k > 0; k -= k & -k) r += s[k];
        return r;
    }
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) s[k] += v;
    }
    vector<int> s;
    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);
    for (int i = 0; i < q; i++) {
        cin >> t[i] >> x[i];
        if (t[i] == 2) x[i]--;
    }

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

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

    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[p2[x[i]]], -1);
            m--;
        } else {
            d += x[i];
        }
        I j = lower_bound(0, n, [&](I j) {
            return m - bt.sum(j) <= a[j].first + d;
        });
        cout << m - bt.sum(j) << '\n';
    }

    return 0;
}
0