CodeForces 616D Longest k-Good Segment
用队列维护一下即可
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std; const int maxn=+;
int n,k;
int a[maxn];
int tot[+];
struct Node
{
int id;
int val;
} node[maxn];
queue<Node>Q; int main()
{
scanf("%d%d",&n,&k);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
node[i].id=i;
node[i].val=a[i];
} memset(tot,,sizeof tot);
int ans=,ansl,ansr;
int now=; for(int i=; i<=n; i++)
{
Q.push(node[i]);
if(tot[node[i].val]==) now++;
tot[node[i].val]++;
if(now<=k)
{
Node head=Q.front();
if(node[i].id-head.id+>ans)
{
ans=node[i].id-head.id+;
ansl=head.id;
ansr=node[i].id;
}
}
else if(now>k)
{
while()
{
Node head=Q.front();
if(tot[head.val]==) now--;
tot[head.val]--;
Q.pop();
if(now==k) break;
} Node head=Q.front();
if(node[i].id-head.id+>ans)
{
ans=node[i].id-head.id+;
ansl=head.id;
ansr=node[i].id;
}
}
}
printf("%d %d\n",ansl,ansr);
return ;
}
CodeForces 616D Longest k-Good Segment的更多相关文章
- 【CodeForces 616D】Longest k-Good Segment
题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- codeforces gym 100971 K Palindromization 思路
题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...
- Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- codeforces 1269 E K Integers
E. K Integers 题目连接:https://codeforces.com/contest/1269/problem/E 题意 给了一个排列p,你每次操作可以交换两个相邻的元素,现在问你最少操 ...
- Codeforces 700D - Huffman Coding on Segment(莫队+根分)
Codeforces 题目传送门 & 洛谷题目传送门 好家伙,刚拿到此题时我连啥是 huffman 编码都不知道 一种对 \(k\) 个字符进行的 huffman 编码的方案可以看作一个由 \ ...
- Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面
K - Cross SpiderTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...
- Codeforces 242E:XOR on Segment(位上的线段树)
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...
- 【codeforces 242E】XOR on Segment
[原题题面]传送门 [题面翻译]传送门 [解题思路] 操作涉及到区间求和和区间异或,考虑到异或操作,我们对每个数二进制分解. 把每一位单独提出来做,异或要么取反要么变为不变,对于每一位建一颗线段树,那 ...
随机推荐
- MySQL数据表中内容大小写区分的设置
MYSQL在默认的情况下查询是不区分大小写的,例如: ? 1 2 3 4 5 6 7 mysql> create table t1( -> name varchar(10)); Qu ...
- Vim常用命令【转载】
下面基本是vim的基本用法,刚开始学习可能有些不习惯.但贵在坚持,即使不习惯,也要坚持使用,做到不经过思考就能操作,你会发现真的很方便.很多操作可以通过不同的命令达到,我这里只列出常用的. 基础命令 ...
- 如何清除jboss缓存
要清除Jboss下的缓存,只要清除以下文件的所有文件就可以了:1.D:\JavaServer\jboss-4.2.2.GA\server\default\tmp2.D:\JavaServer\jbos ...
- MD5 32位加密算法源码(测试通过)(系转载 飞扬天下)
供自己学习使用 md5.h文件 #ifndef MD5_H #define MD5_H #include <string> #include <fstream> /* Type ...
- 一个经典的PHP验证码类分享
我们通过PHP的GD库图像处理内容,设计一个验证码类Vcode.将该类声明在文件vcode.class.php中,并通过面向对象的特性将一些实现 的细节封装在该类中.只要在创建对象时,为构造方法提供三 ...
- tab奇偶行颜色交替+插件
(function($){ $.fn.tableUI=function(options){ var defaults={ evenRowclass:"evenRow", oddro ...
- boost库之graph入门
#include <boost/graph/undirected_graph.hpp> #include <boost/graph/adjacency_list.hpp> us ...
- Android实现GIF图片解码与播放
Android实现GIF图片解码与播放 如何在Android中播放GIF图片呢?如果直接按以前的方法,分解图片,可能相对比较麻烦. 今天给大伙介绍一种新的方式,构造自己的Android图片解码帮助类, ...
- java 文件字符输入、输出流
Example10_6.java import java.io.*; public class Example10_6 { public static void main(String args[]) ...
- UVALive 7299 Boggle(深搜的姿势)
一开始确实是我的锅,我把题意理解错了,以为是一个q周围没有q的时候才可以当时qu,其实是只要碰到q,他就是qu,所以我们也可以通过预处理的方式,把字典中的不满足qu连在一起的直接去掉. 后来的各种TI ...