Codeforces 660 C. Hard Process (尺取)

时间:2022-09-03 22:21:55

题目链接:http://codeforces.com/problemset/problem/660/C

尺取法

 #include <bits/stdc++.h>
using namespace std;
int main()
{
static int num[int(3e5 + )];
int n, k;
scanf("%d %d", &n, &k);
for(int i = ; i <= n; ++i) {
scanf("%d", num + i);
}
int l = , res = , cnt = , flagl = , flagr = -;
for(int i = ; i <= n; ++i) {
if(num[i]) {
if(i - l + > res) {
res = i - l + , flagl = l, flagr = i;
}
} else {
cnt++;
while(cnt > k && l <= i) {
if(!num[l++])
--cnt;
}
if(i - l + > res) {
res = i - l + , flagl = l, flagr = i;
}
}
}
for(int i = flagl; i <= flagr; ++i)
num[i] |= ;
printf("%d\n", res);
for(int i = ; i <= n; ++i) {
printf("%d%c", num[i], i == n ? '\n': ' ');
}
return ;
}

Codeforces 660 C. Hard Process (尺取)的更多相关文章

  1. Codeforces Round &num;116 &lpar;Div&period; 2&comma; ACM-ICPC Rules&rpar; E&period; Cubes &lpar;尺取&rpar;

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  2. Educational Codeforces Round 53 &lpar;Rated for Div&period; 2&rpar; C&period; Vasya and Robot 【二分 &plus; 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  3. 【尺取或dp】codeforces C&period; An impassioned circulation of affection

    http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...

  4. Codeforces 939E Maximize&excl; &lpar;三分 &vert;&vert; 尺取&rpar;

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

  5. B&period; Complete the Word(Codeforces Round &num;372 &lpar;Div&period; 2&rpar;) 尺取大法

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Educational Codeforces Round 53 &lpar;Rated for Div&period; 2&rpar; C&period; Vasya and Robot(二分或者尺取)

    题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...

  7. Codeforces Round &num;321 &lpar;Div&period; 2&rpar; B&period; Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  8. Codeforces - 6E - Exposition - 尺取

    https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...

  9. Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取

    https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...

随机推荐

  1. java基础-基本数据类型

    浏览以下内容前,请点击并阅读 声明 java有八种基本数据类型,其中包括: byte,字节型,是8位带符号的整数,即其范围在-128和127之间(包括) short,短整型,是16位带符号的整数,范围 ...

  2. redis-persist上线

    九月份惨不忍睹,因为代码质量不够高,直接被Boss喷成了筛子.被反复教育说要高质量的代码,要可维护.高性能…… 幸而,最后一周终于在紧张的加班中,灰度上线redis-land-go了,项目也改名为re ...

  3. hadoop学习之一

         Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Hadoop的框架最核心的设计 ...

  4. Ecshop、Discuz&excl; 等开源产品的局限

    Ecshop.Discuz! 等开源产品的局限 记得今年年初,我初次接触Discuz!和Ecshop时,一阵阵地惊叹:成熟度这么高的产品,居然是免费的.我们这些搞传统软件开发的要怎么活?另外也奇怪,做 ...

  5. Calculating a bearing between points in location-aware apps

    https://software.intel.com/en-us/blogs/2012/11/30/calculating-a-bearing-between-points-in-location-a ...

  6. 以a为变量名,给出下列描述的定义

    a)一个整型数(An integer) b) 一个指向整型数的指针(A pointer to an integer) c) 一个指向指针的的指针,它指向的指针是指向一个整型数(A pointer to ...

  7. 14&period;4&period;2 Configuring InnoDB for Read-Only Operation 配置InnoDB 永于只读操作&colon;

    14.4.2 Configuring InnoDB for Read-Only Operation 配置InnoDB 永于只读操作: 你可以查询InnoDB 表 MySQL 数据目录是在只读介质里,通 ...

  8. Linq to SQL -- Group By、Having和Exists、In、Any、All、Contains

    Group By/Having操作符 适用场景:分组数据,为我们查找数据缩小范围. 说明:分配并返回对传入参数进行分组操作后的可枚举对象.分组:延迟 1.简单形式: var q = from p in ...

  9. 熊猫ios手游直播教程 苹果投屏电脑

    如今手游越来越火热,不管是大人小孩都喜欢在闲暇时刻玩一玩游戏,手机屏幕终归还是有点小的,所以有的小伙伴想要将手机投屏到电脑上,岂不是一件很好的事情,iPhone是有镜像投屏功能的,下面给大家分享熊猫i ...

  10. 关于ie7下display:inline-block;不支持的解决方案。

    摘要: 声明:此文章为转载(点击查看原文),如有侵权24小时内删除.联系QQ:1522025433. 今天码的时候遇到这个问题了. 如果本身是内联元素的,把它的display属性设置设置为inline ...