light oj 1080 区间更新
来源:互联网 发布:淘宝信用还款方式 编辑:程序博客网 时间:2024/05/29 00:33
Submit Status uDebug
Description
Given a binary number, we are about to do some operations on the number. Two types of operations can be here.
'I i j' which means invert the bit from i to j (inclusive)
'Q i' answer whether the ith bit is 0 or 1
The MSB (most significant bit) is the first bit (i.e. i=1). The binary number can contain leading zeroes.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case starts with a line containing a binary integer having length n (1 ≤ n ≤ 105). The next line will contain an integer q (1 ≤ q ≤ 50000) denoting the number of queries. Each query will be either in the form 'I i j' where i, j are integers and 1 ≤ i ≤ j ≤ n. Or the query will be in the form 'Q i' where i is an integer and 1 ≤ i ≤ n.
Output
For each case, print the case number in a single line. Then for each query 'Q i' you have to print 1 or 0 depending on the ith bit.
Sample Input
2
0011001100
6
I 1 10
I 2 7
Q 2
Q 1
Q 7
Q 5
1011110111
6
I 1 10
I 2 7
Q 2
Q 1
Q 7
Q 5
Sample Output
Case 1:
0
1
1
0
Case 2:
0
0
0
1
Hint
Dataset is huge, use faster i/o methods.
JANE ALAM JAN
LightOJ, Jane Alam Jan
#include <iostream>
#include <cstdio>#include <cstring>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int N = 100010;
char str[N];
int flag[N<<2], lazy[N<<2];
void update(int L,int R,int l,int r,int rt);
void pushup(int rt);
int query(int p,int l,int r,int rt);
int main()
{
int t, ncase=1;
scanf("%d", &t);
while(t--)
{
memset(flag,0,sizeof(flag));
memset(lazy,0,sizeof(lazy));
scanf("%s",str);
int n=strlen(str);
int q, x, y;
char ss[10];
scanf("%d", &q);
printf("Case %d:\n",ncase++);
while(q--)
{
scanf("%s",ss);
if(ss[0]=='I')
{
scanf("%d %d", &x, &y);
update(x,y,1,n,1);
}
else
{
scanf("%d", &x);
int num=query(x,1,n,1);
if(num&1)
{
printf("%c\n",str[x-1]=='0'?'1':'0');
}
else
{
printf("%c\n",str[x-1]=='0'?'0':'1');
}
}
}
}
return 0;
}
void update(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
flag[rt]++;
lazy[rt]++;
return ;
}
pushup(rt);
int mid=(l+r)/2;
if(L<=mid)
{
update(L,R,lson);
}
if(R>mid)
{
update(L,R,rson);
}
return ;
}
void pushup(int rt)
{
if(lazy[rt])
{
flag[rt<<1]+=lazy[rt];
flag[rt<<1|1]+=lazy[rt];
lazy[rt<<1]+=lazy[rt];
lazy[rt<<1|1]+=lazy[rt];
lazy[rt]=0;
}
return ;
}
int query(int p,int l,int r,int rt)
{
if(l==r)
{
return flag[rt];
}
pushup(rt);
int mid=(l+r)/2;
if(p<=mid)
{
return query(p,lson);
}
else
{
return query(p,rson);
}
}
- light oj 1080 区间更新
- Light-oj 1080 - Binary Simulation(线段树区间更新)
- Light oj 1080 - Binary Simulation(树状数组区间更新点查询)
- Light OJ 1080 - Binary Simulation - (线段树区间更新 单点查询)
- light oj 1348 树链剖分(单点更新区间求值)
- light oj 1422,区间dp
- light oj 1422(区间dp)
- light oj 1025 区间dp
- Light OJ 1031 区间dp
- 区间DP :Light OJ 1031
- 学院OJ:1684:Light on or off __线段树 区间更新
- Light oj 1422 Halloween Costumes(区间 dp)
- Light OJ 1422 - Halloween Costumes (区间DP)
- light oj 1031 区间dp+博弈
- Light oj 1422 Halloween Costumes 区间DP
- Light OJ 1422 Halloween Costumes(区间DP)
- Light oj 1025 (区间dp)
- light oj 1033 - Generating Palindromes (区间dp)
- C++中##(两个井号)和#(一个井号)用法
- php mysql拆分表操作
- redis集群安装
- 京东m.jd站点静态页实现(首页) H5
- 日志级别的选择:Debug、Info、Warn、Error还是Fatal
- light oj 1080 区间更新
- java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'occupationalHistoryController'
- 判断点是否在多边形区域里面
- 如何理解hibernate
- java String与StringBuffer的效率分析
- 一点一点学maven(11)——Eclipse开发Maven项目提示:程序包org.junit不存在解决方案
- 数据结构实验之串二:字符串匹配
- Oracle 索引 详解
- MR程序编写