結果

問題 No.59 鉄道の旅
ユーザー 👑 kmjpkmjp
提出日時 2014-11-06 23:28:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,159 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 145,456 KB
実行使用メモリ 11,352 KB
最終ジャッジ日時 2023-08-26 05:20:37
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,712 KB
testcase_01 AC 2 ms
7,540 KB
testcase_02 AC 2 ms
7,468 KB
testcase_03 AC 3 ms
7,460 KB
testcase_04 AC 27 ms
11,352 KB
testcase_05 AC 2 ms
7,760 KB
testcase_06 AC 2 ms
7,556 KB
testcase_07 AC 2 ms
7,700 KB
testcase_08 AC 10 ms
11,216 KB
testcase_09 AC 11 ms
11,060 KB
testcase_10 AC 8 ms
10,788 KB
testcase_11 AC 3 ms
7,544 KB
testcase_12 AC 9 ms
7,472 KB
testcase_13 AC 15 ms
5,800 KB
testcase_14 AC 16 ms
5,836 KB
testcase_15 AC 2 ms
5,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void update(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;}
};
BIT<int,20> bt;

int N,K;
int W[1000001];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>x;
		if(x>0) {
			if(bt.total(1<<20)-bt.total(x-1)<K) bt.update(x,1),W[x]++;
		}
		else {
			if(W[-x]) W[-x]--, bt.update(-x,-1);
		}
	}
	cout << bt.total(1<<20) << endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0