이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int rt, pa[nx], lvl[nx];
vector<int> d[nx], res;
set<pair<int, int>> s[nx];
pair<int, int> mx;
pair<int, int> getmax(int x)
{
if (s[x].empty()) return {-1, -1};
return *(prev(s[x].end()));
}
void findmax(int x)
{
auto tmp=getmax(x);
tmp.first-=lvl[x];
mx=max(mx, tmp);
int u=x;
while (u!=0)
{
int t=pa[u];
for (auto v:d[t])
{
if (v==u) continue;
pair<int, int> tmp=getmax(v);
tmp.first-=lvl[v];
tmp.first+=lvl[x]-lvl[t]+1;
mx=max(mx, tmp);
}
u=t;
if (s[u].find({lvl[u], u})!=s[u].end()) mx=max(mx, {lvl[x]-lvl[u], u});
}
}
void addnode(int x)
{
int u=x;
s[u].insert({lvl[u], u});
while (u!=0) u=pa[u], s[u].insert({lvl[x], x});
}
void erasenode(int x)
{
int u=x;
s[u].erase({lvl[u], u});
while (u!=0) u=pa[u], s[u].erase({lvl[x], x});
}
std::vector<int> createFunTour(int N, int Q) {
for (int i=1; i<N; i++) d[(i-1)/2].push_back(i), pa[i]=(i-1)/2, lvl[i]=lvl[pa[i]]+1;
for (int i=0; i<N; i++) addnode(i);
rt=N-1;
res.push_back(rt);
erasenode(rt);
for (int i=1; i<N; i++)
{
//cout<<"rt "<<rt<<'\n';
mx={-1, -1};
findmax(rt);
//cout<<mx.first<<' '<<mx.second<<'\n';
res.push_back(mx.second);
erasenode(mx.second);
rt=mx.second;
}
/*
cout<<"res : ";
for (auto x:res) cout<<x<<' ';
cout<<'\n';
*/
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |