이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "fun.h"
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<pii>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t)){
cerr<<", ";
}
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=2e5+5;
struct node{
int id, gleb=0;
node* l, *r, *par;
node(int id): id(id){}
};
bool czy[N];
int gleb[N];
int find_dist(node* v){
//deb("a");
if(!v->par)return 0;
if(v==v->par->l){
if(v->par->r)return max(find_dist(v->par)+1, v->par->r->gleb+2);
else return find_dist(v->par)+1;
}
else{
//deb(v->id);
if(v->par->l)return max(find_dist(v->par)+1, v->par->l->gleb+2);
else return find_dist(v->par)+1;
}
}
void upd(node*v){
v->gleb=0;
if(v->l)v->gleb=v->l->gleb+1;
if(v->r)v->gleb=max(v->gleb, v->r->gleb+1);
}
node* find(node* v, int dist, int t){
//deb("c");deb(v, dist, t);
if(v){
//deb(v, dist, t)
}
if(dist==0)return v;
if(t){
if(v->l && v->l->gleb==dist-1)return find(v->l, dist-1, 1);
else return find(v->r, dist-1, 1);
}
if(v==v->par->l && v->par->r && dist==v->par->r->gleb+2)return find(v->par->r, dist-2, 1);
if(v==v->par->r && v->par->l && dist==v->par->l->gleb+2)return find(v->par->l, dist-2, 1);
return find(v->par, dist-1, 0);
}
vector<node*> nodes;
std::vector<int> createFunTour(int n, int Q) {
//int H = hoursRequired(0, N - 1);
//int A = attractionsBehind(0, N - 1);
for(int i=0; i<n; i++){
nodes.pb(new node(i));
if(i){
nodes[i]->par=nodes[(i-1)/2];
if(i&1)nodes[i]->par->l=nodes[i];
else nodes[i]->par->r=nodes[i];
}
}
for(int i=n-1; i>=0; i--){
upd(nodes[i]);
}
vi ans;
node* root=nodes[0];
ans.pb(find(root, root->gleb, 1)->id);
while(ans.size()<n){
//deb(ans.back());
if(ans.back()==root->id){
//deb("a");
int d=root->gleb;
node*v=find(root, d, 1);
if(root->l==0){
root->r->par=0;
root=root->r;
}
else{
root->l->par=0;
root=root->l;
}
ans.pb(v->id);
}
else{
node*v=nodes[ans.back()];
int d=find_dist(v);
node*u=find(v, d, 0);
//deb(v->id, u->id, d);
if(v==v->par->l)v->par->l=0;
else v->par->r=0;
while(v->par){
v=v->par;
upd(v);
}
ans.pb(u->id);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:87:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
87 | while(ans.size()<n){
| ~~~~~~~~~~^~
# | 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... |