# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
290068 | abyyskit | Jousting tournament (IOI12_tournament) | C++14 | 1092 ms | 14072 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>
using namespace std;
#define FOR(i, x, y) for(int i = x; i < y; ++i)
#define pb push_back
int G;
vector<int> base;
int TRACK;
struct node{
vector<int> e;
int c = 1;
int par = -1;
int ind = -1;
int l = -1;
int r = -1;
int score = 0;
};
vector<node> g;
int Find(int cur, int ind){
// cout << "cur, ind " << cur << ", " << ind << "\n";
FOR(i, 0, g[cur].e.size()){
int nex = g[cur].e[i];
int wex = g[nex].c;
if (wex > ind){
return Find(nex, ind);
}
else if (wex <= ind){
ind -= wex;
}
}
return cur;
}
void Add(int cur, int amount){
// cout << "here with "<< cur << " size " << amount << "\n";
FOR(i, 0, amount){
g[cur].e.pb(G);
g[G].par = cur;
G++;
}
g[cur].c += amount - 1;
int par = g[cur].par;
while(par != -1){
g[par].c += amount - 1;
cur = par;
par = g[cur].par;
}
}
void initbase(int cur){
if (g[cur].e.size() == 0){
base[TRACK] = cur;
g[cur].ind = TRACK;
g[cur].l = TRACK;
g[cur].r = TRACK + 1;
TRACK++;
return;
}
int L = INT_MAX;
int R = -1;
FOR(i, 0, g[cur].e.size()){
int nex = g[cur].e[i];
initbase(nex);
L = min(L, g[nex].l);
R = max(R, g[nex].r);
}
g[cur].l = L;
g[cur].r = R;
}
vector<int> seg;
void update(int ind, int x){
ind += seg.size()/2;
seg[ind] = x;
ind /= 2;
while (ind > 0){
seg[ind] = max(seg[2*ind], seg[2*ind + 1]);
ind /= 2;
}
}
int R;
int query(int l, int r){
//inclusive-exclusive
l += seg.size()/2;
r += seg.size()/2;
int ans = 0;
while (r > l){
if (l % 2 == 1){
ans = max(ans, seg[l]);
l++;
}
if (r % 2 == 1){
ans = max(ans, seg[r - 1]);
}
l /= 2;
r /= 2;
}
return ans;
}
void process(int cur){
int high = query(g[cur].l, g[cur].r - 1);
if (high < R){
g[cur].score = g[g[cur].par].score + 1;
}
else{
g[cur].score = 0;
}
}
int GetBestPosition(int N, int C, int r, int *K, int *S, int *E) {
R = r;
g.resize(2*N);
base.resize(N);
TRACK = 0;
G = 1;
seg.resize(2*(N-1));
FOR(i, 0, N - 1){
update(i,K[i]);
}
for(int i = C - 1; i >= 0; --i){
int ind = Find(0,S[i]);
Add(ind, E[i] - S[i] + 1);
}
initbase(0);
FOR(i, 0, G){
process(i);
}
/* cout << "Done\n";
cout << G << "\n";
FOR(i, 0, G){
cout << i << ":\n";
cout << "e: ";
FOR(j, 0, g[i].e.size()){
cout << g[i].e[j] << " ";
}
cout << "\n";
cout << "c = " << g[i].c << "\n";
cout << "par = " << g[i].par << "\n";
cout << "(l, r) = (" << g[i].l << ", " << g[i].r << ")\n";
cout << "score = " << g[i].score << "\n";
cout << "------------------------------\n";
}
FOR(i, 0, base.size()){
cout << base[i] << " ";
}
cout << "\n";
FOR(i, 0, seg.size()){
cout << i << ": " << seg[i] << "\n";
}
*/
int smax = 0;
int ind = 0;
FOR(i, 0, base.size()){
if (g[base[i]].score > smax){
smax = g[base[i]].score;
ind = i;
}
}
return ind;
}
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... |