1080 - Binary Simulation
Time Limit: 2 second(s) Memory Limit: 64 MB

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

Output for 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

Case 1:

0

1

1

0

Case 2:

0

0

0

1

Note

Dataset is huge, use faster i/o methods.


PROBLEM SETTER: JANE ALAM JAN
思路:线段树;
线段树维护加反了多少次。
 1 #include<stdio.h>
2 #include<iostream>
3 #include<algorithm>
4 #include<string.h>
5 #include<queue>
6 #include<math.h>
7 using namespace std;
8 char str[100005];
9 int tree[4*100005];
10 void in(int l,int r,int k,int nn,int mm)
11 {
12 if(l>mm||r<nn)
13 {
14 return ;
15 }
16 else if(l<=nn&&r>=mm)
17 {
18 tree[k]++;
19 tree[k]%=2;
20 return ;
21 }
22 else
23 {
24 tree[2*k+1]+=tree[k];
25 tree[2*k+1]%=2;
26 tree[2*k+2]+=tree[k];
27 tree[2*k+2]%=2;
28 tree[k] = 0;
29 in(l,r,2*k+1,nn,(nn+mm)/2);
30 in(l,r,2*k+2,(nn+mm)/2+1,mm);
31 }
32 }
33 int ask(int l,int r,int k,int nn,int mm)
34 {
35 if(l>mm||r<nn)
36 {
37 return 0;
38 }
39 else if(l<=nn&&r>=mm)
40 {
41 return tree[k];
42 }
43 else
44 {
45 tree[2*k+1]+=tree[k];
46 tree[2*k+1]%=2;
47 tree[2*k+2]+=tree[k];
48 tree[2*k+2]%=2;
49 tree[k] = 0;
50 int nx = ask(l,r,2*k+1,nn,(nn+mm)/2);
51 int ny = ask(l,r,2*k+2,(nn+mm)/2+1,mm);
52 return (nx + ny)%2;
53 }
54 }
55 int main(void)
56 {
57 int T;
58 scanf("%d",&T);
59 int __ca = 0;
60 while(T--)
61 {
62 __ca++;
63 printf("Case %d:\n",__ca);
64 memset(tree,0,sizeof(tree));
65 scanf("%s",str);
66 int n;int l = strlen(str);
67 scanf("%d ",&n);
68 while(n--)
69 {
70 char a[10];
71 int x,y;
72 scanf("%s",a);
73 if(a[0] == 'I')
74 {scanf("%d %d",&x,&y);
75 in(x-1,y-1,0,0,l-1);
76 }
77 else
78 {
79 int x;
80 scanf("%d",&x);
81 int ny = ask(x-1,x-1,0,0,l-1);
82 printf("%d\n",(str[x-1]-'0'+ny)%2);
83 }
84 }
85 }return 0;
86 }

1080 - Binary Simulation的更多相关文章

  1. Light OJ 1080 - Binary Simulation

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1080 1080 - Binary Simulation PDF (Englis ...

  2. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  3. (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0

      深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...

  4. 【转】What's the difference between simulation and emulation

    摘要:这2个单词 还是用英文解释,比较准确.按我的理解:simulation就是模拟,可以做些改变. emulation是仿真,是按照原来的样子进行部署,不可以改变. Yes, the concept ...

  5. ROS_Kinetic_29 kamtoa simulation学习与示例分析(一)

    致谢源代码网址:https://github.com/Tutorgaming/kamtoa-simulation kamtoa simulation学习与示例分析(一) 源码学习与分析是学习ROS,包 ...

  6. 深度学习主机环境配置: Ubuntu16.04+GeForce GTX 1080+TensorFlow

    接上文<深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0>,我们继续来安装 TensorFlow,使其支持GeForce GTX 1080显卡 ...

  7. 基于Ubuntu16.04的GeForce GTX 1080驱动安装,遇到的问题及对应的解决方法

    1.在主机上插上GPU之后,查看设备: $ nvidia-smi Tue Dec :: +------------------------------------------------------- ...

  8. 算法学习笔记之——priority queue、heapsort、symbol table、binary search trees

    Priority Queue 类似一个Queue,但是按照priority的大小顺序来出队 一般存在两种方式来实施 排序法(ordered),在元素入队时即进行排序,这样插入操作为O(N),但出队为O ...

  9. Leetcode之深度优先搜索(DFS)专题-1080. 根到叶路径上的不足节点(Insufficient Nodes in Root to Leaf Paths)

    Leetcode之深度优先搜索(DFS)专题-1080. 根到叶路径上的不足节点(Insufficient Nodes in Root to Leaf Paths) 这篇是DFS专题的第一篇,所以我会 ...

随机推荐

  1. git的使用理解(分支合并的使用理解,多人编程的解决方案)

    本文主要记录了对git日常使用的一些理解,主要是对git分支的一些感悟. git强大的版本控制系统,之前也使用过SVN,感觉上git对于多人开发的版本控制更加强大,特别是最近对git分支的使用,更是深 ...

  2. Java 读取txt文件生成Word文档

    本文将以Java程序代码为例介绍如何读取txt文件中的内容,生成Word文档.在编辑代码前,可参考如下代码环境进行配置: IntelliJ IDEA Free Spire.Doc for Java T ...

  3. javaSE高级篇5 — java8新特性详解———更新完毕

    java8新特性 在前面已经见过一些东西了,但是:挖得有坑儿 1.lambda表达式 lambda表达式是jdk1.8引入的全新语法特性 它支持的是:只有单个抽象方法的函数式接口.什么意思? 就是说: ...

  4. Vue相关,Vue生命周期及对应的行为

    先来一张经典图 生命钩子函数 使用vue的朋友们知道,生命周期函数长这样- mounted: function() { } // 或者 mounted() { } 注意点,Vue的所有生命周期函数都是 ...

  5. vi查找替换命令详解 (转载)

    转载至:   http://blog.csdn.net/lanxinju/article/details/5731843 一.查找 查找命令 /pattern<Enter> :向下查找pa ...

  6. proxysql+MHA+半同步复制

    先配置成主从同步 先在各节点安装服务 [root@inotify ~]# yum install mariadb-server -y 编辑主节点的配置文件,并启动 [root@centos7 ~]# ...

  7. spring-cloud-alibaba-dependencies版本问题

    org.springframework.cloud的spring-cloud-alibaba-dependencies管理的nacos最新版本是0.9.0.RELEASE,已经不再维护了,用起来有版本 ...

  8. 那些年采的python的坑

    1:使用virtualenvwrapper 新建虚拟环境时出现的错误 OSError: Command D:\file\python\virtu...r\Scripts\python.exe - se ...

  9. 【力扣】454. 四数相加 II

    给定四个包含整数的数组列表 A , B , C , D ,计算有多少个元组 (i, j, k, l) ,使得 A[i] + B[j] + C[k] + D[l] = 0. 为了使问题简单化,所有的 A ...

  10. 为什么Redis集群有16384个槽

    一.前言 我在<那些年用过的Redis集群架构(含面试解析)>一文里提到过,现在redis集群架构,redis cluster用的会比较多. 如下图所示 对于客户端请求的key,根据公式H ...