只有第二个点过了,求调
查看原帖
只有第二个点过了,求调
1066207
zongchengxin楼主2024/10/3 10:01

rt

#include <bits/stdc++.h>
using namespace std;
int n,q,tree[300005],t[300005];
void push_down(int k,int l,int r){
	int mid=(l+r)>>1;
	if(t[k]%2!=0){
		tree[k*2]=(mid-l+1)-tree[k*2],t[k*2]+=1;
		tree[k*2+1]=(r-mid)-tree[k*2+1],t[k*2+1]+=1; 
	}
	t[k]=0;
}
void change(int k,int x,int y,int a,int b){
	if(x>=a && y<=b){
		t[k]+=1;
	 	tree[k]=(y-x+1)-tree[k];
	 	//cout<<t[k]<<' '<<x<<' '<<y<<' '<<tree[k]<<endl;
	 	return ;
	}
	int mid=(x+y)>>1;
	push_down(k,x,y); 
	if(a<=mid) change(k*2,x,mid,a,b);
	if(b>mid) change(k*2+1,mid+1,y,a,b);
	tree[x]=tree[x*2]+tree[x*2+1];
}
int merge(int k,int x,int y,int a,int b){
	if(x>=a && y<=b){
		//cout<<x<<' '<<y<<' '<<tree[k]<<endl;
		return tree[k];
	}
	int mid=(x+y)>>1;
	push_down(k,x,y);
	int res=0;
	if(a<=mid) res+=merge(k*2,x,mid,a,b);
	if(b>mid) res+=merge(k*2+1,mid+1,y,a,b);
	return res;
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=q;i++){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t==0){
			change(1,1,n,a,b);
		}else{
			printf("%d\n",merge(1,1,n,a,b));
		}
	}
	return 0;
} 
2024/10/3 10:01
加载中...