結果

問題 No.59 鉄道の旅
ユーザー chaemonchaemon
提出日時 2014-11-09 22:57:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,073 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 75,632 KB
実行使用メモリ 10,924 KB
最終ジャッジ日時 2023-08-26 05:30:58
合計ジャッジ時間 1,629 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,796 KB
testcase_01 AC 5 ms
10,772 KB
testcase_02 AC 4 ms
10,544 KB
testcase_03 AC 5 ms
10,596 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
10,792 KB
testcase_07 WA -
testcase_08 AC 8 ms
10,608 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
10,560 KB
testcase_12 AC 19 ms
10,720 KB
testcase_13 AC 39 ms
10,596 KB
testcase_14 WA -
testcase_15 AC 4 ms
10,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

//range i..j (inclusive)
//larger range which contains k
inline int up(const int &k){return k|(k+1);}
//previous range adjacent to k
inline int left(const int &k){return (k&(k+1))-1;}

//{{{ Fenwick Tree
template <class T>
struct fenwick_tree {
	vector<T> x;
	fenwick_tree(int n) : x(n, 0) { }
	T sum(int p, int q) {
		if (p == 0) {
			T S = 0;
			for (int j=q ; j >= 0; j = left(j)) S += x[j];
			return S;
		} else return sum(0, q) - sum(0, p-1);
	}
	void add(int p, T a) {
		for (int k=p ; k < x.size(); k=up(k)) x[k] += a;
	}
};
//}}}

int main(){
	fenwick_tree<Int> ft(1000001);
	int N,K;
	cin>>N>>K;
	REP(i,N){
		int W;
		cin>>W;
		if(W<0){
			W = -W;
			if(ft.sum(W,W+1)>0)ft.add(W,-1);
		}else{
			if(ft.sum(W,(int)ft.x.size())<K)ft.add(W,1);
		}
	}
	cout<<ft.sum(0,ft.x.size())<<endl;
	return 0;
}
0