結果

問題 No.59 鉄道の旅
ユーザー masamasa
提出日時 2016-07-29 13:14:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 941 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 78,988 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 07:06:27
合計ジャッジ時間 3,873 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

const int MAX_K = 100000;

class BIT
{
private:
	int n;
	vector<int> bit;
public:
	BIT();
	BIT(int a) {
		n = a;
		bit.assign(n + 1, 0);
	}
	~BIT() {
		bit.clear();
	};

	void add(int idx, int val) {
		while (idx <= n) {
			bit[idx] += val;
			idx += idx & -idx;
		}
	}

	int sum(int idx) {
		int ret = 0;
		while (idx > 0) {
			ret += bit[idx];
			idx -= idx & -idx;
		}
		return ret;
	}

	int get(int idx) {
		return sum(idx) - sum(idx - 1);
	}
};

int main() {
	int n, k, w;

	scanf("%d %d", &n, &k);

	map<int, int> store;

	BIT bit(MAX_K);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w);
		if (w >= 0) {
			if (bit.sum(MAX_K) - bit.sum(w - 1) < k) {
				bit.add(w, 1);
			}
		} else {
			w = -w;
			if (bit.get(w) > 0) {
				bit.add(w, -1);
			}
		}
	}

	printf("%d\n", bit.sum(MAX_K));
	return 0;
}
0