QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424119#8179. 2D ParenthesesAFewSunsWA 471ms78812kbC++204.1kb2024-05-28 22:02:392024-05-28 22:02:42

Judging History

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

  • [2024-05-28 22:02:42]
  • 评测
  • 测评结果:WA
  • 用时:471ms
  • 内存:78812kb
  • [2024-05-28 22:02:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
#define LC x<<1
#define RC x<<1|1
map<pair<ll,ll>,ll> mp;
set<pair<ll,ll> > s;
ll n,cnt=0,lsh[400040],tot=0,fa[200020],ans[200020];
ll tree[1600016],lz[1600016];
struct nd{
	ll x,y,t;
}a[400040];
struct node{
	ll x,y,xx,yy;
}b[200020];
struct line{
	ll pos,l,r,id,opt;
}c[400040];
il bl operator<(const line &x,const line &y){
	if(x.pos!=y.pos) return x.pos<y.pos;
	if(x.opt!=y.opt) return x.opt>y.opt;
	if(!x.opt){
		if((x.r-x.l)!=(y.r-y.l)) return (x.r-x.l)>(y.r-y.l);
		return x.id<y.id;
	}
	else{
		if((x.r-x.l)!=(y.r-y.l)) return (x.r-x.l)<(y.r-y.l);
		return x.id>y.id;
	}
}
il bl cmp(nd x,nd y){
	if(x.x==y.x) return x.y<y.y;
	return x.x<y.x;
}
il void pushup(ll x){
	if(tree[LC]==-1||tree[RC]==-1||tree[LC]!=tree[RC]) tree[x]=-1;
	else tree[x]=tree[LC];
}
void build(ll x,ll l,ll r){
	tree[x]=0;
	lz[x]=-1;
	if(l==r) return;
	ll mid=(l+r)>>1;
	build(LC,l,mid);
	build(RC,mid+1,r);
}
il void pushdown(ll x){
	if(lz[x]==-1) return;
	tree[LC]=tree[RC]=lz[LC]=lz[RC]=lz[x];
	lz[x]=-1;
	return;
}
void mdf(ll x,ll l,ll r,ll ql,ll qr,ll v){
	if(ql<=l&&r<=qr){
		tree[x]=lz[x]=v;
		return;
	}
	ll mid=(l+r)>>1;
	pushdown(x);
	if(ql<=mid) mdf(LC,l,mid,ql,qr,v);
	if(mid<qr) mdf(RC,mid+1,r,ql,qr,v);
	pushup(x);
}
ll query(ll x,ll l,ll r,ll ql,ll qr){
	if(ql<=l&&r<=qr) return tree[x];
	ll mid=(l+r)>>1;
	pushdown(x);
	if(qr<=mid) return query(LC,l,mid,ql,qr);
	if(ql>mid) return query(RC,mid+1,r,ql,qr);
	ll res1=query(LC,l,mid,ql,qr),res2=query(RC,mid+1,r,ql,qr);
	if(res1==-1||res2==-1||res1!=res2) return -1;
	else return res1;
}
int main(){
	n=read();
	fr(i,1,2*n){
		a[i].x=read();
		a[i].y=read();
		a[i].t=(i>n);
		mp[MP(a[i].x,a[i].y)]=i;
	}
	sort(a+1,a+2*n+1,cmp);
	fr(i,1,2*n){
		if(!a[i].t) s.insert(MP(a[i].y,a[i].x));
		else{
			set<pair<ll,ll> >::iterator it=s.upper_bound(MP(a[i].y-1,a[i].x-1));
			if(it!=s.begin()){
				pair<ll,ll> tmp=*(--it);
				b[++cnt]=(node){tmp.sec,tmp.fir,a[i].x,a[i].y};
				s.erase(tmp);
				ans[mp[MP(tmp.sec,tmp.fir)]]=mp[MP(a[i].x,a[i].y)]-n;
			}
		}
	}
	if(cnt!=n){
		pf("No");
		return 0;
	}
	fr(i,1,n){
		lsh[++tot]=b[i].y;
		lsh[++tot]=b[i].yy-1;
	}
	sort(lsh+1,lsh+tot+1);
	tot=unique(lsh+1,lsh+tot+1)-lsh-1;
	fr(i,1,n){
		b[i].y=lower_bound(lsh+1,lsh+tot+1,b[i].y)-lsh;
		b[i].yy=lower_bound(lsh+1,lsh+tot+1,b[i].yy-1)-lsh;
	}
	fr(i,1,n){
		c[2*i-1]=(line){b[i].x,b[i].y,b[i].yy,i,0};
		c[2*i]=(line){b[i].xx,b[i].y,b[i].yy,i,1};
	}
	sort(c+1,c+2*n+1);
	fr(i,1,2*n){
		if(!c[i].opt){
			ll tmp=query(1,1,tot,c[i].l,c[i].r);
			if(tmp==-1){
				pf("No");
				return 0;
			}
			fa[c[i].id]=tmp;
			mdf(1,1,tot,c[i].l,c[i].r,c[i].id);
		}
		else{
			ll tmp=query(1,1,tot,c[i].l,c[i].r);
			if(tmp!=c[i].id){
				pf("No");
				return 0;
			}
			mdf(1,1,tot,c[i].l,c[i].r,fa[c[i].id]);
		}
	}
	pf("Yes\n");
	fr(i,1,n) writeln(ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 13960kb

input:

3
0 0
2 -2
1 1
2 2
3 1
2 3

output:

Yes
3
2
1

result:

ok answer is YES, 3 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 13992kb

input:

2
1 0
0 1
2 3
3 2

output:

No

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 1ms
memory: 5688kb

input:

1
1 1
0 0

output:

No

result:

ok answer is NO

Test #4:

score: -100
Wrong Answer
time: 471ms
memory: 78812kb

input:

199996
94702923 895749121
-830347683 823853414
-638337012 -528381915
774504965 -903560893
465975432 931026841
47062323 901390864
539345338 830099354
278774201 896803047
-445303873 568413124
80473317 828648317
804283391 -307873779
543648687 893783688
814084625 -664894626
169476937 -999435847
-8232728...

output:

No

result:

wrong answer expected YES, found NO