結果

問題 No.59 鉄道の旅
ユーザー fiordfiord
提出日時 2015-07-31 01:28:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 635 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 144,044 KB
実行使用メモリ 11,300 KB
最終ジャッジ日時 2023-08-26 06:31:20
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,428 KB
testcase_01 AC 3 ms
7,444 KB
testcase_02 AC 2 ms
7,684 KB
testcase_03 AC 3 ms
7,456 KB
testcase_04 AC 46 ms
11,148 KB
testcase_05 AC 3 ms
9,496 KB
testcase_06 AC 2 ms
9,540 KB
testcase_07 AC 2 ms
5,440 KB
testcase_08 AC 11 ms
11,300 KB
testcase_09 AC 13 ms
10,928 KB
testcase_10 AC 12 ms
10,656 KB
testcase_11 AC 4 ms
7,456 KB
testcase_12 AC 15 ms
7,520 KB
testcase_13 AC 34 ms
5,744 KB
testcase_14 AC 34 ms
5,784 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
class bit{
	public:
	int dp[1<<20];
	void init(){
		memset(dp,0,sizeof(dp));
	}
	int call(int x){
		int ret=0;
		while(x>0){
			ret+=dp[x];
			x&=x-1;
		}
		return ret;
	}
	void add(int x,int y){
		while(x<1<<20){
			dp[x]+=y;
			x+=x-(x&(x-1));
		}
	}
};

int num[1<<20];
bit data;

int main(){
	int n,k;	cin>>n>>k;
	int cnt=0;
	for(int i=0;i<n;i++){
		int w;	cin>>w;
		if(w<0){
			w*=-1;
			if(num[w]<=0)	continue;
			num[w]--;
			data.add(w,-1);
			cnt--;
		}
		else{
			if(cnt-data.call(w-1)>=k)	continue;
			num[w]++;
			data.add(w,1);
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}
0