LOJ10042
这题瞎搞一大堆。。
讲正解:
假如
Ai<=N
A
i
<=
N
两个指针
L,R
L
,
R
维护当前区间
每次
L++
L
+
+
,相应得尽量推
R
R
指针,更新答案就好了
然后辣么大,怎么办?数字哈希?
——非常有毒,撞车概率极高
sort离散一下,根据大小关系给个所谓的hash值就好了
#include<bits/stdc++.h>
#define gt() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
#define __R register
using namespace std;
static char buf[1000000],*p1=buf,*p2=buf;
const int maxn=(1e6)+5;
int n,num[maxn],Ans;bool vis[maxn];
struct ff{
int x,id;
inline bool operator <(const ff b)const{return x<b.x;}
}a[maxn];
int read(){
int ret=0;char ch=gt();
while(ch<'0'||ch>'9') ch=gt();
while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=gt();
return ret;
}
int main(){
n=read();
for(__R int i=1;i<=n;i++) a[i]=(ff){read(),i};sort(a+1,a+1+n);
for(__R int i=1,j,tot=0;i<=n;i=j){
j=i,++tot;
while(j<=n&&a[j].x==a[i].x) num[a[j++].id]=tot;
}
int L=0,R=0;
while(L<=R){
vis[num[L++]]=0;
while(R<n&&!vis[num[R+1]]) vis[num[++R]]=1;
if(R-L+1>Ans) Ans=R-L+1;
if(n-L<=Ans) break;
}
printf("%d\n",Ans);
return 0;
}