제출 #481837

#제출 시각아이디문제언어결과실행 시간메모리
481837Foxyy마상시합 토너먼트 (IOI12_tournament)C++17
0 / 100
317 ms28420 KiB
#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 = 0; i < pos; 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...