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. QQ空间技术架构之深刻揭秘

    QQ空间技术架构之深刻揭秘 来源: 腾讯大讲堂  发布时间: 2012-05-17 17:24  阅读: 7822 次  推荐: 4   [收藏]   QQ 空间作为腾讯海量互联网服务产品,经过近七年 ...

  2. 深入了解scanf() getchar()和gets()等函数之间的区别

    scanf(), getchar()等都是标准输入函数,一般人都会觉得这几个函数非常简单,没什么特殊的.但是有时候却就是因为使用这些函数除了问题,却找不出其中的原因.下面先看一个很简单的程序: 程序1 ...

  3. 巩固javaweb第一天

    巩固内容: 实例解析 <!DOCTYPE html> 声明为 HTML5 文档 <html> 元素是 HTML 页面的根元素 <head> 元素包含了文档的元(me ...

  4. mongDB进阶

    Mongo进阶 聚合 聚合操作将来自多个文档的值组合在一起,并且可以对分组数据执行各种操作以返回单个结果. 文档进入多阶段管道,将文档转换为聚合结果 聚合管道 例子: 第一阶段:过滤,$match 第 ...

  5. Hive(十)【窗口函数】

    目录 一.定义 窗口函数: 标准聚合函数 分析排名函数 二.语法 (1)窗口函数 over([partition by 字段] [order by 字段] [ 窗口语句]) (2)窗口语句 三.需求练 ...

  6. Git配置文件与git config命令

    在Git配置文件中配置变量,可以控制Git的外观和操作的各个方面.通过git config命令可以获得和设置配置变量. 一.Git配置文件的位置 这些变量可以被存储在三个不同的位置: 1./etc/g ...

  7. go recover让崩溃的程序继续执行

    package main import ( "fmt" "log" ) func de() { //recover() //可以打印panic的错误信息 //f ...

  8. ubuntu基础

    下载地址: http://cdimage.ubuntu.com/releases/ #:配置多网卡静态IP地址和路由 root@ubuntu:~# vim /etc/netplan/01-netcfg ...

  9. OpenStack之六: plancement服务(端口8778)

    官网地址:https://docs.openstack.org/placement/stein/install/install-rdo.html #:创建placement库,并授权 MariaDB ...

  10. class.getName()和class.getSimpleName()的区别

    根据API中的定义: Class.getName():以String的形式,返回Class对象的"实体"名称: Class.getSimpleName():获取源代码中给出的&qu ...