Educational Codeforces Round 6 C. Pearls in a Row
来源:互联网 发布:淘宝客卖保健品 编辑:程序博客网 时间:2024/05/16 12:05
题意:
找到最大连续有重复数字的子段
#include <iostream>#include <stdio.h>#include <map>#include <cstring>#include <queue>using namespace std;const int maxn=300005;int a[maxn];int l[maxn];int r[maxn];int now[maxn];int main(){ map<int,int>mp; int n; int cnt=0; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(mp.count(a[i])==0) { mp[a[i]]=++cnt; } } int ans=0; queue<int>q; int st=1; for(int i=1;i<=n;i++) { int pos=mp[a[i]]; if(now[pos]==0) { now[pos]=i; q.push(pos); } else { l[++ans]=st; r[ans]=i; st=i+1; while(!q.empty()) { int t=q.front(); now[t]=0; q.pop(); } } } if(ans==0) { printf("-1\n"); return 0; } r[ans]=n; printf("%d\n",ans); for(int i=1;i<=ans;i++) { printf("%d %d\n",l[i],r[i]); } return 0;}
阅读全文
0 0
- cf Educational Codeforces Round 6 C Pearls in a Row
- Educational Codeforces Round 6 C. Pearls in a Row
- Educational Codeforces Round 6 C. Pearls in a Row
- Educational Codeforces Round 6 C. Pearls in a Row(贪心)
- Educational Codeforces Round 6 620C Pearls in a Row
- Educational Codeforces Round 6 C. Pearls in a Row
- Codeforces - Educational Codeforces Round 6C - Pearls in a Row(练习)
- Educational Codeforces Round 6-C. Pearls in a Row(贪心)
- Educational Codeforces Round 6 620C Pearls in a Row(stl)
- Educational Codeforces Round 6 C. Pearls in a Row (分离序列+set)
- 【Educational Codeforces Round 6C】【DP or 贪心】Pearls in a Row n个数分最多区间使得每个区间都有重复数
- Codeforces-Edu6-C.Pearls in a Row
- codeforces 620C Pearls in a Row
- Pearls in a Row CodeForces
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- C. Pearls in a Row
- JS回车事件
- stdafx.h和targetver.h的作用
- Learning Similarity Functions for Topic Detection in Online Reputation Monitoring
- 【Java学习笔记】20.Properties实现付费功能案例
- realm支持散列(MD5加密)实现认证
- Educational Codeforces Round 6 C. Pearls in a Row
- dubbo-非常详细的DUBBO配置方式详解
- Nginx proxy_set_header中$proxy_host,$host,$http_host的区别
- [Android]四子棋游戏开发源码和分析
- 视图
- linux系统设置命令别名
- (转)王国斌:价值投资的制度基础
- djang框架原理阐述
- 成绩排序(解题报告)