求助
查看原帖
求助
1161520
Michael1234楼主2024/5/11 23:25
  • 树状数组 #3 WA 求助!
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
using namespace std;
const int N=1e5+5;
int n,q,opt,x,y,x1,x2,yy,y2,tr[3][N];
inline void fx(int x,int y,int k)
{
	for(;x<=n;x+=x&-x) tr[1][x]+=k;
	for(;y<=n;y+=y&-y) tr[2][y]+=k;
	return;
}
inline int gt(int x,int k)
{
	int res=0;
	for(;x;x-=x&-x) res+=tr[k][x];
	return res;
}
inline bool sch(int a,int b,int c,int d)
{
	return ((gt(c,1)-gt(a-1,1)==c-a+1||gt(d,2)-gt(b-1,2)==d-b+1)?true:false);
}
signed main()
{
	ios;cin>>n>>q;
	while(q--)
	{
		cin>>opt;
		if(opt==1) {cin>>x>>y;fx(x,y,1);}
		else if(opt==2) {cin>>x>>y;fx(x,y,-1);}
		else {cin>>x1>>yy>>x2>>y2;cout<<(sch(x1,yy,x2,y2)?"Yes\n":"No\n");}
	}
	exit(0);
}
2024/5/11 23:25
加载中...