답안 #150146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150146 2019-09-01T07:48:15 Z 오리버스부릉부릉(#3679, rdd6584, orihehe, phpark) 십자가 놓기 (FXCUP4_cross) C++17
100 / 100
344 ms 71532 KB
#include "cross.h"
#include <algorithm>
#include <functional>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

struct node {
	int l, r, val, ori;
} tree[5000001];

pii vec[200001];
int y[200001];
int root[200001];
int szz = 1, num = 0;

// 1~n�����ϱ�.
int init(int l, int r) {
	int now = num++;

	if (l != r) {
		tree[now].l = init(l, (l + r) / 2);
		tree[now].r = init((l + r) / 2 + 1, r);
	}
	else tree[now].ori = l;

	return now;
}

// ++1 g�ϴ� ����.
int update(int i, int l, int r, int le, int ri) {
	if (l > ri || r < le) return i;

	int now = num++;
	if (le == ri) {
		tree[now].val = tree[i].val + 1;
		tree[now].ori = le;
		return now;
	}

	int p = update(tree[i].l, l, r, le, (le + ri) / 2);
	int q = update(tree[i].r, l, r, (le + ri) / 2 + 1, ri);

	tree[now] = { p, q, tree[p].val + tree[q].val };
	return now;
}

// worm�ڵ带 ��� �ۼ��ϳ�... ���� �����ʿ� �ִ� �ź��� ���� �ϴµ�..
// �ϴ� root������ ���� üũ�ϰ�.
// ���������� �������� �ش� ��忡�������� Ŀ�� ĥ �� �ִ����� ����ؼ� ����.

int worm(int i, int cnt) {
	if (tree[i].l == 0) return tree[i].ori;
	if (tree[tree[i].r].val >= cnt) return worm(tree[i].r, cnt);
	else return worm(tree[i].l, cnt - tree[tree[i].r].val);
}

ll SelectCross(int k, std::vector<int> in, std::vector<int> o) {
	int n = in.size();
	while (szz <= n) szz *= 2;

	for (int ii = 1; ii <= n; ii++) {
		vec[ii] = { in[ii - 1], o[ii - 1] };
		y[ii] = o[ii - 1];
	}
	sort(vec + 1, vec + 1 + n);
	sort(y + 1, y + n + 1);

	root[0] = init(1, n);

	ll mav = 0;
	for (int i = n; i >= 1; i--) {
		int t = lower_bound(y + 1, y + n + 1, vec[i].second) - y;
		root[i] = update(root[(i + 1 > n) ? 0 : i + 1], t, t, 1, n);

		if (n - k < i - 1) continue;
		int tt = worm(root[i], k);
		mav = max(mav, (ll)y[tt] * y[tt] - ((ll)y[tt] - vec[i].first) * (y[tt] - vec[i].first));
	}

	return mav;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 19 ms 3968 KB Output is correct
6 Correct 337 ms 71528 KB Output is correct
7 Correct 338 ms 71528 KB Output is correct
8 Correct 317 ms 71528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 19 ms 3968 KB Output is correct
6 Correct 337 ms 71528 KB Output is correct
7 Correct 338 ms 71528 KB Output is correct
8 Correct 317 ms 71528 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 432 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 20 ms 3968 KB Output is correct
13 Correct 159 ms 35184 KB Output is correct
14 Correct 312 ms 71528 KB Output is correct
15 Correct 318 ms 71528 KB Output is correct
16 Correct 330 ms 71532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 19 ms 3968 KB Output is correct
6 Correct 337 ms 71528 KB Output is correct
7 Correct 338 ms 71528 KB Output is correct
8 Correct 317 ms 71528 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 432 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 20 ms 3968 KB Output is correct
13 Correct 159 ms 35184 KB Output is correct
14 Correct 312 ms 71528 KB Output is correct
15 Correct 318 ms 71528 KB Output is correct
16 Correct 330 ms 71532 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 21 ms 4224 KB Output is correct
20 Correct 154 ms 35180 KB Output is correct
21 Correct 242 ms 55912 KB Output is correct
22 Correct 332 ms 71532 KB Output is correct
23 Correct 339 ms 71396 KB Output is correct
24 Correct 344 ms 71524 KB Output is correct
25 Correct 322 ms 71524 KB Output is correct
26 Correct 321 ms 71528 KB Output is correct