# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
428975 | wiwiho | Jousting tournament (IOI12_tournament) | C++14 | 189 ms | 11900 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 <bits/extc++.h>
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define uni(a) a.resize(unique(iter(a)));
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
using tree = __gnu_pbds::tree<int, __gnu_pbds::null_type, less<>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
const ll MOD = 1000000000;
int GetBestPosition(int n, int m, int R, int *K, int *S, int *E) {
vector<int> pos;
for(int i = 0; i < n - 1; i++){
if(K[i] > R) pos.eb(i);
}
tree tr;
for(int i = 0; i <= n; i++) tr.insert(i);
vector<pii> ev;
vector<bool> kill(m);
for(int i = 0; i < m; i++){
auto lit = tr.find_by_order(S[i]);
auto rit = tr.find_by_order(E[i]);
S[i] = *lit;
E[i] = *next(rit) - 1;
for(auto it = next(lit); *it <= E[i]; it = tr.erase(it));
ev.eb(mp(S[i], i + 1));
ev.eb(mp(E[i] + 1, -i - 1));
auto it = lower_bound(iter(pos), S[i]);
kill[i] = it != pos.end() && *it < E[i];
}
lsort(ev);
tree now;
set<int> ks;
int ep = 0;
int ans = 0, ansp = 0;
for(int i = 0; i < n; i++){
while(ep < ev.size() && ev[ep].F <= i){
if(ev[ep].S > 0){
int id = ev[ep].S - 1;
now.insert(id);
if(kill[id]) ks.insert(id);
}
else{
int id = -ev[ep].S - 1;
now.erase(id);
ks.erase(id);
}
ep++;
}
int tans;
if(ks.empty()) tans = now.size();
else tans = now.order_of_key(*ks.begin());
if(tans > ans){
ans = tans;
ansp = i;
}
}
return ansp;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |