Submission #761786

#TimeUsernameProblemLanguageResultExecution timeMemory
761786Sohsoh84Jousting tournament (IOI12_tournament)C++17
100 / 100
151 ms11764 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << ": " << x << endl; #define sep ' ' const int MAXN = 1e6 + 10; int n, ans[MAXN]; namespace fenwick { int fen[MAXN]; inline void update(int ind, int val) { for (++ind; ind < MAXN; ind += ind & -ind) fen[ind] += val; } inline void update(int l, int r, int val) { update(l, val); update(r + 1, -val); } inline int query(int ind) { int ans = 0; for (++ind; ind > 0; ind -= ind & -ind) ans += fen[ind]; return ans; } } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { n = N; vector<int> bst; for (int i = 0; i < n - 1; i++) if (K[i] > R) bst.push_back(i); ordered_set pst; for (int i = 0; i <= n; i++) pst.insert(i); set<int> opt; for (int i = 0; i < n; i++) opt.insert(i); for (int i = 0; i < C; i++) { int l = *pst.find_by_order(S[i]), r = *pst.find_by_order(E[i] + 1) - 1; if (l == r) continue; while (*pst.upper_bound(l) <= r) pst.erase(pst.upper_bound(l)); auto it = lower_bound(all(bst), l); if (it != bst.end() && *it <= r - 1) { while (opt.lower_bound(l) != opt.end() && *opt.lower_bound(l) <= r) { int ind = *opt.lower_bound(l); ans[ind] = fenwick::query(ind); opt.erase(ind); } } else fenwick::update(l, r, 1); } for (int ind : opt) ans[ind] = fenwick::query(ind); int fans = 0; for (int i = 0; i < n; i++) { if (ans[i] > ans[fans]) fans = i; } return fans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...