Submission #415955

#TimeUsernameProblemLanguageResultExecution timeMemory
415955snasibov05Jousting tournament (IOI12_tournament)C++14
49 / 100
1095 ms5448 KiB
#include <vector> using namespace std; #define pb push_back vector<int> val; vector<vector<int>> ed; struct SegmentTree{ vector<int> t; SegmentTree(int n){ t.resize(4*n+5); } void update(int v, int tl, int tr, int idx, int k){ if (tl == tr){ t[v] = k; return; } int tm = (tl + tr) / 2; if (idx <= tm) update(v*2, tl, tm, idx, k); else update(v*2+1, tm+1, tr, idx, k); t[v] = t[v*2] + t[v*2+1]; } int idx(int v, int tl, int tr, int k){ if (tl == tr){ return tl; } int tm = (tl + tr) / 2; if (t[v*2] > k) return idx(v*2, tl, tm, k); else return idx(v*2+1, tm+1, tr, k - t[v*2]); } }; int buildTree(int n, int c, int*& s, int*& e){ int idx = n; vector<int> cur(n); SegmentTree tree(n); for (int i = 0; i < n; ++i) { tree.update(1, 0, n-1, i, 1); cur[i] = i; } for (int i = 0; i < c; ++i) { vector<int> v; for (int j = s[i]; j <= e[i]; ++j) { int k = tree.idx(1, 0, n-1, j); v.pb(k); ed[idx].pb(cur[k]); } for (int j = s[i]; j <= e[i]; ++j) { cur[v[j - s[i]]] = idx; if (j != s[i]) tree.update(1, 0, n-1, v[j - s[i]], 0); } idx++; } return idx-1; } void dfs(int v){ for (auto x : ed[v]){ dfs(x); val[v] = max(val[v], val[x]); } } int GetBestPosition(int n, int c, int r, int *k, int *s, int *e) { val.resize(2*n); ed.resize(2*n); int m = buildTree(n, c, s, e); int mx = 0, ans = 0; for (int i = 0; i < n; ++i) { val.assign(2*n+1, 0); for (int j = 0; j < i; ++j) { val[j] = k[j]; } val[i] = r; for (int j = i; j < n-1; ++j) { val[j+1] = k[j]; } dfs(m); int cnt = 0; for (int j = 0; j <= m; ++j) { if (val[j] == r) cnt++; } if (cnt > mx) { ans = i; mx = cnt; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...