結果

問題 No.59 鉄道の旅
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-03 23:53:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 777 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 69,312 KB
実行使用メモリ 7,408 KB
最終ジャッジ日時 2023-08-26 07:15:37
合計ジャッジ時間 1,568 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,256 KB
testcase_01 AC 4 ms
7,408 KB
testcase_02 AC 5 ms
7,272 KB
testcase_03 AC 4 ms
7,284 KB
testcase_04 AC 40 ms
7,352 KB
testcase_05 AC 5 ms
7,332 KB
testcase_06 AC 5 ms
7,332 KB
testcase_07 AC 4 ms
7,328 KB
testcase_08 AC 8 ms
7,368 KB
testcase_09 AC 8 ms
7,244 KB
testcase_10 AC 8 ms
7,296 KB
testcase_11 AC 6 ms
7,300 KB
testcase_12 AC 19 ms
7,404 KB
testcase_13 AC 39 ms
7,220 KB
testcase_14 AC 37 ms
7,268 KB
testcase_15 AC 5 ms
7,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
//[1,n]
const int MAX_W = 1000010;
int bit[MAX_W + 1];

int sum(int i){//iまでの和を求める
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, int x){//iの値にxを加える
	while(i <= MAX_W){
		bit[i] += x;
		i += i & -i;
	}
}

int main(void){
	int n, k; cin >> n >> k;
	vector<int> w(n);
	rep(i, MAX_W + 1) bit[i] = 0;
	rep(i, n){
		int w; cin >> w;
		if(w > 0){
			if(sum(MAX_W) - sum(w - 1) < k){
				add(w, 1);
			}
		}else{
			if(sum(-w) - sum(-w - 1) >= 1){
				add(-w, -1);
			}
		}
	}
	cout << sum(MAX_W) << endl;
	return 0;
}
0