题目:http://codeforces.com/contest/390/problem/C

参考:http://codeforces.com/blog/Berezin

第一次参加比赛,卡在这道题了,一直TLE,暴力法O(n * w) 太慢。下面是参考 Tutorial 后写的。

代码:

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <sstream>
#include <iomanip>#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>using namespace std;//#define LOCALint sum[100005];
int should[100005];int main()
{
#ifdef LOCALfreopen("data.txt", "r", stdin);
#endifint n, k, w;cin >> n >> k >> w;getchar();memset(sum, 0, sizeof(sum));memset(should, 0, sizeof(should));should[0] = 0;sum[0] = 0;char c;for (int i = 1; i < k; i++) {scanf("%c", &c);should[i] = c - '0';sum[i] = sum[i-1] + c - '0';}for (int i = k; i <= n; i++) {scanf("%c", &c);should[i] = should[i - k] + c - '0';sum[i] = sum[i-1] + c - '0';}for (int i = 0; i < w; i++) {int l, r;scanf("%d %d", &l, &r);int res = (sum[r] - sum[l-1]) - (should[r] - should[l-1]) + (r - l + 1) / k - (should[r] - should[l-1]);printf("%d\n", res);}return 0;
}

Codeforces #229 D2C:Inna and Candy Boxes相关推荐

  1. cf C. Inna and Candy Boxes

    题意:给你一个长度为n的只含有1和0的字符串,w个询问,每次询问输入l,r:在[l,r]中在l+k-1.l+2*k-1.......r的位置都必须为1,如果不为1的,变成1,记为一次操作,其它的地方的 ...

  2. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  3. 信息学奥赛一本通 1380:分糖果(candy)

    [题目链接] ybt 1380:分糖果(candy) 可以认为小朋友间关系的最大数量为 1 0 5 10^5 105 [题目考点] 1. 图论:广搜 2. 图论:最短路径 [解题思路] 每个小朋友是一 ...

  4. Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或)

    Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或) 题意: 3种操作: 1 插入一个数 2 删除一个数 3 给出一个数 ...

  5. CodeForces 14E Camels :利用1-4拼成长为n的序列,使准确含有t个峰t-1个谷,求方案数 :dp...

    3 ≤ n ≤ 20, 1 ≤ t ≤ 10 如此小的数据接下来就能各种暴力了=== dp[i][j][k][t1][t2]表示前i个字符的最后两个是j和k已有t1个峰t2个谷 枚举当前放的数,转移方 ...

  6. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) 思维 + 质因子

    传送门 文章目录 题意: 思路: 题意: 大体题意跟easyeasyeasy版本差不多,就是hardhardhard版本的aaa范围更大.见这里Codeforces Round #601 (Div. ...

  7. Codeforces Gym 101142C:CodeCoder vs TopForces(搜索)

    http://codeforces.com/gym/101142/attachments 题意:每个人在TC和CF上分别有两个排名,如果有一个人在任意一个网站上大于另一个人的排名,那么这个人可以打败另 ...

  8. Codeforces Round 722C:Destroying Array(离线)

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. CodeForces刷题:Theatre Square、Watermelon、Chat Server‘s Outgoing Traffic、Triangle、Die Roll

    记录Codeforces刷题QAQ 一.Theatre Square 题面翻译 用 $ a \times a$ 的石板覆盖 $n \times m $ 的长方形广场,允许石板覆盖的区域超出广场,不允许 ...

最新文章

  1. 如何动态修改windows下的host文件
  2. Django之BBS博客项目
  3. 200多位阿里工程师齐聚“光明顶”,双11模拟演习怎么搞?
  4. flutter能开发游戏吗_游戏开发者都擅长“打自己的游戏”吗?
  5. 小米路由器4Q的设置
  6. swift面向对象之方法
  7. qt输出中文乱码处理(解决方法)
  8. Win10窗口拖动时自动最大化的问题,屏幕显示绿框,中间显示1
  9. delphi mysql 连接_Delphi 使用之连接数据库
  10. Ti_ccs_2.0
  11. 手机熊猫直播怎么投屏
  12. 剑指offer系列——剑指 Offer 55 - I. 二叉树的深度
  13. 2007年9月运势之水瓶座
  14. reviewer中文_中文审稿意见怎么写
  15. LeetCode算法题解 38-报数
  16. char *const 和 const char *(char const*)
  17. java-php-python-科技专业师生沟通平台计算机毕业设计
  18. docker运行centos镜像 安装python3.9环境
  19. 理解windows消息通告消息和命令消息!!!
  20. git status怎么操作_git操作-方向对了,就不怕路远了!-51CTO博客

热门文章

  1. WWDC20 Session 清单(06-23)
  2. 设计一个有利于A股东的配股方案
  3. 软件对硬盘性能测试,新买的固态硬盘 有哪些软件可以测试性能?
  4. RK3568平台开发系列讲解(USB篇)libusb流程简介
  5. 基于matlab的有噪声语音信号处理,基于matlab的有噪声语音信号处理毕设
  6. Winform像菜单一样弹出自定义内容实现示例
  7. 笔趣阁小说-圣墟-爬虫源代码
  8. 深入浅出工控机加固的那点事
  9. 文件传输 SSHSecureShellClient-3.2.9 |CSDN创作打卡
  10. html在线印章,纯前端Html+JavaScript+canvas生成公章