結果

問題 No.59 鉄道の旅
ユーザー TwizzTwizz
提出日時 2017-05-26 22:39:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 160,308 KB
実行使用メモリ 7,592 KB
最終ジャッジ日時 2023-10-20 00:19:34
合計ジャッジ時間 2,127 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 100000000;

int n, k;
int bit[1000002];

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

void add(int i, int x) {
	while (i <= 1000002) {
		bit[i] += x;
		i += i&-i;
	}
}

int main() {
	cin >> n >> k;
	REP(i, 1000002)bit[i] = 0;
	REP(i, n) {
		int w; cin >> w;
		if (w > 0) {
			if (sum(1000002) - sum(w - 1) < k) {add(w, 1);}
		}else {
			if (sum(-w) - sum(-w - 1) >= 1) {add(-w, -1);}
			}
		}
	print(sum(1000002));
	return 0;
}
0