QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784042 | #9630. 沙堆 | wcdr | AC ✓ | 2655ms | 359628kb | C++17 | 11.1kb | 2024-11-26 12:54:44 | 2024-11-26 12:54:45 |
Judging History
answer
#include<random>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<climits>
//#define NDEBUG
#include<cassert>
#include<cstring>
#include<complex>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<bitset>
//#define LL __int128
#define LL long long
#define ULL unsigned LL
#define uint unsigned int
//#define int LL
//#define double long double
#define mkp make_pair
#define par pair<int,int>
#define psb push_back
#define epb emplace_back
#define f(x) ((x).first)
#define s(x) ((x).second)
using namespace std;
#define Lbt(x) ((x)&(-(x)))
#define Swap(x,y) (x^=y^=x^=y)
const int Mxxx=1e5;
inline char gc()
{
// return getchar();
static char buf[Mxxx],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxxx,stdin),p1==p2)?EOF:*p1++;
}
inline char pc(char ch,bool fl=false)
{
// return fl?0:putchar(ch),0;
static char buf[Mxxx],*p1=buf,*p2=buf+Mxxx;
return (fl||((*p1++=ch)&&p1==p2))&&(fwrite(buf,1,p1-buf,stdout),p1=buf),0;
}
#define output pc('!',true)
inline int read()
{
char ch=gc();
int gans=0,gflag=0;
for(;ch<'0'||'9'<ch;gflag|=ch=='-',ch=gc());
for(;'0'<=ch&&ch<='9';gans=(gans<<1)+(gans<<3)+(ch^48),ch=gc());
return gflag?-gans:gans;
}
template<typename T>
inline char read(T&gans)
{
char ch=gc();
int gflag=0;gans=0;
for(;ch<'0'||'9'<ch;gflag|=ch=='-',ch=gc());
for(;'0'<=ch&&ch<='9';gans=(gans<<1)+(gans<<3)+(ch^48),ch=gc());
return gans=gflag?-gans:gans,ch;
}
template<typename T>
inline void write(T x)
{
if(x>9)write(x/10);
pc(x%10^48);
}
template<typename T>
inline void writenum(T x,char ch)
{
if(x<0)pc('-'),x=-x;
write(x);pc(ch);
}
inline void writechar(char x,char ch)
{
pc(x);pc(ch);
}
template<typename T>
inline T Max(T x,T y)
{
return x>y?x:y;
}
template<typename T>
inline T Min(T x,T y)
{
return x<y?x:y;
}
template<typename T>
inline T Abs(T x)
{
return x<0?-x:x;
}
template<typename T>
inline void ckmx(T&x,T y)
{
x=Max(x,y);
}
template<typename T>
inline void ckmn(T&x,T y)
{
x=Min(x,y);
}
namespace Splay
{
const int Mx=2e6;
#define ls(k) sn[0][k]
#define rs(k) sn[1][k]
int cnt,pr[Mx+5],sn[2][Mx+5];
int sz[Mx+5];LL vl[Mx+5];LL sm[Mx+5];
int D;inline void St(int d){D=d;}
inline void Up(int x)
{
sz[x]=sz[ls(x)]+sz[rs(x)]+1;
sm[x]=sm[ls(x)]+sm[rs(x)]+(vl[x]);//vl[x]-D
//sm[x]-=sz[x]*D
}
inline int Sn(int x)
{
return rs(pr[x])==x;
}
inline void Rtt(int x)
{
int y=pr[x],z=pr[y];
int l=Sn(x),r=l^1;
int p=sn[r][x],ch=Sn(y);
// assert(x&&y);
if(z)sn[ch][z]=x;
sn[r][x]=y;sn[l][y]=p;
if(p)pr[p]=y;
pr[y]=x;pr[x]=z;
Up(y);Up(x);
}
// inline void Pre_Dn(int x)
inline int Spy(int x)
{
int y;for(;(y=pr[x]);Rtt(x))if(pr[y])Rtt(Sn(x)==Sn(y)?y:x);
return assert(!pr[x]),x;
}
inline int Ins_L(int x,int v)
{
if(!x)return vl[++cnt]=v,Up(cnt),cnt;
assert(!pr[x]);
for(;ls(x);x=ls(x));
Spy(x);assert(!ls(x));
int k=++cnt;//assert(k);
pr[ls(x)=k]=x;vl[k]=v;
return Up(k),Up(x),x;
}
inline int Ck(int x,int y){return sz[x]<sz[y];}
inline int Get_L(int&x)
{
assert(!pr[x]);
for(;ls(x);x=ls(x));
Spy(x);assert(!ls(x));
int y=x;pr[x=rs(y)]=0;
return rs(y)=0,Up(y),y;
}
inline int Fnd_K(int x,int y,LL t)
{
if(!x)return x;
LL sl=sm[ls(x)]-(LL)sz[ls(x)]*(D-1);
if(sl+vl[x]-D+1<=t)return Fnd_K(rs(x),y,t-(sl+vl[x]-D+1));
return t<sl?Fnd_K(ls(x),y,t):x;
}
inline int Ins_K(int x,int y,LL t)
{
assert(!pr[x]);
int p=Fnd_K(x,y,t);
if(!p)
{
for(;rs(x);x=rs(x));
Spy(x);assert(!rs(x));
rs(x)=y;pr[y]=x;vl[y]=t-(sm[x]-(LL)sz[x]*(D-1))+(D-1);
return Up(y),Up(x),x;
}
Spy(p);int q=ls(p);
if(!q)return vl[y]=t-1+D,vl[p]-=t,
ls(p)=y,pr[y]=p,Up(y),Up(p),p;
LL sl=sm[ls(p)]-(LL)sz[ls(p)]*(D-1);
// cout<<"------------Ck_Mrg_Ins:"<<y<<" "<<p<<":"<<t<<" "<<sl<<"\n";
vl[y]=(t-sl)+(D-1);vl[p]-=t-sl;
pr[q]=y;pr[y]=p;ls(p)=y;ls(y)=q;
return Up(y),Up(p),p;
}
inline int Rcd_Mrg(vector<pair<pair<int,LL>,pair<int,LL> > >&v,int x,int y,LL&t)
{
if(!x)return y;
y=Rcd_Mrg(v,ls(x),y,t);
t+=vl[x]-D+1;int p=Fnd_K(y,x,t);
if(p)Spy(p),v.epb(mkp(mkp(x,vl[x]),mkp(p,vl[p])))
// ,cout<<"------------Ck_Rcd_Mrg:"<<x<<" "<<p<<":"<<t<<"\n"
;
else
{
for(p=y;rs(p);p=rs(p));
Spy(p);v.epb(mkp(mkp(x,vl[x]),mkp(0,0)));
// cout<<"------------Ck_Rcd_Mrg:"<<x<<" "<<0<<":"<<t<<"\n";
}
return y=p,Rcd_Mrg(v,rs(x),y,t);
}
inline int Mrg(int x,int y,LL t=0)
{
if(!y)return x;
assert(!pr[y]);
int z=Get_L(y);t+=vl[z]-D+1;
return Mrg(Ins_K(x,z,t),y,t);
}
int P;
inline LL Fnd(int x,int v,int f)
{
assert(v);if(!x)return assert(f),v-1;//!f?(cout<<"---Fnd?:"<<x<<":"<<v<<" "<<f<<"\n"):(void*)0,
LL sl=sm[ls(x)]-(LL)sz[ls(x)]*(D-1);P=x;
if(v<=sl*f+sz[ls(x)])return Fnd(ls(x),v,f);
return v<=(sl+vl[x]-D+1)*f+sz[ls(x)]+1?(f?Min(v-(sl*f+sz[ls(x)])-1+sl,sl+vl[x]-D):sl+vl[x]-D)
:sl+vl[x]-D+1+Fnd(rs(x),v-((sl+vl[x]-D+1)*f+sz[ls(x)]+1),f);
}
inline int Upd(){return Spy(P);}
inline int Ask(int x,LL t)
{
if(!x)return 0;
LL sl=sm[ls(x)]-(LL)sz[ls(x)]*(D-1);P=x;
if(t<sl)return Ask(ls(x),t);
return t<sl+vl[x]-D+1?sz[ls(x)]:sz[ls(x)]+1+Ask(rs(x),t-(sl+vl[x]-D+1));
}
inline int Ask_(int x,LL t)
{
if(!x)return 0;
LL sl=sm[ls(x)]-(LL)sz[ls(x)]*(D-1);
if(sl+vl[x]-D+1<=t)return Ask_(rs(x),t-(sl+vl[x]-D+1));
return t<sl?Ask(ls(x),t):x;
}
inline int Cut(int x,LL t)
{
// cout<<"Ck_Cut:"<<x<<" "<<t<<"\n";
int p=Ask_(x,t);
if(!p)
{
// for(;rs(x);x=rs(x));
// Spy(x);assert(!rs(x));
return 0;
}
Spy(p);
LL sl=sm[ls(p)]-(LL)sz[ls(p)]*(D-1);
vl[p]=(sl+vl[p]-D-t)+D;
pr[ls(p)]=0;ls(p)=0;
return Up(p),p;
}
inline int Rcd_Ask(int x,LL t,int&a,int&b)
{
int p=Ask_(x,t);
if(!p)
{
for(;rs(x);x=rs(x));
Spy(a=x);assert(!rs(x));
return b=0;
}
Spy(b=p);int q;
if((q=ls(p)))
{
for(;rs(q);q=rs(q));
Spy(a=q);
}else a=q;
return vl[p];
}
inline int Lnk(int x,int y)
{
Spy(x);Spy(y);
assert(!rs(x));
assert(!ls(y));
pr[ls(y)=x]=y;
return Up(y),y;
}
inline int Del(int x)
{
Spy(x);
if(!ls(x))return pr[rs(x)]=0,rs(x);
if(!rs(x))return pr[ls(x)]=0,ls(x);
int p=ls(x);pr[p]=0;
for(;rs(p);p=rs(p));
Spy(p);pr[rs(p)=rs(x)]=p;
return Up(p),p;
}
inline int Cov(int x,LL y)
{
return Spy(x),vl[x]=y,Up(x),x;
}
inline int Bld(const vector<pair<pair<int,LL>,pair<int,LL> > >&v,int&q)
{
for(auto to:v)
{
int p=f(f(to));q=Del(p);
pr[p]=ls(p)=rs(p)=vl[p]=0;
}
int ls=0;
for(auto to:v)
{
int p=f(f(to));if(f(s(to)))q=Cov(f(s(to)),s(s(to)));
vl[p]=s(f(to));ls(p)=ls;if(ls)pr[ls]=p;
Up(ls=p);
}
return ls;
}
// inline int Chk_Out(int x,LL t=0)
// {
// if(!x)return t;
// t=Chk_Out(ls(x),t);
// cout<<" "<<x<<"_"<<vl[x]<<"_"<<(t+=vl[x]-D+1)<<" ";
//// cout<<(t+=vl[x]-D+1)<<" ";
// return Chk_Out(rs(x),t);
// }
}
const int Mx=1e6;
int n,cnt,c[Mx+5],h[Mx+5],du[Mx+5],nxt[(Mx<<1)+5],tto[(Mx<<1)+5];
inline void ade(int x,int y){nxt[++cnt]=h[x];tto[h[x]=cnt]=y;du[y]++;}
inline void Ade(int x,int y){ade(x,y),ade(y,x);}int dp[Mx+5],rt[Mx+5];
vector<pair<pair<int,LL>,pair<int,LL> > >tp1[(Mx<<1)+5];int flg[(Mx<<1)+5];
inline int Rcd(int x,int y,int z,int p)
{
LL tp=0;flg[y]=z;
return Splay::Rcd_Mrg(tp1[y],x,p,tp);
}int tp2[Mx+5],tp3[Mx+5],tp5[Mx+5];
inline int Rcd_(int x,LL y,int z)
{
return tp5[z]=Splay::Rcd_Ask(x,y,tp2[z],tp3[z]),tp2[z]?tp2[z]:tp3[z];
}int tp4[Mx+5];
inline void Rcdd(int x,int y)
{
tp4[y]=x;
}LL tt[Mx+5];
inline void DFS(int x,int y,int z)
{
int i,to;dp[x]=z;
for(i=h[x];i;i=nxt[i])if((to=tto[i])^y)
{
DFS(to,x,z+1);
if(!rt[x]&&!rt[to])continue;
Splay::St(z+1);
if(Splay::Ck(rt[x],rt[to]))
{
rt[to]=Rcd(rt[x],i,0,rt[to]);
rt[x]=Splay::Mrg(rt[to],rt[x]);
}
else
{
rt[x]=Rcd(rt[to],i,1,rt[x]);
rt[x]=Splay::Mrg(rt[x],rt[to]);
}
}
// cout<<"Ck_son_merge:"<<x<<" "<<Splay::sz[rt[x]]<<":";Splay::St(z+1);Splay::Chk_Out(rt[x]);cout<<"\n";
if(c[x]>=du[x])
{
Splay::St(z+1);Splay::P=rt[x];
LL t=Splay::Fnd(rt[x],c[x]-du[x]+1,y!=0)+1;
rt[x]=Splay::Upd();Splay::P=rt[x];tt[x]=t;
c[x]-=(y!=0)*t+Splay::Ask(rt[x],t);
rt[x]=Splay::Upd();
if(y)c[y]+=t;
// cout<<"Ck???"<<x<<" "<<t<<":"<<rt[x]<<"???\n";
rt[x]=Rcd_(rt[x],t,x);
rt[x]=Splay::Cut(rt[x],t);
}
// cout<<"Ck_Splay_before:"<<x<<" "<<Splay::sz[rt[x]]<<":";Splay::St(z+1);Splay::Chk_Out(rt[x]);cout<<"\n";
int k;for(i=1,Rcdd(k=du[x]-1-c[x],x);i<=k;i++)
rt[x]=Splay::Ins_L(rt[x],dp[x]);
// cout<<"Ck_Splay:"<<x<<" "<<Splay::sz[rt[x]]<<":";Splay::St(z);Splay::Chk_Out(rt[x]);cout<<"\n";
// cout<<"Ck_DFS1_end:"<<x<<" "<<y<<":"<<c[x]<<"_c "<<tt[x]<<"_t "<<c[y]<<"_y\n";
// cout<<"Ck_DFS1_end:"<<x<<" "<<y<<":"<<c[x]<<"_c "<<tt[x]<<"_t "<<c[y]<<"_y | | | "<<Splay::ls(0)<<" "<<Splay::rs(0)<<" "<<Splay::pr[0]<<"\n";
// cout<<"Ck_DFS1_end:"<<x<<" "<<y<<":"<<c[x]<<" "<<tt[x]<<"|"<<c[y]<<" "<<du[x]<<" "<<du[y]<<"\n";
}
inline void DFS(int x,int y)
{
int i,to;
for(i=1;i<=tp4[x];i++)Splay::Get_L(rt[x]);
// cout<<"Ck_Splay2:"<<x<<" "<<Splay::sz[rt[x]]<<":";Splay::St(dp[x]+1);Splay::Chk_Out(rt[x]);cout<<"\n";
if(c[x]>=du[x])
{
Splay::St(dp[x]+1);Splay::P=rt[x];
LL t=Splay::Fnd(rt[x],c[x]-du[x]+1,y!=0)+1;
// cout<<"Now????:"<<x<<" "<<Splay::sz[rt[x]]<<":";Splay::St(dp[x]+1);Splay::Chk_Out(rt[x]);cout<<"\n";
// cout<<"--ck_t:"<<x<<" "<<t<<":"<<c[x]<<" "<<du[x]<<"|"<<rt[x]<<"?"<<Splay::Ask(rt[x],t)<<"\n";
rt[x]=Splay::Upd();Splay::P=rt[x];tt[x]+=t;
c[x]-=(y!=0)*t+Splay::Ask(rt[x],t);
rt[x]=Splay::Upd();
// if(y)c[y]+=t;
}
// cout<<"Ck_DFS2:"<<x<<":"<<c[x]<<" "<<tt[x]<<"\n";//<<" | | | "<<Splay::ls(0)<<" "<<Splay::rs(0)<<" "<<Splay::pr[0]<<"\n";
if(tp3[x])
{
rt[x]=Splay::Cov(tp3[x],tp5[x]);
if(tp2[x])rt[x]=Splay::Lnk(tp2[x],tp3[x]);
}else if(tp2[x])rt[x]=tp2[x];
vector<int>tmp;tmp.clear();
for(i=h[x];i;i=nxt[i])if((to=tto[i])^y)
{
tmp.epb(i);
// c[to]+=tt[x];
// DFS(to,x);
}
for(;!tmp.empty();tmp.pop_back())
{
i=tmp.back();to=tto[i];Splay::St(dp[x]+1);
c[to]+=tt[x];rt[to]=Splay::Bld(tp1[i],rt[x]);
if(!flg[i])swap(rt[x],rt[to]);
// if(to==11)puts("");
// cout<<"Ck_DFS2_to_Splay:"<<x<<"->"<<to<<" "<<Splay::sz[rt[to]]<<":";Splay::St(dp[x]+1);Splay::Chk_Out(rt[to]);cout<<"\n";
// cout<<"Ck_DFS2_:"<<x<<" "<<Splay::sz[rt[x]]<<":";Splay::St(dp[x]+1);Splay::Chk_Out(rt[x]);cout<<"\n";
// if(to==13)puts("");
DFS(to,x);
}
}
signed main()
{
#ifndef ONLINE_JUDGE
system("fc _.out __.out");
freopen("_.in","r",stdin);
freopen("_.out","w",stdout);
#endif
int i,s=0;n=read();
for(i=1;i<n;i++)Ade(read(),read());
for(i=1;i<=n;i++)c[i]=read(),s+=du[i]-1;
for(i=1;i<=n;i++)if((s-=c[i])<0)return writenum(-1,10),output;
DFS(1,0,1);//puts("-------------------------");
DFS(1,0);for(i=1;i<=n;i++)writenum(c[i],i==n?10:32);
return output;
}//0 0 2 2 0 1 1 1 0 1 1 1 1 0 0
//0 0 2 2 0 1 1 1 0 1 1 1 1 1 0
/*
6
1 2
2 3
2 4
1 5
4 6
1 1 0 0 1 1
*/
/*
12
1 2
1 3
2 4
3 5
5 6
2 7
7 8
4 9
8 10
5 11
3 12
2 0 0 0 1 0 1 0 1 1 0 1
*/
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 77340kb
input:
6 1 2 2 3 2 4 1 5 4 6 1 1 0 0 1 1
output:
1 2 0 1 0 0
result:
ok single line: '1 2 0 1 0 0'
Test #2:
score: 0
Accepted
time: 4ms
memory: 77348kb
input:
12 1 2 1 3 2 4 3 5 5 6 2 7 7 8 4 9 8 10 5 11 3 12 2 0 0 0 1 0 1 0 1 1 0 1
output:
0 1 2 1 1 0 1 1 0 0 0 0
result:
ok single line: '0 1 2 1 1 0 1 1 0 0 0 0'
Test #3:
score: 0
Accepted
time: 7ms
memory: 77364kb
input:
40 1 2 2 3 1 4 3 5 5 6 6 7 4 8 6 9 8 10 6 11 6 12 9 13 10 14 7 15 9 16 15 17 15 18 12 19 18 20 16 21 18 22 22 23 5 24 22 25 2 26 24 27 14 28 27 29 20 30 29 31 30 32 20 33 26 34 26 35 19 36 11 37 34 38 37 39 29 40 3 0 0 0 0 1 1 0 1 0 1 0 1 0 0 0 0 0 1 1 3 0 1 0 3 0 0 0 1 0 0 0 0 0 0 0 0 0 2 1
output:
1 1 0 1 0 4 1 0 2 0 1 0 0 0 0 1 0 2 1 1 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 0 1 0 0 0
result:
ok single line: '1 1 0 1 0 4 1 0 2 0 1 0 0 0 0 ...0 0 0 0 2 0 0 0 0 0 0 0 1 0 0 0'
Test #4:
score: 0
Accepted
time: 12ms
memory: 80100kb
input:
5000 1 2 1 3 2 4 4 5 3 6 5 7 7 8 6 9 8 10 9 11 10 12 11 13 13 14 14 15 12 16 16 17 15 18 17 19 16 20 18 21 16 22 15 23 20 24 24 25 25 26 22 27 23 28 19 29 27 30 29 31 27 32 28 33 32 34 31 35 26 36 34 37 35 38 35 39 33 40 38 41 40 42 42 43 30 44 41 45 37 46 39 47 47 48 36 49 48 50 46 51 44 52 51 53 4...
output:
1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 ...
result:
ok single line: '1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #5:
score: 0
Accepted
time: 13ms
memory: 78012kb
input:
5000 1 2 1 3 2 4 3 5 4 6 5 7 6 8 8 9 7 10 9 11 10 12 6 13 11 14 12 15 13 16 16 17 14 18 17 19 17 20 19 21 15 22 21 23 22 24 18 25 23 26 24 27 25 28 28 29 27 30 29 31 26 32 30 33 19 34 34 35 32 36 20 37 37 38 31 39 35 40 39 41 40 42 42 43 41 44 33 45 43 46 38 47 46 48 45 49 48 50 44 51 49 52 51 53 50...
output:
1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 ...
result:
ok single line: '1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #6:
score: 0
Accepted
time: 11ms
memory: 80072kb
input:
5000 1 2 1 3 2 4 3 5 4 6 5 7 6 8 8 9 7 10 10 11 9 12 11 13 12 14 13 15 15 16 14 17 17 18 16 19 18 20 19 21 21 22 20 23 22 24 23 25 24 26 26 27 25 28 28 29 27 30 29 31 31 32 30 33 32 34 33 35 35 36 34 37 36 38 37 39 39 40 38 41 40 42 31 43 41 44 43 45 44 46 42 47 46 48 45 49 48 50 49 51 51 52 52 53 5...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 2 0 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 2 1 1 1 1 2 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 ...
result:
ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #7:
score: 0
Accepted
time: 16ms
memory: 77988kb
input:
5000 1 2 1 3 2 4 3 5 5 6 4 7 7 8 6 9 9 10 10 11 8 12 11 13 13 14 12 15 14 16 16 17 7 18 15 19 18 20 19 21 17 22 22 23 20 24 24 25 23 26 21 27 25 28 27 29 29 30 28 31 26 32 31 33 30 34 32 35 35 36 34 37 33 38 38 39 39 40 40 41 37 42 41 43 43 44 42 45 36 46 44 47 45 48 46 49 48 50 47 51 43 52 49 53 52...
output:
1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 2 1 1 3 1 1 1 2 1 1 1 2 0 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 0 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 0 1 1 0 2 1 1 1 0 2 1 1 1 0 1 1 1 0 0 1 1 1 1 1 2 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 4 0 1 0 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #8:
score: 0
Accepted
time: 11ms
memory: 78040kb
input:
5000 1 2 1 3 2 4 3 5 5 6 4 7 6 8 8 9 8 10 10 11 9 12 11 13 7 14 13 15 12 16 14 17 15 18 16 19 18 20 19 21 20 22 17 23 21 24 24 25 23 26 26 27 22 28 25 29 27 30 28 31 31 32 30 33 32 34 33 35 34 36 35 37 37 38 38 39 36 40 40 41 39 42 29 43 42 44 44 45 42 46 46 47 41 48 47 49 49 50 45 51 43 52 51 53 48...
output:
1 1 1 1 1 1 1 2 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 ...
result:
ok single line: '1 1 1 1 1 1 1 2 1 1 1 1 1 0 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #9:
score: 0
Accepted
time: 9ms
memory: 78280kb
input:
5000 1 2 1 3 2 4 3 5 4 6 5 7 6 8 8 9 7 10 8 11 9 12 10 13 11 14 13 15 14 16 15 17 17 18 16 19 17 20 12 21 18 22 20 23 21 24 24 25 23 26 20 27 22 28 28 29 25 30 29 31 27 32 30 33 32 34 34 35 33 36 30 37 36 38 31 39 35 40 37 41 26 42 39 43 38 44 19 45 42 46 44 47 40 48 46 49 49 50 45 51 48 52 47 53 50...
output:
1 1 0 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 ...
result:
ok single line: '1 1 0 1 1 1 1 2 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #10:
score: 0
Accepted
time: 8ms
memory: 78052kb
input:
5000 1 2 2 3 1 4 3 5 4 6 5 7 6 8 7 9 6 10 6 11 10 12 11 13 13 14 12 15 9 16 14 17 15 18 16 19 17 20 18 21 21 22 22 23 18 24 20 25 23 26 25 27 8 28 28 29 26 30 24 31 27 32 19 33 30 34 29 35 33 36 34 37 37 38 35 39 34 40 32 41 36 42 42 43 39 44 43 45 44 46 45 47 46 48 41 49 47 50 49 51 48 52 52 53 50 ...
output:
1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 0 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 0 1 1 1 3 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 4 1 1 1 2 ...
result:
ok single line: '1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #11:
score: 0
Accepted
time: 7ms
memory: 78196kb
input:
5000 1 2 2 3 3 4 4 5 1 6 6 7 7 8 5 9 8 10 10 11 9 12 12 13 11 14 13 15 10 16 15 17 14 18 17 19 17 20 16 21 20 22 19 23 22 24 23 25 24 26 25 27 25 28 21 29 18 30 26 31 27 32 30 33 31 34 32 35 34 36 36 37 37 38 38 39 35 40 39 41 40 42 29 43 41 44 44 45 42 46 41 47 43 48 28 49 47 50 46 51 50 52 51 53 5...
output:
1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 0 1 2 1 2 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 ...
result:
ok single line: '1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #12:
score: 0
Accepted
time: 15ms
memory: 75944kb
input:
5000 1 2 1 3 3 4 2 5 4 6 6 7 5 8 7 9 8 10 9 11 10 12 3 13 11 14 14 15 11 16 13 17 17 18 16 19 15 20 20 21 21 22 18 23 19 24 22 25 12 26 24 27 27 28 25 29 26 30 29 31 30 32 23 33 30 34 34 35 33 36 35 37 32 38 37 39 36 40 18 41 39 42 28 43 41 44 31 45 43 46 44 47 40 48 46 49 47 50 49 51 42 52 38 53 45...
output:
1 1 2 1 1 1 1 1 1 1 2 1 1 1 0 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 2 0 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '1 1 2 1 1 1 1 1 1 1 2 1 1 1 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #13:
score: 0
Accepted
time: 2655ms
memory: 359628kb
input:
1000000 1 2 1 3 2 4 3 5 4 6 5 7 7 8 8 9 9 10 8 11 6 12 12 13 13 14 11 15 15 16 14 17 16 18 11 19 15 20 18 21 10 22 22 23 19 24 20 25 15 26 25 27 25 28 28 29 17 30 30 31 29 32 30 33 24 34 31 35 34 36 33 37 23 38 28 39 32 40 26 41 21 42 42 43 27 44 39 45 36 46 43 47 37 48 34 49 44 50 47 51 50 52 48 53...
output:
1 1 1 1 1 1 1 2 1 1 2 1 1 1 3 1 1 1 1 1 1 1 1 1 2 1 1 3 1 2 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 0 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 2 1 1 1 1 1 1 0 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 0 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 ...
result:
ok single line: '1 1 1 1 1 1 1 2 1 1 2 1 1 1 3 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #14:
score: 0
Accepted
time: 2541ms
memory: 349212kb
input:
1000000 1 2 2 3 2 4 4 5 3 6 6 7 5 8 7 9 9 10 1 11 9 12 10 13 11 14 12 15 14 16 15 17 13 18 17 19 16 20 20 21 18 22 8 23 22 24 19 25 24 26 21 27 23 28 25 29 26 30 30 31 28 32 27 33 32 34 26 35 31 36 35 37 36 38 33 39 37 40 34 41 35 42 39 43 42 44 41 45 43 46 38 47 40 48 45 49 29 50 44 51 48 52 49 53 ...
output:
1 2 1 1 1 1 1 1 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 3 1 1 2 1 1 1 1 1 1 1 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 2 2 1 2 2 2 1 1 1 ...
result:
ok single line: '1 2 1 1 1 1 1 1 2 1 0 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #15:
score: 0
Accepted
time: 1936ms
memory: 288668kb
input:
1000000 1 2 1 3 3 4 2 5 4 6 5 7 6 8 7 9 9 10 8 11 10 12 11 13 12 14 13 15 14 16 16 17 17 18 15 19 19 20 18 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 29 28 30 29 31 31 32 32 33 30 34 33 35 35 36 34 37 36 38 37 39 38 40 40 41 39 42 41 43 42 44 43 45 44 46 45 47 47 48 46 49 48 50 49 51 50 52 51 5...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #16:
score: 0
Accepted
time: 2138ms
memory: 317096kb
input:
1000000 1 2 1 3 2 4 4 5 3 6 5 7 6 8 7 9 8 10 9 11 11 12 10 13 12 14 14 15 13 16 15 17 16 18 15 19 18 20 17 21 19 22 20 23 22 24 23 25 21 26 24 27 27 28 25 29 28 30 26 31 31 32 30 33 29 34 33 35 32 36 35 37 36 38 34 39 38 40 40 41 41 42 39 43 37 44 42 45 44 46 45 47 43 48 47 49 48 50 49 51 46 52 50 5...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #17:
score: 0
Accepted
time: 21ms
memory: 83752kb
input:
1000000 1 2 1 3 2 4 3 5 4 6 6 7 5 8 8 9 7 10 9 11 11 12 10 13 13 14 12 15 14 16 16 17 15 18 17 19 19 20 18 21 21 22 20 23 22 24 23 25 24 26 26 27 25 28 27 29 28 30 29 31 30 32 32 33 33 34 31 35 34 36 36 37 35 38 38 39 37 40 39 41 41 42 40 43 42 44 43 45 44 46 45 47 46 48 47 49 48 50 49 51 50 52 51 5...
output:
-1
result:
ok single line: '-1'
Test #18:
score: 0
Accepted
time: 12ms
memory: 81536kb
input:
1000000 1 2 1 3 3 4 2 5 4 6 5 7 7 8 8 9 6 10 9 11 10 12 11 13 13 14 12 15 14 16 15 17 17 18 16 19 18 20 19 21 21 22 20 23 22 24 23 25 24 26 25 27 26 28 28 29 27 30 30 31 31 32 32 33 29 34 33 35 34 36 36 37 35 38 38 39 37 40 39 41 40 42 41 43 42 44 44 45 45 46 43 47 46 48 47 49 49 50 48 51 50 52 51 5...
output:
-1
result:
ok single line: '-1'
Test #19:
score: 0
Accepted
time: 1574ms
memory: 256420kb
input:
1000000 1 2 2 3 1 4 3 5 4 6 5 7 6 8 8 9 7 10 10 11 9 12 11 13 13 14 14 15 12 16 15 17 16 18 17 19 19 20 20 21 18 22 21 23 22 24 23 25 25 26 24 27 27 28 26 29 29 30 28 31 30 32 32 33 33 34 31 35 34 36 35 37 37 38 36 39 38 40 39 41 40 42 42 43 41 44 43 45 44 46 45 47 46 48 48 49 49 50 47 51 50 52 51 5...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #20:
score: 0
Accepted
time: 1673ms
memory: 265328kb
input:
1000000 1 2 2 3 3 4 4 5 1 6 5 7 6 8 8 9 7 10 10 11 11 12 9 13 12 14 14 15 13 16 16 17 15 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 26 27 25 28 27 29 29 30 28 31 30 32 31 33 32 34 34 35 33 36 35 37 36 38 37 39 38 40 39 41 41 42 42 43 40 44 43 45 44 46 46 47 47 48 48 49 45 50 49 51 48 52 52 5...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #21:
score: 0
Accepted
time: 7ms
memory: 56800kb
input:
1 1
output:
-1
result:
ok single line: '-1'