QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85292#5689. 喵了个喵 IIfengyuyueRE 0ms0kbC++145.1kb2023-03-07 14:58:582023-03-07 14:59:00

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 14:59:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-03-07 14:58:58]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define INF 0x3f3f3f3f

using namespace std;

char aa;

namespace ljh
{

namespace IO
{
//    const int SIZ=1<<20;
//    char ibuf[SIZ],*p1,*p2,obuf[SIZ],*p3=obuf;
//  #define gc() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,SIZ,stdin),p1==p2)?EOF:*p1++)
//  void pc(const char &c)
//  {
//      if(p3-obuf==SIZ) fwrite(obuf,1,SIZ,stdout),p3=obuf;
//      *p3++=c;
//  }
    int rd()
    {
        int x=0,f=1;
        char ch=gc();
        while(!isdigit(ch)){
            if(ch=='-') f=-1;
            ch=gc();
        }
        while(isdigit(ch)){
            x=x*10+ch-'0';
            ch=gc();
        }
        return x*f;
    }
    void wr(int x,char ch)
    {
        if(x<0) x=-x,pc('-');
        static char st[12];
        int top=0;
        do{
            st[top++]=x%10+'0',x/=10;
        }while(x);
        while(top) pc(st[--top]);
        pc(ch);
    }
    ll ll_rd()
    {
        ll x=0;
        int f=1;
        char ch=gc();
        while(!isdigit(ch)){
            if(ch=='-') f=-1;
            ch=gc();
        }
        while(isdigit(ch)){
            x=x*10+ch-'0';
            ch=gc();
        }
        return x*f;
    }
    void ll_wr(ll x,char ch)
    {
        if(x<0) x=-x,pc('-');
        static char st[22];
        int top=0;
        do{
            st[top++]=x%10+'0',x/=10;
        }while(x);
        while(top) pc(st[--top]);
        pc(ch);
    }
}

using namespace IO;

const int N=5e4+5,V=(N<<7)+(N<<1),E=(N<<8)+(N<<2),mod=0;

namespace tem
{
    int qpow(int a,int b,int p)
    {
        a%=p;
        int res=1;
        while(b){
            if(b&1) res=1ll*res*a%p;
            a=1ll*a*a%p;
            b>>=1;
        }
        return res;
    }
    int get_inv(int x){return qpow(x,mod-2,mod);}
    int lowbit(int x){return x&(-x);}
    void add(int &x,const int y){ x=(x+y>=mod?x+y-mod:x+y); }
//  int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x])};
    int gcd(int a,int b){return b?gcd(b,a%b):a;}
    int lcm(int a,int b){return a/gcd(a,b)*b;}
}

using namespace tem;

int n,a[N<<2],p[N][5],c[N];
int cnt=1,head[V],nxt[E<<1],to[E<<1];
int num,dfn[V],low[V],col[V],scc,rk[N];
bool in_st[V];
int st[V],top;
vector<pii>vc[N<<2];
int ans[N];
char out[N<<2];

int id(int i,bool p)
{
	return p*n+i;
}

void add_edge(int u,int v){nxt[++cnt]=head[u],to[cnt]=v,head[u]=cnt;}

namespace seg
{
	int ls[N<<7],rs[N<<7];
	
	int rt[N<<2],idx;
	
	int ins(int p,int &q,int l,int r,int x)
	{
		q=++idx;
		ls[q]=ls[p],rs[q]=rs[p];
		if(l==r) return p;
		int mid=(l+r)>>1;
		return x<=mid?ins(ls[p],ls[q],l,mid,x):ins(rs[p],rs[q],mid+1,r,x);
	}
	
	void add(int p,int l,int r,int L,int R,int u)
	{
		if(!p) return ;
		if(L<=l&&R>=r) return add_edge(u,p),void();
		int mid=(l+r)>>1;
		if(L<=mid) add(ls[p],l,mid,L,R,u);
		if(R>mid) add(rs[p],mid+1,r,L,R,u);
	}
}

using namespace seg;

void Tar(int u)
{
	dfn[u]=low[u]=++num;
	st[++top]=u;
	in_st[u]=true;
	for_son(u){
		int v=to[e];
		if(!dfn[v]){
			Tar(v);
			low[u]=min(low[u],low[v]);
		}
		else if(in_st[v]) low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u]){
		++scc;
		int x=0;
		do{
			x=st[top--];
			c[x]=scc;
			in_st[x]=false;
			if(x<=n*2) rk[++rk[0]]=x;
		}while(x!=u);
	}
}

void main()
{
	n=rd();
	For(i,1,n*4) a[i]=rd(),p[a[i]][++c[a[i]]]=i;
	For(i,1,n){
		int x=p[i][1],y=p[i][2],z=p[i][3],w=p[i][4];
		vc[x].pb({y,id(i,1)}),vc[z].pb({w,id(i,1)});
		vc[x].pb({z,id(i,0)}),vc[y].pb({w,id(i,0)});
	}
	idx=n*2;
	IFor(i,n*4,1){
		rt[i]=rt[i+1];
		for(pii t:vc[i]){
			int x=ins(rt[i],rt[i],1,n*4,t.fi);
			add_edge(x,t.se);
		}
	}
	For(i,1,n){
		int x=p[i][1],y=p[i][2],z=p[i][3],w=p[i][4];
		add(rt[x+1],1,n*4,1,y,id(i,0)),add(rt[z+1],1,n*4,1,w,id(i,0));
		add(rt[x+1],1,n*4,1,z,id(i,1)),add(rt[y+1],1,n*4,1,w,id(i,1));
	}
	For(i,n*2+1,idx){
		if(ls[i]) add_edge(i,ls[i]);
		if(rs[i]) add_edge(i,rs[i]);
	}
	For(i,1,idx) if(!dfn[i]) Tar(i);
	For(i,1,n) if(c[id(i,0)]==c[id(i,1)]) return puts("No"),void();
	For(i,1,n) ans[i]=-1;
	For(i,1,n){
		int x=rk[i],y=x>n?x-n:x;
		if(ans[y]!=-1) continue;
		ans[y]=x>n;
	}
	For(i,1,n){
		int x=p[i][1],y=p[i][2],z=p[i][3],w=p[i][4];
		if(!ans[i]) out[x]=out[z]='0',out[y]=out[w]='1';
		else out[x]=out[y]='0',out[z]=out[w]='1';
	}
	puts("Yes");
	puts(out+1);
//  fwrite(obuf,1,p3-obuf,stdout);
}

/*
2
1 1 2 1 2 2 1 2
*/

}

char bb;

int main()
{
//  freopen("1.in","r",stdin);
//  freopen("1.out","w",stdout);    
//  int st=clock();
    ljh::main();
//  int ed=clock();
//  cerr<<ed-st<<"ms"<<endl;
//      cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

50000
12725 41478 2443 1096 36968 36898 3393 45898 43154 26629 22985 37972 13935 25628 40196 40293 39791 29109 455 45812 12634 21086 8928 13600 25416 30244 15917 22568 35849 40189 27442 28785 46334 25651 7172 30994 39724 27853 47091 21306 42087 31612 22081 23002 17127 15269 11569 8254 41080 30112 31...

output:


result: