/*
STLsort离散化==T
手工sort离散化==T
map在线==T
map离线处理c==A 240ms
*/
#include<cstdio>
#include<map>
#define maxn 1000010
using namespace std;
int T,n,c[maxn],a[maxn],ans,s,t,num;
map<int,int>p;
int init(){
int x=,f=;char s=getchar();
while(s<''||s>''){if(s=='-')f=-;s=getchar();}
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x*f;
}
int main()
{
T=init();
while(T--){
n=init();s=;ans=num=;p.clear();
for(int i=;i<=n;i++){
a[i]=init();
if(p[a[i]]==){
p[a[i]]=i;c[i]=;
}
else {
c[i]=p[a[i]];p[a[i]]=i;
}
}
while(){
for(t=s;t<=n;t++){
if(c[t]>=s){
s=c[t]+;c[t]=;break;
}
ans=max(ans,t-s+);
}
if(t>=n)break;
}
printf("%d\n",ans);
}
return ;
}

UVA - 11572 Unique Snowflakes的更多相关文章

  1. (白书训练计划)UVa 11572 Unique Snowflakes(窗体滑动法)

    题目地址:UVa 11572 这样的方法曾经接触过,定义两个指针,不断从左向右滑动,推断指针内的是否符合要求. 这个题为了能高速推断是否有这个数,能够用STL中的set. 代码例如以下: #inclu ...

  2. uva 11572 unique snowflakes——yhx

    Emily the entrepreneur has a cool business idea: packaging and selling snowakes. She has devised ama ...

  3. UVa 11572 Unique snowflakes【滑动窗口】

    题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素 看的紫书,滑动窗口来做的 当右端碰到有相同的数的时候,左端向前滑动一个数 模拟一个样例好理解些 #include<iostr ...

  4. uva 11572 - Unique Snowflakes(和书略有不同)

    本书是关于使用刘汝佳set, 通过收集找到.count()和删除.erase().这种方法比我好.用较短的时间. 我想map这个任务可以完成.但是,这是不容易删除,必须先找到find()标.然后删除索 ...

  5. UVA 11572 Unique snowflakes (滑窗)

    用set,保存当前区间出现过的数字,如果下一个数字没有出现过,加入,否则删掉左端点,直到没有重复为止 #include<bits/stdc++.h> using namespace std ...

  6. UVA - 11572 Unique Snowflakes 滑动扫描

    题目:点击打开题目链接 思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除 ...

  7. UVA - 11572 Unique Snowflakes(唯一的雪花)(滑动窗口)

    题意:输入一个长度为n(n <= 10^6)的序列A,找到一个尽量长的连续子序列AL~AR,使得该序列中没有相同的元素. 分析: 法一:从r=0开始不断增加r,当a[r+1]在子序列a[l~r] ...

  8. 11572 - Unique Snowflakes(贪心,两指针滑动保存子段最大长度)

    Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...

  9. UVA 11527 Unique Snowflakes

    用STL做会很方便 SET: /*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring ...

随机推荐

  1. 【POJ11855】 Buzzwords (后缀数组)

    Description The word “the” is the most commonthree-letter word. It evenshows up inside other words, ...

  2. Spring MVC 解读——View,ViewResolver(转)

    上一篇文章(1)(2)分析了Spring是如何调用和执行控制器方法,以及处理返回结果的,现在我们就分析下Spring如何解析返回的结果生成响应的视图. 一.概念理解 View ---View接口表示一 ...

  3. android design library提供的TabLayout的用法

    在开发中,我们常常需要ViewPager结合Fragment一起使用,如下图: 我们可以使用三方开源的PagerSlidingTabStrip去实现,或者viewpagerindicator,我一般都 ...

  4. iconv

    iconv -f 源字符集 -t 目标字符集 文件名 iconv   -f UTF-8 -t GBK  success.msg [root@perass ~]# cat success.msg | t ...

  5. This configuration file was broken by system-config-keyboard

    posts • Page of problem with startx Postby evarie » // :: Normally i can get started with the x wind ...

  6. (转载)用PHP实现翻页

    (转载)http://blog.csdn.net/emili/article/details/5221744 原文参考http://www.cnblogs.com/xxcainiao/archive/ ...

  7. leetcode 最大矩形和

    1.枚举法(超时) public class Solution { public int largestRectangleArea(int[] height) { int max=-1; for(in ...

  8. Cogs 1070. [焦作一中2012] 玻璃球游戏 带权并查集,逆序处理

    题目: http://cojs.tk/cogs/problem/problem.php?pid=1070 1070. [焦作一中2012] 玻璃球游戏 ★   输入文件:marbles.in   输出 ...

  9. Shell上传文件到ftp

    写一个shell文件,将给定的文件上传到指定的ftp. 代码如下: #!/bin/bash #用来将文件上传到ftp,输入参数:文件名(包括路径).ftp的IP.ftp的端口.用户名.密码 ip=$ ...

  10. Very simple problem - SGU 111(大数开方)

    分析:使用的是构造新数字法进行不断构造,然后逼近每一位数字,然后使用c++徒手敲了240多行代码,竟然过了........................很有成就感. 代码如下: ========== ...