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.
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的更多相关文章
- Light OJ 1080 - Binary Simulation
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1080 1080 - Binary Simulation PDF (Englis ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0
深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...
- 【转】What's the difference between simulation and emulation
摘要:这2个单词 还是用英文解释,比较准确.按我的理解:simulation就是模拟,可以做些改变. emulation是仿真,是按照原来的样子进行部署,不可以改变. Yes, the concept ...
- ROS_Kinetic_29 kamtoa simulation学习与示例分析(一)
致谢源代码网址:https://github.com/Tutorgaming/kamtoa-simulation kamtoa simulation学习与示例分析(一) 源码学习与分析是学习ROS,包 ...
- 深度学习主机环境配置: Ubuntu16.04+GeForce GTX 1080+TensorFlow
接上文<深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0>,我们继续来安装 TensorFlow,使其支持GeForce GTX 1080显卡 ...
- 基于Ubuntu16.04的GeForce GTX 1080驱动安装,遇到的问题及对应的解决方法
1.在主机上插上GPU之后,查看设备: $ nvidia-smi Tue Dec :: +------------------------------------------------------- ...
- 算法学习笔记之——priority queue、heapsort、symbol table、binary search trees
Priority Queue 类似一个Queue,但是按照priority的大小顺序来出队 一般存在两种方式来实施 排序法(ordered),在元素入队时即进行排序,这样插入操作为O(N),但出队为O ...
- Leetcode之深度优先搜索(DFS)专题-1080. 根到叶路径上的不足节点(Insufficient Nodes in Root to Leaf Paths)
Leetcode之深度优先搜索(DFS)专题-1080. 根到叶路径上的不足节点(Insufficient Nodes in Root to Leaf Paths) 这篇是DFS专题的第一篇,所以我会 ...
随机推荐
- oracle 将电话号码中间4位数以星号*代替
select replace('17665312355',substr('17665312355',4,4),'****') as phone, #类似E ...
- STM32 BootLoader升级固件
一.知识点 1.BootLoader就是单片机启动时候运行的一段小程序,这段程序负责单片机固件的更新,也就是单片机选择性的自己给自己下程序.可以更新,也可以不更新,更新的话,BootLoader更新完 ...
- linux 常用查看命令
linux 常用查看命令 目录 linux 常用查看命令 linux 查看内存/进程-ps/top linux 查看磁盘存储-df linux 查看io读写-iotop linux 查看端口占用-ne ...
- Vue2全家桶+Element搭建的PC端在线音乐网站
目录 1,前言 2,已有功能 3,使用 4,目录结构 5,页面效果 登录页 首页 排行榜 歌单列表 歌单详情 歌手列表 歌手详情 MV列表 MV详情 搜索页 播放器 1,前言 项目基于Vue2全家桶及 ...
- 大规模 K8s 集群管理经验分享 · 上篇
11 月 23 日,Erda 与 OSCHINA 社区联手发起了[高手问答第 271 期 -- 聊聊大规模 K8s 集群管理],目前问答活动已持续一周,由 Erda SRE 团队负责人骆冰利为大家解答 ...
- account, accomplish, accumulate
account account从词源和count(数数)有关,和computer也有点关系.calculate则和'stone used in counting'有关.先看两个汉语的例子:1. 回头再 ...
- acquaint
Interpersonal relationships are dynamic systems that change continuously during their existence. Lik ...
- windows磁盘扩容
要邻近的磁盘,才可以扩展.所以必须要先删除恢复分区. 删除恢复分区,参考如下: https://jingyan.baidu.com/article/574c5219598d5e6c8c9dc15e.h ...
- STM32一些特殊引脚做IO使用的注意事项
1 PC13.PC14.PC15的使用 这三个引脚与RTC复用,<STM32参考手册>中这样描述: PC13 PC14 PC15需要将VBAT与VDD连接,实测采用以下程序驱动4个74HC ...
- ORACLE中dual用法详解
基本上oracle引入dual为的就是符合语法1. 我们先从名称来说,dual不是缩写词,本身就是完整的单词.dual名词意思是对数,做形容词时是指二重的,二元的.2. Oracle中的dual表是一 ...