Codeforces Round #229 (Div. 2) C
1 second
256 megabytes
standard input
standard output
Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right.
As the boxes are closed, Inna doesn't know which boxes contain candies and which boxes contain nothing. Inna chose number k and asked w questions to Dima to find that out. Each question is characterised by two integers li, ri (1 ≤ li ≤ ri ≤ n; r - l + 1 is divisible byk), the i-th question is: "Dima, is that true that among the boxes with numbers from li to ri, inclusive, the candies lie only in boxes with numbers li + k - 1, li + 2k - 1, li + 3k - 1, ..., ri?"
Dima hates to say "no" to Inna. That's why he wonders, what number of actions he will have to make for each question to make the answer to the question positive. In one action, Dima can either secretly take the candy from any box or put a candy to any box (Dima has infinitely many candies). Help Dima count the number of actions for each Inna's question.
Please note that Dima doesn't change the array during Inna's questions. That's why when you calculate the number of operations for the current question, please assume that the sequence of boxes didn't change.
The first line of the input contains three integers n, k and w (1 ≤ k ≤ min(n, 10), 1 ≤ n, w ≤ 105). The second line contains ncharacters. If the i-th box contains a candy, the i-th character of the line equals 1, otherwise it equals 0.
Each of the following w lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the description of the i-th question. It is guaranteed thatri - li + 1 is divisible by k.
For each question, print a single number on a single line — the minimum number of operations Dima needs to make the answer to the question positive.
10 3 3
1010100011
1 3
1 6
4 9
1
3
2
For the first question, you need to take a candy from the first box to make the answer positive. So the answer is 1.
For the second question, you need to take a candy from the first box, take a candy from the fifth box and put a candy to the sixth box. The answer is 3.
For the third question, you need to take a candy from the fifth box and put it to the sixth box. The answer is 2.
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <set>
using namespace std;
typedef long long LL ; int dp[][] ;
int main(){
int i , j , x ,n , k , w , L ,R ,sum;
string s ;
for(i = ; i < ; i++)
dp[][i] = ;
cin>>n>>k>>w ;
cin>>s ;
for(i = ; i <= n ; i++){
for(j = ; j < k ; j++)
dp[i][j] = dp[i-][j] ;
dp[i][i%k] += s[i-] == '' ;
}
while(w--){
cin>>L>>R ;
sum = ;
x = R % k ;
for(i = ; i < k ; i++){
if(i == x)
sum += (R-L+)/k - (dp[R][i] - dp[L-][i]) ;
else
sum += dp[R][i] - dp[L-][i] ;
}
cout<<sum<<endl ;
}
return ;
}
Codeforces Round #229 (Div. 2) C的更多相关文章
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- Codeforces Round #229 (Div. 2) D
D. Inna and Sweet Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- Quartus ii 12.0 和ModelSim 10.1 SE安装及连接
quartus ii 10.0后就没有自带的仿真软件,每次写完一个VerilogHDL都想简单仿真一下,结果发现没有了自带仿真软件.这时候就需要第三方仿真软件ModelSim 10.1 SE. Qua ...
- Swift的文档注释
官方文档地址:https://developer.apple.com/library/mac/documentation/Xcode/Reference/xcode_markup_formatting ...
- javascript的异步编程方法
一,callback 回调函数 即函数f1和函数f2的关系是f1(f2()); f2作为f1()的回调函数,在f1执行过程中就开始执行f2,先执行线程的主要逻辑,将比较耗时的任务放在后面执行. 回调函 ...
- HttpContext.Cache 详解
提到HttpContext.Cache必然会想到Application,他们有什么共性和不同点呢,我们一一道来 相同点: 1.两者都是使用键值对来存储对象 2.两者都是应用程序同生命周期(在cache ...
- swift objective-及c语言 混编
在xocde6出来我们大部分代码都是用objective-c写的(部分C/C++),现在出生来了一个新的语言叫swift,那么如何既能使用我们之前的代码,还可以使用新语言呢, 本文就此做一下说明. 关 ...
- Linux type命令
用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下几种: alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命 ...
- php 判断复选框checkbox是否被选中
php 判断复选框checkbox是否被选中 复选框checkbox在php表单提交中经常被使用到,本文章通过实例向大家介绍php如何判断复选框checkbox中的值是否被选中,需要的朋友可以参考 ...
- Structs2中iterator的status属性的用法
iterator标签主要是用于迭代输出集合元素,如list set map 数组等,在使用<s:iterator/>标签的时候有三个属性值得我们关注 1. value属性:可选的属性,va ...
- 公测后,微信小程序应用可能被拒原因.
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 34.0px "PingFang SC Semibold"; color: #23232 ...
- tensorflow3
参考文献:tensorflow_manual_cn.pdf 一.tensorflow和caffe对应: graph-->.prototxt定义的网络结构 session-->solver( ...