Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用了两个map= =

Posted by crazyX at 2016-02-23 21:33:27 on Problem 3320
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int a[1000000+7],n;
map<int,int> fuck;
map<int,int> f;
int main()
{
//	memset(a,0,sizeof(a));
	scanf("%d",&n);
	int count=0;
	for (int i = 0; i < n; i += 1){
		scanf("%d",&a[i]);
		if(fuck[a[i]]==0){
			count++;
		}
		fuck[a[i]]++;
	}
	int s=0,res=n+1,t=0,sum=0;
	while (1)
	{
		while(t<n&&sum<count){
			if(f[a[t]]==0)sum++;
			f[a[t++]]++;
		}
		if(sum<count)break;
		res=min(res,t-s);
		f[a[s]]--;
		if(f[a[s++]]==0)sum--;
	}
	cout<<res<<endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator