結果

問題 No.59 鉄道の旅
ユーザー btkbtk
提出日時 2015-06-16 23:19:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 541 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 51,836 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-08-26 05:39:47
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#define M 1000000
int bit[M + 1];

int sum(int i){
	i = M - i;
	int s = 0;
	while (i > 0){
		s += bit[i];
		i -= i&-i;
	}
	return s;
}
int get(int i){
	return (i == M) ? sum(i) : sum(i) - sum(i + 1);
}
void add(int i,int x){
	i = M - i;
	while (i <= M){
		bit[i]+=x;
		i += i&-i;
	}
}


using namespace std;
int main(){
	int N, K, W;
	cin >> N >> K;
	for (int i = 0; i < N; i++){
		cin >> W;
		if (W > 0){
			if (sum(W) < K)add(W,1);
		}
		else{
			if (get(-W) > 0)add(-W, -1);
		}
	}
	cout << sum(1) << endl;
	return 0;
}
0