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 "fun.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
vector<int>createFunTour(int N,int Q){
vector<int>adj[N];
for(int i=1;i<N;i++){
int p=(i-1)/2;
adj[i].pb(p);
adj[p].pb(i);
}
set<pair<int,int>,greater<pair<int,int>>>st[N];
for(int i=0;i<N;i++){
int cur=i,dist=0;
while(true){
st[cur].insert({dist,cur});
if(cur==0) break;
cur=(cur-1)/2;
dist++;
}
}
auto [z,s]=*st[0].begin();
vector<int>ans={s};
for(int i=2;i<=N;i++){
if(i<N){
int cur=s,dist=0;
while(true){
st[cur].erase({dist,s});
if(cur==0) break;
cur=(cur-1)/2;
dist++;
}
}
int cur=s,bef=-1;
int mx=-1,nxt=-1;
while(true){
if(cur==s){
auto [D,j]=*st[cur].begin();
if(D>mx){
mx=D;
nxt=j;
}
}
else{
for(auto u:adj[cur]){
if(u<cur||u==bef) continue;
auto [D,j]=*st[cur].begin();
if(D>mx){
mx=D;
nxt=j;
}
}
}
if(cur==0) break;
bef=cur;
cur=(cur-1)/2;
}
ans.pb(nxt);
s=nxt;
}
return ans;
}
# | 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... |