比赛 2026.9.12 评测结果 AAAAAAAAAA
题目名称 画线 最终得分 100
用户昵称 2_16鸡扒拌面 运行时间 1.404 s
代码语言 C++ 内存使用 15.61 MiB
提交时间 2026-09-12 12:23:25
显示代码纯文本
#include<bits/stdc++.h>
#define SNSNMO 1000010
#define ll long long
using namespace std;

int n,q;
int match[SNSNMO],mx[SNSNMO*4],mn[SNSNMO*4];

void build(int p,int l,int r)
{
	if(l==r)
	{
		if(match[l]==0||match[l]==n+1)
		{
			mx[p]=0;
			mn[p]=n+1;
		}
		else mx[p]=mn[p]=match[l];
		return;
	}
	int m=(l+r)/2;
	build(p*2,l,m);
	build(p*2+1,m+1,r);
	mx[p]=max(mx[p*2],mx[p*2+1]);
	mn[p]=min(mn[p*2],mn[p*2+1]);
}

void update(int p,int l,int r,int pos,int val)
{
	if(l==r)
	{
		mx[p]=mn[p]=val;
		return;
	}
	int m=(l+r)/2;
	if(pos<=m) update(p*2,l,m,pos,val);
	else update(p*2+1,m+1,r,pos,val);
	mx[p]=max(mx[p*2],mx[p*2+1]);
	mn[p]=min(mn[p*2],mn[p*2+1]);
}

void query(int p,int l,int r,int L,int R,int &rmx,int &rmn)
{
	if(L<=l&&r<=R)
	{
		rmx=max(rmx,mx[p]);
		rmn=min(rmn,mn[p]);
		return;
	}
	int m=(l+r)/2;
	if(L<=m) query(p*2,l,m,L,R,rmx,rmn);
	if(R>m) query(p*2+1,m+1,r,L,R,rmx,rmn);
}

int main()
{
	freopen("circle.in","r",stdin);
	freopen("circle.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin>>n>>q;
	for(int i=1;i<=n;++i) match[i]=n+1;
	build(1,1,n);
	while(q--)
	{
		int x,y;
		cin>>x>>y;
		if(x>y) swap(x,y);
		if(x+1<=y-1)
		{
			int rmx=0,rmn=n+1;
			query(1,1,n,x+1,y-1,rmx,rmn);
			if(!(rmx==0&&rmn==n+1))
			{
				if(rmx>y||rmn<x)
				{
					cout<<"No"<<'\n';
					continue;
				}
			}
		}
		cout<<"Yes"<<'\n';
		match[x]=y;match[y]=x;
		update(1,1,n,x,y);
		update(1,1,n,y,x);
	}
	return 0;
}