結果

問題 No.433 ICPC国内予選の選抜ルールがこんな感じだったらうれしい
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-10-14 23:21:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 348 ms / 4,000 ms
コード長 2,739 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 95,088 KB
実行使用メモリ 11,660 KB
最終ジャッジ日時 2023-08-14 12:57:46
合計ジャッジ時間 10,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 306 ms
11,204 KB
testcase_01 AC 234 ms
11,008 KB
testcase_02 AC 127 ms
11,420 KB
testcase_03 AC 245 ms
11,068 KB
testcase_04 AC 248 ms
11,080 KB
testcase_05 AC 181 ms
11,240 KB
testcase_06 AC 348 ms
11,016 KB
testcase_07 AC 145 ms
11,228 KB
testcase_08 AC 128 ms
11,176 KB
testcase_09 AC 188 ms
11,220 KB
testcase_10 AC 209 ms
11,012 KB
testcase_11 AC 263 ms
11,600 KB
testcase_12 AC 239 ms
11,012 KB
testcase_13 AC 120 ms
11,160 KB
testcase_14 AC 171 ms
11,076 KB
testcase_15 AC 93 ms
11,088 KB
testcase_16 AC 282 ms
11,236 KB
testcase_17 AC 292 ms
11,060 KB
testcase_18 AC 299 ms
11,660 KB
testcase_19 AC 118 ms
11,212 KB
testcase_20 AC 156 ms
11,020 KB
testcase_21 AC 142 ms
11,240 KB
testcase_22 AC 250 ms
11,400 KB
testcase_23 AC 186 ms
11,416 KB
testcase_24 AC 119 ms
11,080 KB
testcase_25 AC 224 ms
11,156 KB
testcase_26 AC 142 ms
11,380 KB
testcase_27 AC 208 ms
11,232 KB
testcase_28 AC 113 ms
11,240 KB
testcase_29 AC 231 ms
11,088 KB
testcase_30 AC 3 ms
6,912 KB
testcase_31 AC 3 ms
7,016 KB
testcase_32 AC 291 ms
11,216 KB
testcase_33 AC 312 ms
10,960 KB
testcase_34 AC 145 ms
11,084 KB
testcase_35 AC 3 ms
7,012 KB
testcase_36 AC 4 ms
6,908 KB
testcase_37 AC 3 ms
6,912 KB
testcase_38 AC 3 ms
7,108 KB
testcase_39 AC 5 ms
7,032 KB
testcase_40 AC 5 ms
6,968 KB
testcase_41 AC 15 ms
7,440 KB
testcase_42 AC 15 ms
7,504 KB
testcase_43 AC 15 ms
7,380 KB
testcase_44 AC 15 ms
7,388 KB
testcase_45 AC 6 ms
6,996 KB
testcase_46 AC 45 ms
7,336 KB
testcase_47 AC 47 ms
7,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define A 1000000000000000LL
#define C 10000000LL

ll d1[100005];
ll d2[100005];

#define N_MAX (1<<17)
#define INF 100000000000000000LL

int nn_sst;
long long dat_sst1[(2 * N_MAX) - 1];
long long dat_sst2[(2 * N_MAX) - 1];

void init_sst(int n1) {
	nn_sst = 1;

	while (nn_sst < n1)nn_sst *= 2;

	for (int i = 0; i < 2 * nn_sst - 1; i++) {
		dat_sst1[i] = 0;
		dat_sst2[i] = 0;
	}
}

void add_sst(int a, int b, long long x, int k, int l, int r) {
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		dat_sst2[k] += x;
		return;
	}
	add_sst(a, b, x, k * 2 + 1, l, (l + r) / 2);
	add_sst(a, b, x, k * 2 + 2, (l + r) / 2, r);

	dat_sst1[k] = max(dat_sst1[k * 2 + 1] + dat_sst2[k * 2 + 1], dat_sst1[k * 2 + 2] + dat_sst2[k * 2 + 2]);
}

long long query_sst(int a, int b, int k, int l, int r) {
	if (b <= l || r <= a)return -INF;
	if (a <= l && r <= b) {
		return (dat_sst1[k] + dat_sst2[k]);
	}
	else {
		long long vl = query_sst(a, b, k * 2 + 1, l, (l + r) / 2);
		long long vr = query_sst(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr) + dat_sst2[k];
	}
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<pair<pair<ll, ll> , ll> > v;
	rep(i, 0, n) {
		ll a, b, c;
		cin >> a >> b >> c;
		a *= A;
		b = 1000000 - b;
		v.pb(mp(mp(c, a + 100000 * C + b), i));
	}
	sort(all(v));
	rep(i, 0, 100005) {
		d1[i] = C;
		d2[i] = -C;
	}
	rep(i, 0, v.sz) {
		d1[v[i].fi.fi] = min(d1[v[i].fi.fi], i);
		d2[v[i].fi.fi] = max(d2[v[i].fi.fi], i);
	}
	init_sst(v.sz);
	rep(i, 0, v.sz) {
		add_sst(i, i + 1, v[i].fi.se, 0, 0, nn_sst);
	}
	ll index = 0;
	rep(i, 0, v.sz) {
		ll a = query_sst(0, n, 0, 0, nn_sst);
		long long low = 0;
		long long high = n - 1;
		while (low < high) {
			long long mid = (high + low) >> 1;

			if (query_sst(0, mid + 1, 0, 0, nn_sst) == a) {
				high = mid;
			}
			else {
				low = mid + 1;
			}
		}
		ll p = low;
		cout << v[p].se << endl;
		ll g = v[p].fi.fi;
		add_sst(d1[g], d2[g] + 1, -1 * C, 0, 0, nn_sst);
		add_sst(p, p + 1, -INF, 0, 0, nn_sst);
		index++;
		if (index == k)break;
	}
	return 0;
}
0