답안 #481838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481838 2021-10-22T03:11:58 Z Foxyy 마상시합 토너먼트 (IOI12_tournament) C++17
17 / 100
1000 ms 107716 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll LINF = 1e18;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#define randint(l, r) uniform_int_distribution(l, r)(rng);

const int MAXN = 5e3;

struct Treap {
	static Treap pmem[MAXN+5], *cur;
	Treap *l, *r;
	int sz, mx, val;
	int pri = randint(0, INT_MAX);
	Treap(){}
	Treap(int x):
		l(nullptr), r(nullptr), sz(1), mx(x), val(x){}
} Treap::pmem[MAXN+5], *Treap::cur = Treap::pmem;

inline int get_sz(Treap *t) {
	return t ? t->sz : 0;
}

inline int get_mx(Treap *t) {
	return t ? t->mx : -1;
}

void pull(Treap *t) {
	t->sz = get_sz(t->l) + get_sz(t->r) + 1;
	t->mx = max({get_mx(t->l), get_mx(t->r), t->val});
}

void split(Treap *t, int k, Treap *&a, Treap *&b) {
	if (!t) return void(a = b = t);
	if (get_sz(t->l)+1 < k) {
		a = t;
		split(t->r, k-(get_sz(t->l)+1), a->r, b);
		pull(a);
	} else {
		b = t;
		split(t->l, k, a, b->l);
		pull(b);
	}
}

Treap* merge(Treap *a, Treap *b) {
	if (!a||!b) return a ? a : b;
	if (a->pri > b->pri) {
		a->r = merge(a->r, b);
		pull(a);
		return a;
	} else {
		b->l = merge(a, b->l);
		pull(b);
		return b;
	}
}

void print(Treap *t) {
	if (!t) return;
	print(t->l);
	cout << t->val << " ";
	print(t->r);
}

int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
	int ans = -1, mx = -1;
	for(int pos = 0; pos < N; pos++) {
		Treap::cur = Treap::pmem;
		Treap *t = new (Treap::cur++) Treap(R);
		for(int i = pos-1; i >= 0; i--)
			t = merge(new (Treap::cur++) Treap(K[i]), t);
		for(int i = pos+1; i < N; i++)
			t = merge(t, new (Treap::cur++) Treap(K[i-1]));
		Treap *a, *b, *c;
		int cnt = 0;
		for(int i = 0; i < C; i++) {
			split(t, S[i]+1, a, b);
			split(b, E[i]-S[i]+2, b, c);
			if (b->mx == R) cnt++;
			Treap *nt = new Treap(b->mx);
			t = merge(merge(a, nt), c);
		}
		if (cnt > mx) ans = pos, mx = cnt;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 5 ms 844 KB Output is correct
3 Correct 99 ms 11048 KB Output is correct
4 Correct 101 ms 11660 KB Output is correct
5 Correct 24 ms 1100 KB Output is correct
6 Correct 102 ms 11484 KB Output is correct
7 Correct 102 ms 11692 KB Output is correct
8 Correct 104 ms 11588 KB Output is correct
9 Correct 21 ms 684 KB Output is correct
10 Correct 35 ms 2180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 28360 KB Output is correct
2 Execution timed out 1101 ms 107716 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 1620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -