QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85297#5689. 喵了个喵 IIfengyuyueWA 514ms169136kbC++145.2kb2023-03-07 15:15:272023-03-07 15:15:29

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 15:15:29]
  • 评测
  • 测评结果:WA
  • 用时:514ms
  • 内存:169136kb
  • [2023-03-07 15:15:27]
  • 提交

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],to[E];
int num,dfn[V],low[V],col[V],scc,rk[V];
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--];
			col[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]);
	}
//	cerr<<"build"<<endl;
//	cerr<<"idx="<<idx<<" "<<"E="<<cnt<<endl;
	For(i,1,idx) if(!dfn[i]) Tar(i);
	
//	cerr<<"Tar"<<endl;
	For(i,1,n) if(col[id(i,0)]==col[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: 100
Accepted
time: 232ms
memory: 162288kb

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:

Yes
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok correct

Test #2:

score: 0
Accepted
time: 260ms
memory: 167952kb

input:

50000
39298 39298 14319 14319 11620 11620 20424 20424 14345 14345 28478 28478 11587 11587 25545 25545 24607 24607 18203 18203 30593 30593 144 144 2117 2117 14201 14201 27012 27012 20683 20683 39367 39367 7902 7902 12365 12365 17601 17601 29145 29145 15133 15133 47765 47765 22205 22205 13706 13706 20...

output:

Yes
01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

result:

ok correct

Test #3:

score: 0
Accepted
time: 221ms
memory: 162408kb

input:

50000
21684 21684 49246 49246 20339 20339 12374 12374 25130 25130 30869 30869 21854 21854 19251 19251 24016 24016 4812 4812 13915 13915 14386 14386 33943 33943 43449 43449 16175 16175 29984 29984 4712 4712 48795 48795 952 952 3589 3589 34274 34274 12915 12915 6840 6840 23436 23436 15670 15670 3873 3...

output:

Yes
01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

result:

ok correct

Test #4:

score: -100
Wrong Answer
time: 514ms
memory: 169136kb

input:

50000
236 236 32031 707 41062 32031 37516 21446 707 41062 37516 21446 26170 44004 47187 26170 9742 44004 47187 9742 14845 835 14845 43803 4270 835 43803 4270 44275 22853 44275 45825 5286 8810 10767 49050 26809 22853 36108 45825 46063 5286 6289 5206 8810 24938 33324 48973 10767 49050 49412 19286 4152...

output:

Yes
01000100111100010111001001110010000001010100100011000001111110011100000001110011100001110110000000000101011101010101110101100111101000001100011110000011110011110010100001110001100001111000011001110110011100110011000000111000000110101010000101011111010100111011101111101000110000001100110100101100...

result:

wrong answer Wrong Answer