QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233784#6633. Exam Requirementsugly2333ML 35ms345824kbC++202.3kb2023-10-31 22:57:452023-10-31 22:57:46

Judging History

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

  • [2023-10-31 22:57:46]
  • 评测
  • 测评结果:ML
  • 用时:35ms
  • 内存:345824kb
  • [2023-10-31 22:57:45]
  • 提交

answer

//Δ_C
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
const int W = N<<5;
int n,m,w,a[N],b[N],p[N],e[N];
vector<int> v[W],r[W];
void ins(int x,int y){
	v[x].push_back(y);//cout<<x<<' '<<y<<endl;
	r[y].push_back(x);
}
bool cmpa(int i,int j){
	return a[i]<a[j]||(a[i]==a[j]&&i<j);
}
bool cmpb(int i,int j){
	return b[i]<b[j];
}
vector<int> c;
int sz,t[1<<19];
void build(int k=1,int l=0,int r=sz){
	t[k]=++w;
	if(l==r){
		if(c[l]<=n)
			ins(t[k],c[l]);
		return;
	}
	int h=l+r>>1;
	build(k<<1,l,h);
	build(k<<1|1,h+1,r);
	ins(t[k],t[k<<1]);
	ins(t[k],t[k<<1|1]);
}
void query(int L,int R,int X,int k=1,int l=0,int r=sz){
	if(L>R)
		return;
	if(L<=l&&r<=R){
		ins(X,t[k]);
		return;
	}
	int h=l+r>>1;
	if(L<=h)
		query(L,R,X,k<<1,l,h);
	if(h<R)
		query(L,R,X,k<<1|1,h+1,r);
}
void solve(int l,int r){
	if(l==r)
		return;
	int h=l+r>>1,i,j,x;
	solve(l,h);
	solve(h+1,r);
	c.clear();
	for(i=l;i<=h;i++)
		c.push_back(p[i]),e[p[i]]=i;
	sz=c.size()-1;
	build();
	for(i=l,j=h+1;i<=h||j<=r;){
		if(i<=h&&(j>r||b[p[i]]<b[p[j]])){
			i++;
		}
		else{
			if(p[j]>n){
				x=e[p[j]-n];
				if(x&&x>=i){
					query(i-l,x-l-1,p[j]);
					query(x-l+1,h-l,p[j]);
				}
				else
					query(i-l,h-l,p[j]);
			}
			j++;
		}
	}
	for(i=l;i<=h;i++)
		e[p[i]]=0;
	sort(p+l,p+r+1,cmpb);
}
int tt,d[W],f[W];
void dfsr(int u){
	if(f[u])
		return;
	f[u]=1;
	int i,x;
	for(i=0;i<r[u].size();i++){
		x=r[u][i];
		dfsr(x);
	}
	d[++tt]=u;
}
void dfsv(int u,int ff){
	if(f[u])
		return;
	f[u]=ff;
	int i,x;
	for(i=0;i<v[u].size();i++){
		x=v[u][i];
		dfsv(x,ff);
	}
}
int main(){
	int T,i,x,y;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		for(i=1;i<=n;i++){
			scanf("%d%d",a+i,b+i);
			a[n+i]=b[i],b[n+i]=a[i];
		}
		for(i=1;i<=m;i++){
			scanf("%d%d",&x,&y);
			ins(x,n+y);
			ins(y,n+x);
		}
		for(i=1;i<=n*2;i++)
			p[i]=i;
		sort(p+1,p+n*2+1,cmpa);
		w=n*2;
		solve(1,n*2);
		tt=0;
		for(i=1;i<=w;i++)
			dfsr(i);
		for(i=1;i<=w;i++)
			f[i]=0;
		for(i=w;i>=1;i--)
			dfsv(d[i],d[i]);
		x=1;
		for(i=1;i<=n;i++)
			if(f[i]==f[n+i])
				x=0;
		if(x)
			printf("YES\n");
		else
			printf("NO\n");
		for(i=1;i<=w;i++)
			v[i].clear(),r[i].clear(),d[i]=0,f[i]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
memory: 345824kb

input:

2
3 1
1 5
2 7
10 11
2 1
3 3
1 5
2 7
5 7
1 2
2 3
3 1

output:

YES
NO

result:

ok 2 lines

Test #2:

score: -100
Memory Limit Exceeded

input:

1
100000 100000
15084647 15220430
217541056 217598054
222963701 223110976
71224450 71340221
320463268 320631387
334861459 334924668
328950591 329083669
178996498 178996584
428529461 428605033
405428435 405504132
197936687 197947412
9058562 9190197
169407597 169474101
297518153 297590927
31471874 316...

output:

NO

result: