跳到正文

题解

水题AT1814题解

Tetrahydrofunina约 1 分钟
原文
文章信息与版本

文章信息

发布
2022年2月10日
收录
2026年2月18日
更新
2026年11月11日
篇幅
约 1 分钟

版本

  1. v1当前

这题不就跟 P5057 差不多么。。。

由于区间异或满足区间加法原则,可以使用树状数组,把两个函数改动一下,就可以 AC 了。在代码里有标出改动处。

Code

C++
#include <bits/stdc++.h>
using namespace std;
int n;
bool c[500005];
inline int lowbit(int n){
	return n&(-n);
}
void update(int x){
	while(x<=n){
		c[x]^=1;//①
		x+=lowbit(x);
	}
}
bool getsum(int x){
	bool ans=0;
	while(x){
		ans^=c[x];//②
		x-=lowbit(x);
	}
	return ans;
}
int main(){
	int m,op,x,y;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		update(x);
		update(y+1);
	}
	for(int i=1;i<=n;i++)printf("%d",getsum(i));
	putchar('\n');
	return 0;
}

然后,就:

原文
存档评论1 条抓取于