#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 100005;
int C[maxn];
char a[maxn];
int lowbit(int lo)
{
return lo & (-lo);
}
void modify(int pos, int value)
{
while(pos < maxn)
{
C[pos] += value;
pos += lowbit(pos);
}
}
int getsum(int pos)
{
int sum = 0;
while(pos > 0)
{
sum += C[pos];
pos -= lowbit(pos);
}
return sum;
}
int main()
{
int T, n, len, x, y;
char op[10];
scanf("%d", &T);
for(int t = 1; t <= T; t++)
{
memset(a, 0, sizeof(a));
memset(C, 0, sizeof(C));
printf("Case %d:\n",t);
scanf("%s", a);
len = strlen(a);
scanf("%d", &n);
for(int i = 0; i < len; i++)
{
if(a[i] == '1')
{
modify(i + 2, 1);
modify(i + 3, 1);
}
}
while(n--)
{
scanf("%s", &op);
if(op[0] == 'I')
{
scanf("%d%d", &x, &y);
x += 1; y += 1;
modify(x, 1);
modify(y + 1,1);
}
else
{
scanf("%d", &x);
x += 1;
int sum2 = getsum(x);
//int sum1 = getsum(x - 1); //因为这个没理解好,WA了半天!!!
printf("%d\n", (abs)(sum2) % 2 );
}
}
}
return 0;
}
LightOj1080Binary Simulation(区间更新单点查询)
最新推荐文章于 2017-08-25 19:15:43 发布