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 "art.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int _n, sz, X;
vector<int> a;
vector<int> tree;
int merge(int x, int y) {
if (x==0) return y;
else if (y==0) return x;
a[x-1]=y; a[y-1]=x;
int r=publish(a);
a[x-1]=x; a[y-1]=y;
if (r<X) return y;
else return x;
}
void build(int v, int l, int r) {
if (r-l==1) return;
int mid=(l+r)>>1;
build(2*v+1,l,mid);
build(2*v+2,mid,r);
int x=tree[2*v+1], y=tree[2*v+2];
tree[v]=merge(x,y);
}
int _quit=0;
void update(int v, int l, int r, int i) {
if (l>i || r<=i) return;
if (r-l==1) return;
int mid=(l+r)>>1;
int old=tree[v];
update(2*v+1,l,mid,i);
update(2*v+2,mid,r,i);
if (_quit) return;
int x=tree[2*v+1], y=tree[2*v+2];
tree[v]=merge(x,y);
if (tree[v]==old) _quit=1;
}
void upd(int i) {
_quit=0;
tree[sz+i-1]=0;
update(0,0,sz,i);
}
void print() {
cout<<"TREE: \n";
int z=0;
while (z<tree.size()) {
for (int i=z; i<2*z+1; i++) cout<<tree[i]<<' ';
cout<<'\n';
z=z*2+1;
}
cout<<'\n';
}
void solve (int n) {
_n=n;
a.assign(n,0);
for (int i=0; i<n; ++i) a[i]=i+1;
X = publish(a);
sz=1; while (sz<n) sz<<=1;
tree.assign(2*sz-1,0);
for (int i=0; i<n; ++i) tree[sz+i-1]=i+1;
build(0,0,sz);
vector<int> ans;
for (int i=0; i<n; ++i) {
ans.push_back(tree[0]);
upd(tree[0]-1);
}
answer(ans);
}
Compilation message (stderr)
art.cpp: In function 'void print()':
art.cpp:54:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while (z<tree.size()) {
| ~^~~~~~~~~~~~
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(v.size() != N) {
| ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if(v.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |