博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
×_7_12_2013 I: Light on or off
阅读量:7042 次
发布时间:2019-06-28

本文共 2217 字,大约阅读时间需要 7 分钟。

hot3.png

Problem I: Light on or off

Time Limit: 1 Sec  
Memory Limit: 128 MB
Submit: 11  
Solved: 1
[ ][ ][ ]

Description

There is N lights on the wall of Dreamone’s house from left to right.Initially,some lights on and some lights 
off, and we use ‘1’ represented the light on, use ‘0’ represented the light off. As we know, there is a cat in 
dremone’s house, and she is very naught. She always change the status continuously from Ath light to Bth 
one. (1<=A, B<=N).If the light is on, then the light will be off, If the light is off, then the light will be on. 
Actually, she can do it K times like this. Then the cat puts forward another problem: How many lights on 
from Cth light to Dth (1<=C, D<=N) one? For example: 
When N=4 K=2, and the initial status is assumed as: 
1 0 1 1 
‘1’ represented on,’0’ represented off. 
From the initial status we can get: There is 3 lights on from 1st light to 4th, 2 lights on from 2nd to 4th and so 
on. Then we assume the first operation that we change the status from 2nd to 4th, and then the status will be: 
1 1 0 0 
Then there are 2 lights on from 1st light to 4th one, 1 light on from 2nd to 4th one and so on. Then the second 
operation is assumed as from the 1st to 2nd .Then the status will be 0 0 0 0. And there will be no lights on. 
Can you get the main idea? Can you help the naught cat? 

Input

The first line of input will be a positive integer indicating how many test cases will be included (T) and T 
will be less than 10. Each of the next T cases will contain two parts: 
The first part: two integer N, K (1<=N<=100000, 1<=K<=100000) 
The second part: N numbers (which is ‘0’ or ‘1’) represented the initial status from left to right. 
Then third part: K lines. Each line will be X C D (1<=C, D<=N) X is a letter which is either ‘Q’ or ‘C’. If 
X=’Q’, you will be output the numbers of lights on from Cth to Dth, and if X=’C’, you will be change the 
status of lights as the rules described above. 

Output

For each query,(when X=’Q’),you should output the numbers of lights on. What’s more, you must output a 
blank line after you have processed a test case

Sample Input

2

 4 3 

 1 0 1 1

 Q 2 4 

 C 2 3 

 Q 1 4 

 4 1

 1 0 1 1

 Q 2 4

Sample Output

 3

 2

转载于:https://my.oschina.net/dianpaopao/blog/145709

你可能感兴趣的文章
《C语言及程序设计》实践项目——用break和continue改变流程
查看>>
The total number of locks exceeds the lock table size错误(已纠正)
查看>>
maven2完全使用手册
查看>>
SQL应用与开发:(一)导论和环境
查看>>
简单封装quartz实现任务调度的配置和管理
查看>>
Android Matrix详解
查看>>
JVM 堆栈区域数据存放流程
查看>>
【MyBatis框架】配置文件-resultMap总结
查看>>
JSP生成验证码
查看>>
浏览器的窗口位置和大小
查看>>
Path实现常见toolbar点击弹出菜单效果
查看>>
介绍Spring Cloud微服务架构的核心特性
查看>>
剥开比原看代码(六):比原是如何把请求区块数据的信息发出去的
查看>>
小猿圈linux之linux基础命令大全(一)
查看>>
当经历所有大厂的实习面试过后
查看>>
从BEC“代币蒸发”事件看智能合约编写注意事项
查看>>
CentOS 7 Minimal 安装 LXQT
查看>>
机器码 指令 汇编语言 的关系
查看>>
摸索 JS 内深拷贝的最佳实践
查看>>
设计师面试会遇到的问题(part1:HR篇)
查看>>