cf-edu#5-D - Longest k-Good Segment-map+贪心维护
来源:互联网 发布:第三波软件 编辑:程序博客网 时间:2024/06/02 05:41
http://codeforces.com/contest/616/problem/D
直接扫一遍
当kind超过m则去掉最前面的元素,并且更新map,
否则map[元素]++
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <vector>#include <iostream>using namespace std; int n,m;int tm[5*100000+8] ; map<int,int> sb;int main(){ cin>>n>>m; int i,j; for (i=1;i<=n;i++) { scanf("%d",&tm[i]); } int max_long=0; int size=0; int st=1; int max_st; for (i=1;i<=n;i++) { if (sb.find(tm[i])==sb.end()) { while(size==m) { if (sb[tm[st]]>0) sb[tm[st]]--; if (sb[tm[st]]==0) sb.erase(tm[st]); size=sb.size(); st++; } size++; if (i-st+1>max_long) { max_long=i-st+1; max_st=st; } sb[tm[i]]++; } else { sb[tm[i]]++; if (i-st+1>max_long) { max_long=i-st+1; max_st=st; } } } printf("%d %d\n",max_st,max_st+max_long-1); return 0; }
0 0
- cf-edu#5-D - Longest k-Good Segment-map+贪心维护
- Educational Codeforces Round 5 D Longest k-Good Segment 贪心
- D. Longest k-Good Segment
- Longest k-Good Segment codeforces 616D map 简单应用
- Educational Codeforces Round 5 D. Longest k-Good Segment
- Educational Codeforces Round 5 (D. Longest k-Good Segment)
- Educational Codeforces Round 5 D. Longest k-Good Segment
- Educational Codeforces Round 5 D. Longest k-Good Segment
- codeforces 616D Longest k-Good Segment
- codeforces 616D Longest k-Good Segment
- Codeforces 616 D. Longest k-Good Segment
- codeforces 616D Longest k-Good Segment
- CodeForces 616D Longest k-Good Segment
- codeforces Longest k-Good Segment 616D
- CodeForces 616D Longest k-Good Segment
- Codeforces 616D Longest k-Good Segment
- codeforces 616D Longest k-Good Segment
- Longest k-Good Segment
- QTGraphicsViewFramework学习
- cf-edu#5-C The Labyrinth-dfs记忆化搜搜
- 深入了解JAVA可变长度的参数(Varargs)
- Android中 Window 、WindowManager、WindowManager.LayoutParams 相关内容
- Cocos2dX笔记1——生成Docs
- cf-edu#5-D - Longest k-Good Segment-map+贪心维护
- 为PopupWindow设置动画效果
- Magento SQL导出客户购物车产品信息(客户email,产品ID,产品名称,产品描述,产品价格,产品图片)
- 跟我学习dubbo-构建Dubbo服务消费者Web应用的war包并在Tomcat中部署(6)
- 跟我学习dubbo-Dubbo监控中心的介绍与简易监控中心的安装(7)
- laravel 修改migration属性
- 反编译apk
- jeesite框架搭建 (mysql数据库)
- zend中function的声明