結果

問題 No.59 鉄道の旅
ユーザー heno239heno239
提出日時 2019-01-22 08:07:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,890 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 114,784 KB
実行使用メモリ 11,492 KB
最終ジャッジ日時 2023-10-13 17:37:31
合計ジャッジ時間 2,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,248 KB
testcase_01 AC 5 ms
11,244 KB
testcase_02 AC 5 ms
11,284 KB
testcase_03 AC 6 ms
11,376 KB
testcase_04 AC 63 ms
11,492 KB
testcase_05 AC 6 ms
11,204 KB
testcase_06 AC 6 ms
11,200 KB
testcase_07 AC 6 ms
11,312 KB
testcase_08 AC 13 ms
11,244 KB
testcase_09 AC 10 ms
11,372 KB
testcase_10 AC 11 ms
11,204 KB
testcase_11 AC 10 ms
11,240 KB
testcase_12 AC 45 ms
11,244 KB
testcase_13 AC 50 ms
11,372 KB
testcase_14 AC 62 ms
11,396 KB
testcase_15 AC 6 ms
11,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
struct segt {
private:
	int n; vector<int> node;
public:
	segt(int n_) {
		n = 1;
		while (n < n_)n *= 2;
		node.resize(2*n-1, 0);
	}
	void add(int k, int a) {
		k += n - 1;
		node[k] += a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = node[2 * k + 1] + node[2 * k + 2];
		}
	}
	int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return node[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return vl + vr;
		}
	}
	bool exi(int k) {
		return node[k + n - 1];
	}
};
int n, k;
const int mn = 1000001;
int main() {
	cin >> n >> k;
	segt st(mn);
	rep(i, n) {
		int w; cin >> w;
		if (w > 0) {
			int num = st.query(w, mn);
			if (num >= k)continue;
			else st.add(w, 1);
		}
		else {
			w = -w;
			if (st.exi(w))st.add(w, -1);
		}
	}
	cout << st.query(0, mn) << endl;
	//stop
	return 0;
}
0