###### Yedl的专栏

Stay hungry, stay foolish

###### Codeforces Round #229 (Div. 2)C. Inna and Candy Boxes

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5+10;
int n, k, w;
char str[N]; //dp[i][j]表示说以i为开头，区间[i+1,j]需要几步
int dp[15][N];

int sol(int x)
{
if (k == 1)
{
if (str[x-1] == '0') return 1;
}
else
{
if (str[x-1] == '1') return 1;
}
return 0;
}

int main()
{
scanf("%d%d%d%s", &n, &k, &w,str);
int len = strlen(str);
memset(dp, 0, sizeof(dp));
for(int i = 0; i < k ; i++)
{
for(int j = i+1; j <= len ; j++)
{
dp[i][j] = dp[i][j-1];
if((j+1-i+k) % k == 0) if(str[j-1] == '0') dp[i][j]++;
if((j+1-i+k) % k != 0) if(str[j-1] == '1') dp[i][j]++;
}
}
int l , r;
while(w--)
{
scanf("%d%d", &l ,&r);
int t = l % k;
int cnt = 0;
cnt = dp[t][r] - dp[t][l] + sol(l);
printf("%d\n", cnt);
}
return 0;
}


#### codeforces Inna, Dima and Song

2015-11-11 21:14:08

#### Inna, Dima and Song

2014-02-12 20:30:53

#### Codeforces 390B Inna, Dima and Song(贪心）

2014-02-13 16:35:31

#### C. Inna and Dima 深度搜索

2014-05-05 20:22:02

#### CF 390C - Inna and Candy Boxes（分类统计）

2014-10-28 09:01:46

#### Codeforces 390C Inna and Candy Boxes(dp)

2014-02-13 18:42:08

#### CF 390C：Inna and Candy Boxes

2014-03-07 01:14:50

#### Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes

2014-02-12 14:11:00

#### 【简单题】-CF-390B-Inna, Dima and Song

2014-02-15 22:28:48

#### codeforces 390B Inna, Dima and Song

2015-11-13 17:37:48

## 不良信息举报

Codeforces Round #229 (Div. 2)C. Inna and Candy Boxes