# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
761773 | Sohsoh84 | Jousting tournament (IOI12_tournament) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<
typename Key, // Key type
typename Mapped, // Mapped-policy
typename Cmp_Fn = std::less<Key>, // Key comparison functor
typename Tag = rb_tree_tag, // Specifies which underlying data structure to use
template<
typename Const_Node_Iterator,
typename Node_Iterator,
typename Cmp_Fn_,
typename Allocator_>
class Node_Update = null_node_update, // A policy for updating node invariants
typename Allocator = std::allocator<char> > // An allocator type
class tree;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int MAXN = 1e6 + 10;
int n;
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);
int ans = 0;
for (int i = 0; i < C; i++) {
int tl = S[i] + 1, tr = E[i];
int l = *pst.find_by_order(tl), r = *pst.find_by_order(tr + 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) {
if (opt.lower_bound(l) != opt.end() && *opt.lower_bound(l) <= r)
ans = *opt.lower_bound(l);
while (opt.lower_bound(l) != opt.end() && *opt.lower_bound(l) <= r)
opt.erase(opt.lower_bound(l));
}
}
if (!opt.empty())
ans = *opt.begin();
return 0;
}