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. mysql-日期时间函数大全

    DAYOFWEEK(date)  返回日期date是星期几(1=星期天,2=星期一,--7=星期六,ODBC标准)mysql> select DAYOFWEEK('1998-02-03');  ...

  2. android studio Please configure Android SDK / please select Android SDK

    有可能是sdk文件损坏造成的. file->settings->appearance&behavior->system settings->android sdk-&g ...

  3. Flume对接Kafka

    目录 一.简单实现 1)flume的配置文件 二.自定义interceptor(使用kafka sink) 1)自定义 flume 拦截器 2)编写 flume 的配置文件 3)创建topic 4)启 ...

  4. vue开发多页面应用 - hash模式和history模式

    我们知道vue可以快速开发web单页应用,而且官方为我们提供了自己的应用脚手架vue-cli,我们只需要下载脚手架,安装依赖后就可以启动vue应用雏形. 这得益与webpack的依赖追踪,各种资源后缀 ...

  5. Oracle——生成Awr报告

    Oracle--生成Awr报告 AWR的概念 Oracle数据库是一个使用量很多的数据库,关于Oracle数据库的性能.Oracle10g以后,Oracle提供了一个性能检测的工具:AWR(Autom ...

  6. When should we write our own assignment operator in C++?

    The answer is same as Copy Constructor. If a class doesn't contain pointers, then there is no need t ...

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

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

  8. hadoop Sort排序

    1 public int getPartition(IntWritable key,IntWritable value,int numPartitions){ 2 int Maxnumber = 12 ...

  9. redis入门到精通系列(六):redis的事务详解

    (一)事务的概念 谈到数据库的高级应用,不可避免会谈到事务.熟悉mysql的朋友们对事务肯定不陌生,简单来讲事务就是控制一个数据库操作序列要么全部执行要么全部不执行.今天我们就来了解redis中的事务 ...

  10. 【Java 基础】Arrays.asList、ArrayList的subList注意事项

    1. 使用Arrays.asList的注意事项 1.1 可能会踩的坑 先来看下Arrays.asList的使用: List<Integer> statusList = Arrays.asL ...