結果

問題 No.59 鉄道の旅
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-13 22:35:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 778 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 144,356 KB
実行使用メモリ 11,384 KB
最終ジャッジ日時 2023-08-26 05:38:23
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,472 KB
testcase_01 AC 2 ms
7,544 KB
testcase_02 AC 2 ms
7,496 KB
testcase_03 AC 2 ms
7,472 KB
testcase_04 AC 37 ms
11,172 KB
testcase_05 AC 3 ms
9,620 KB
testcase_06 AC 2 ms
9,560 KB
testcase_07 AC 2 ms
5,524 KB
testcase_08 AC 10 ms
11,384 KB
testcase_09 AC 11 ms
11,048 KB
testcase_10 AC 11 ms
10,684 KB
testcase_11 AC 3 ms
7,528 KB
testcase_12 AC 14 ms
7,520 KB
testcase_13 AC 31 ms
5,684 KB
testcase_14 AC 32 ms
5,844 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define MAX 20

class BIT{
public:
	int dp[1 << MAX];
	void init(){
		for (int i = 0; i < (1 << MAX); i++)
		{
			dp[i] = 0;
		}
	}

	long long bitcall(int a){
		int ret = 0;
		while (a > 0){
			ret += dp[a];
			a &= a - 1;
		}
		return ret;
	}

	void bitadd(int a, int b){
		while (a < (1 << MAX)){
			dp[a] += b;
			a += a - (a & (a - 1));
		}
	}
};

int num[1 << MAX];
BIT bit;

int main(){
	int N, K;
	cin >> N >> K;
	int count = 0;
	for (int i = 0; i < N; i++)
	{
		int W;
		cin >> W;
		if (W < 0){
			W = -W;
			if (num[W] == 0) continue;
			num[W]--;
			bit.bitadd(W, -1);
			count--;
		}
		else{
			if (count - bit.bitcall(W - 1) >= K) continue;
			num[W]++;
			bit.bitadd(W, 1);
			count++;
		}
	}
	cout << count << endl;
}
0