結果

問題 No.59 鉄道の旅
ユーザー hiyokko2hiyokko2
提出日時 2016-08-11 11:17:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 614 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 144,036 KB
実行使用メモリ 11,304 KB
最終ジャッジ日時 2023-08-26 07:08:46
合計ジャッジ時間 2,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,356 KB
testcase_01 AC 2 ms
5,692 KB
testcase_02 AC 2 ms
5,352 KB
testcase_03 AC 2 ms
5,444 KB
testcase_04 AC 42 ms
11,304 KB
testcase_05 AC 2 ms
5,532 KB
testcase_06 AC 2 ms
5,420 KB
testcase_07 AC 3 ms
5,728 KB
testcase_08 AC 11 ms
11,228 KB
testcase_09 AC 11 ms
10,832 KB
testcase_10 AC 11 ms
10,704 KB
testcase_11 AC 3 ms
5,440 KB
testcase_12 AC 14 ms
5,384 KB
testcase_13 AC 31 ms
5,756 KB
testcase_14 AC 31 ms
5,904 KB
testcase_15 AC 2 ms
5,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int bit[1000001];
int n = 1000000;

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 <= n) {
		bit[i] += x;
		i += i & -i;
	}
}

int N, K, W;
int kosu[1000001];

signed main()
{
	cin >> N >> K;
	rep(i,N)
	{
		cin >> W;
		if (W > 0)
		{
			if (sum(1000000) - sum(W-1) < K)
			{
				add(W, 1);
				kosu[W]++;
			}
		} else {
			if (kosu[-W] > 0)
			{
				kosu[-W]--;
				add(-W, -1);
			}
		}
	}
	cout << sum(1000000) << endl;
}
0