結果

問題 No.59 鉄道の旅
ユーザー xuzijian629xuzijian629
提出日時 2018-11-03 00:56:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,056 bytes
コンパイル時間 4,785 ms
コンパイル使用メモリ 200,140 KB
実行使用メモリ 11,128 KB
最終ジャッジ日時 2023-08-13 01:45:03
合計ジャッジ時間 6,271 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,992 KB
testcase_01 AC 4 ms
10,680 KB
testcase_02 AC 4 ms
10,852 KB
testcase_03 AC 4 ms
10,912 KB
testcase_04 AC 41 ms
10,984 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
10,704 KB
testcase_12 AC 19 ms
10,912 KB
testcase_13 WA -
testcase_14 AC 36 ms
10,832 KB
testcase_15 AC 5 ms
10,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class BIT {
    int n;
    vi data;

    i64 sum(int i) {
        i64 s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

public:
    BIT(int n) : n(n) {
        data = vi(n + 1);
    }

    void add(int i, i64 x) {
        i++;
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }

    // [l, r)
    i64 sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

int main() {
    int ans = 0;
    BIT cnt(1010101);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int w;
        cin >> w;
        if (w < 0) {
            w = -w;
            if (cnt.sum(w, w + 1)) {
                cnt.add(w, -1);
                ans--;
            } 
        } else {
            if (cnt.sum(w, 101010) < k) {
                cnt.add(w, 1);
                ans++;
            }
        }
    }
    cout << ans << endl;
}
0