Submission #251523

#TimeUsernameProblemLanguageResultExecution timeMemory
251523kostia244Jousting tournament (IOI12_tournament)C++17
100 / 100
225 ms23544 KiB
#include<bits/extc++.h> using namespace std; using namespace __gnu_pbds; struct range { int i, l, r; bool operator<(const range &rhs) const { return l < rhs.l; } }; using oset = tree<range, null_type, less<range>, rb_tree_tag, tree_order_statistics_node_update>; const int maxn = 1<<18; int n, c, x, l[maxn], r[maxn]; vector<int> g[maxn]; int tr[maxn]; int qry(int l, int r) { int ans = 0; for(l += n, r += n; l < r; l>>=1, r>>=1) { if(l&1) ans = max(ans, tr[l++]); if(r&1) ans = max(ans, tr[--r]); } return ans; } array<int, 2> dfs(int v) { if(v < n) return {0, -v}; int good = qry(l[v], r[v]) < x; array<int, 2> cur = {-1, 1<<30}; for(auto &i : g[v]) cur = max(cur, dfs(i)); cur[0] += good; return cur; } int GetBestPosition(int N, int C, int X, int *a, int *s, int *e) { n = N, c = C, x = X; for(int i = 0; i < n-1; i++) { int j = n+i; for(;j;j>>=1) tr[j] = max(tr[j], a[i]); } oset b; for(int i = 0; i < n; i++) l[i] = r[i] = i, b.insert(range{i, l[i], r[i]}); for(int i = 0; i < c; i++) { int len = e[i] - s[i] + 1; int nl, nr; for(int j = 1; j <= len; j++) { auto t = *b.find_by_order(s[i]); if(j == 1) nl = t.l; if(j == len) nr = t.r; g[n+i].push_back(t.i); b.erase(t); } l[n+i] = nl; r[n+i] = nr; b.insert(range{n+i, nl, nr}); //for(auto i : b) cout << i.l << " " << i.r << " | "; cout << '\n'; } return -dfs(n+c-1)[1]; }

Compilation message (stderr)

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:43:11: warning: 'nr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int nl, nr;
           ^~
tournament.cpp:43:7: warning: 'nl' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int nl, nr;
       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...