結果

問題 No.59 鉄道の旅
ユーザー chocoruskchocorusk
提出日時 2019-01-13 10:37:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 876 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 92,296 KB
実行使用メモリ 11,296 KB
最終ジャッジ日時 2023-08-26 09:21:07
合計ジャッジ時間 2,139 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,560 KB
testcase_01 AC 2 ms
7,440 KB
testcase_02 AC 2 ms
7,460 KB
testcase_03 AC 2 ms
7,448 KB
testcase_04 AC 37 ms
11,296 KB
testcase_05 AC 2 ms
7,448 KB
testcase_06 AC 2 ms
7,460 KB
testcase_07 AC 2 ms
7,536 KB
testcase_08 AC 11 ms
11,128 KB
testcase_09 AC 11 ms
10,848 KB
testcase_10 AC 9 ms
10,676 KB
testcase_11 AC 3 ms
7,584 KB
testcase_12 AC 14 ms
7,420 KB
testcase_13 AC 32 ms
6,036 KB
testcase_14 AC 30 ms
5,904 KB
testcase_15 AC 2 ms
5,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int bit[1000001], n0;
int ct[1000001];
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<=n0){
		bit[i]+=x;
		i+=(i&(-i));
	}
}
int main()
{
	int n, k; cin>>n>>k; n0=1000000; int tot=0;
	for(int i=0; i<n; i++){
		int w; cin>>w;
		if(w>0){
			if(tot-sum(w-1)<k){
				tot++; ct[w]++;
				add(w, 1);
			}
		}else{
			w=-w;
			if(ct[w]>0){
				tot--;
				ct[w]--;
				add(w, -1);
			}
		}
	}
	cout<<tot<<endl;
	return 0;
}
0