Submission #105774

#TimeUsernameProblemLanguageResultExecution timeMemory
105774RezwanArefin01Jousting tournament (IOI12_tournament)C++17
100 / 100
214 ms11028 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef pair<int, int> ii; typedef tree< ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int M = 2e5 + 10; struct node { int sum, flag, l, d; node(int s=0, int f=0, int l=0, int d=0) : sum(s), flag(f), l(l), d(d) {} } t[M]; int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { ordered_set st; int idx = N; for(int i = 0; i < N - 1; i++) { t[i] = node(K[i] > R, K[i] > R, i, 0); st.insert({i, i}); } t[N - 1] = node(0, 0, N - 1, 0); st.insert({N - 1, N - 1}); for(int i = 0; i < C; ++i, ++idx) { auto s = st.find_by_order(S[i]); auto e = st.find_by_order(E[i]); t[idx].flag = t[e -> second].flag; ++e; while(s != e) { int id = s -> second; t[idx].sum += t[id].sum; if(t[id].d + 1 > t[idx].d) { t[idx].d = t[id].d + 1; t[idx].l = t[id].l; } auto it = s; s++; st.erase(it); } st.insert({t[idx].l, idx}); } int maxwin = 0, ans = 0; for(int i = 0; i < idx; i++) if(t[i].d >= maxwin){ if(t[i].sum == 0 || (t[i].sum == 1 && t[i].flag)) { if(t[i].d > maxwin) { maxwin = t[i].d; ans = t[i].l; } else { ans = min(ans, t[i].l); } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...