1 条题解
-
0
C++ :
#include <cstdio> /* 元素互不相同的最长连续段。记录每个值上次出现的位置,双指针。 */ static int a[1000005]; static int last[1000005]; int main(){ int n; if(scanf("%d",&n)!=1) return 0; for(int i=0;i<n;i++) if(scanf("%d",&a[i])!=1) return 0; for(int i=0;i<=1000000;i++) last[i]=-1; int best=0, start=0; for(int j=0;j<n;j++){ if(last[a[j]] >=start) start = last[a[j]]+1; last[a[j]]=j; if(j-start+1>best) best=j-start+1; } printf("%d\n", best); return 0; }
- 1
信息
- ID
- 2632
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者