제출 #541567

#제출 시각아이디문제언어결과실행 시간메모리
541567MohamedFaresNebili마상시합 토너먼트 (IOI12_tournament)C++14
17 / 100
1083 ms1800 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") using namespace std; using ll = long long; using ii = pair<ll, ll>; #define ff first #define ss second #define pb push_back /// #define int ll const int MOD = 1e9 + 7; int st[400001], par[100001], mx[100001]; void update(int v, int l, int r, int pos, int val) { if(l == r) { st[v] = val; return; } int md = (l + r) / 2; if(pos <= md) update(v * 2, l, md, pos, val); else update(v * 2 + 1, md + 1, r, pos, val); st[v] = max(st[v * 2], st[v * 2 + 1]); } int query0(int v, int l, int r, int lo, int hi) { if(l > hi || r < lo) return 0; if(l >= lo && r <= hi) return st[v]; return max(query0(v * 2, l, (l + r) / 2, lo, hi), query0(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi)); } int findSet(int v) { if(par[v] == v) return v; return par[v] = findSet(par[v]); } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { int res = 0, curr = 0; vector<ii> query; vector<ii> s; for(int l = 0; l < N; l++) s.push_back({l, l}); for(int l = 0; l < C; l++) { int lf = S[l], rf = E[l]; /// query.pb({s[lf], s[rf]}); int lo = s[lf].ff, hi = s[rf].ss; query.pb({lo, hi}); s.erase(s.begin() + lf, s.begin() + rf + 1); s.pb({lo, hi}); sort(s.begin(), s.end()); } for(int l = 0; l < N; l++) { for(int i = 0; i < l; i++) { par[i] = i, mx[i] = K[i]; update(1, 0, N - 1, i, mx[i]); } par[l] = l; mx[l] = R; update(1, 0, N - 1, l, mx[l]); for(int i = l; i < N - 1; i++) { par[i + 1] = i + 1, mx[i + 1] = K[i]; update(1, 0, N - 1, i + 1, K[i]); } int calc = 0; for(auto u : query) { int lf = u.ff, rf = u.ss; /// lf = findSet(lf), rf = findSet(rf); /// if(lf > rf) swap(lf, rf); /// par[rf] = lf; mx[lf] = max({mx[lf], mx[rf]}); int val = query0(1, 0, N - 1, lf, rf); if(val == R) calc++; } if(calc > curr) { curr = calc, res = l; } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...