题目描述
题目来源:CQOI 2006
有一个 nnn 个元素的数组,每个元素初始均为 000。有 mmm 条指令,要么让其中一段连续序列数字反转——000 变 111,111 变 000(操作 111),要么询问某个元素的值(操作 222)。
例如当 n=20n=20n=20 时,101010 条指令如下:
操作 | 回答 | 操作后的数组 |
---|---|---|
1 1 101\ 1\ 101 1 10 | N/A | 111111111100000000001111111111000000000011111111110000000000 |
2 62\ 62 6 | 111 | 111111‾1111000000000011111\underline{1}1111000000000011111111110000000000 |
2 122\ 122 12 | 000 | 111111111100‾0000000011111111110\underline{0}0000000011111111110000000000 |
1 5 121\ 5\ 121 5 12 | N/A | 111100000011000000001111000000110000000011110000001100000000 |
2 62\ 62 6 | 000 | 111100‾0000110000000011110\underline{0}0000110000000011110000001100000000 |
2 152\ 152 15 | 000 | 111100000011000‾0000011110000001100\underline 00000011110000001100000000 |
1 6 161\ 6\ 161 6 16 | N/A | 11110111110011110000 1111011111001111000011110111110011110000 |
1 11 171\ 11\ 171 11 17 | N/A | 111101111111000010001111011111110000100011110111111100001000 |
2 122\ 122 12 | 111 | 111101111111‾0000100011110111111\underline 10000100011110111111100001000 |
2 62\ 62 6 | 111 | 111101‾1111110000100011110\underline 11111110000100011110111111100001000 |
输入格式
第一行包含两个整数 n,mn,mn,m,表示数组的长度和指令的条数;
以下 mmm 行,每行的第一个数 ttt 表示操作的种类:
- 若 t=1t=1t=1,则接下来有两个数 L,RL, RL,R,表示区间 [L,R][L, R][L,R] 的每个数均反转;
- 若 t=2t=2t=2,则接下来只有一个数 iii,表示询问的下标。
输出格式
每个操作 222 输出一行(非 000 即 111),表示每次操作 222 的回答。
样例
样例输入
20 10
1 1 10
2 6
2 12
1 5 12
2 6
2 15
1 6 16
1 11 17
2 12
2 6
样例输出
1
0
0
0
1
1
数据范围与提示
对于 50%50\%50% 的数据,1≤n≤103,1≤m≤1041\le n\le 10^3,1\le m\le 10^41≤n≤103,1≤m≤104;
对于 100%100\%100% 的数据,1≤n≤105,1≤m≤5×1051\le n\le 10^5,1\le m\le 5\times 10^51≤n≤105,1≤m≤5×105,保证 L≤RL\le RL≤R。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int lowbit(int x)
{
return x&(-x);
}
int c[100055];
int n;
void add(int x,int y)
{
while(x<=n)
{
c[x]+=y;
x+=lowbit(x);
}
}
int find(int x)
{
int ans=0;
while(x>0)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
int m,a[1000005];
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d",&x);
if(x==1)
{
int z;
scanf("%d%d",&y,&z);
add(y,1);
add(z+1,-1);
}
else
{
scanf("%d",&y);
printf("%d\n",find(y)%2);
}
}
return 0;
}