結果

問題 No.59 鉄道の旅
ユーザー sugim48sugim48
提出日時 2014-11-06 23:27:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,198 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 76,572 KB
実行使用メモリ 11,012 KB
最終ジャッジ日時 2023-08-26 05:19:30
合計ジャッジ時間 1,655 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,768 KB
testcase_01 AC 5 ms
10,700 KB
testcase_02 AC 4 ms
10,828 KB
testcase_03 AC 5 ms
10,776 KB
testcase_04 AC 40 ms
10,748 KB
testcase_05 AC 4 ms
10,776 KB
testcase_06 AC 5 ms
10,820 KB
testcase_07 AC 4 ms
10,656 KB
testcase_08 AC 8 ms
10,764 KB
testcase_09 AC 9 ms
11,012 KB
testcase_10 AC 8 ms
10,836 KB
testcase_11 AC 6 ms
10,820 KB
testcase_12 AC 18 ms
10,892 KB
testcase_13 AC 38 ms
10,980 KB
testcase_14 AC 36 ms
10,660 KB
testcase_15 AC 4 ms
11,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct bit {
	vector<ll> v;
	bit(int n) : v(n + 1) {}
	ll sum(int i) {
		ll res = 0;
		for (; i > 0; i -= i & -i) res += v[i];
		return res;
	}
	void add(int i, ll x) {
		for (i++; i < v.size(); i += i & -i) v[i] += x;
	}
};

int main() {
	int N, K; cin >> N >> K;
	bit b(1000001);
	while (N--) {
		int W; cin >> W;
		if (W > 0) {
			if (b.sum(1000001) - b.sum(W) < K)
				b.add(W, 1);
		}
		else {
			if (b.sum(-W + 1) - b.sum(-W) >= 1)
				b.add(-W, -1);
		}
	}
	cout << b.sum(1000001) << endl;
}
0