求助……连下载来的数据都过了还是一片wa……
  • 板块P2574 XOR的艺术
  • 楼主f_hxr_
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/3/10 20:34
  • 上次更新2023/10/23 22:00:39
查看原帖
求助……连下载来的数据都过了还是一片wa……
754467
f_hxr_楼主2023/3/10 20:34

求助……连下载来的数据都过了还是一片wa……

#include<bits/stdc++.h>
using namespace std;
int n,m,a[100005],x,y,op;
char c;
struct node{
	long long l,r,dat,add;
}t[400005];
void bulid(int p,int l,int r){
	t[p].l=l;t[p].r=r;
	if(l==r){t[p].dat=a[l];return;}
	int mid=(l+r)>>1;
	bulid(p*2,l,mid);
	bulid(p*2+1,mid+1,r);
	t[p].dat=t[p*2].dat+t[p*2+1].dat;
	return;
}
void lazy(int p){
	if(t[p].add){
		t[p*2].dat=(t[p*2].r-t[p*2].l+1)-t[p*2].dat;
		t[p*2+1].dat=(t[p*2+1].r-t[p*2+1].l+1)-t[p*2+1].dat;
		t[p*2].add^=1;t[p*2+1].add^=1;
		t[p].add=0; 
	}
	return;
}
void change(int p,int x,int y){
	if(x<=t[p].l&&y>=t[p].r){
		t[p].dat=(t[p].r-t[p].l+1)-t[p].dat;
		t[p].add^=1;
		return;
	}
	lazy(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid)change(p*2,x,y);
	if(y>mid)change(p*2+1,x,y);
	t[p].dat=t[p*2].dat+t[p*2+1].dat;
	return;
}
long long ask(int p,int x,int y){
	if(x<=t[p].l && y>=t[p].r)return t[p].dat;
	lazy(p);
	int mid=(t[p].l+t[p].r)>>1;
	long long ans=0;
	if(x<=mid)ans+=ask(p*2,x,y);
	if(y>mid)ans+=ask(p*2+1,x,y);
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;i++)scanf("%c",&c),a[i]=(c=='1');
	bulid(1,1,n);
	while(m--){
		scanf("%d%d%d",&op,&x,&y);
		if(op==1)cout<<ask(1,x,y)<<endl;
		else change(1,x,y);
	}
	return 0;
} 
                                        

输入:

10 5
1001010110
1 2 3
0 6 9
1 7 10
1 2 5
1 2 7

输出: 0 1 1 2

QAQ QAQ QAQ

2023/3/10 20:34
加载中...