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

过了的人,帮我看看我的应该怎么优化才能不TLE啊!谢谢了啊!!(代码不长)

Posted by caizhicong0503 at 2007-04-12 20:42:50 on Problem 2104
#include<cstdio> 
#include<map> 
using namespace std;
int q[100002];
map<int, bool> p;
int main()
{
	int n,m,t;
	scanf("%d %d",&n,&m);
	for(t=1;t<=n;t++)	scanf("%d",&q[t]);
	for(t=0;t<=n;++t)	p[t]=0; 
	while(m--)
	{
		int i,j,k; 
		scanf("%d %d %d",&i,&j,&k);
		int len=j-i+1;
		int Min=n; 
		for(t=0;t<len;t++){
			p[q[t+i]]=1;
			if(q[t+i]<Min)	Min=q[t+i];
		} 
		int sum=0,a;  
		for(a=Min;sum<k;++a)	if(p[a])	sum++; 
		printf("%d\n",a-1);
		for(t=0;t<len;t++)	p[q[t+i]]=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