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

Re:我的程序更加简单而精炼,但是还为什么超时????

Posted by bird at 2005-05-15 22:06:47 on Problem 2104
In Reply To:已经这么简单的程序应该怎么改进,才能不超时? Posted by:00348264 at 2005-01-15 18:11:51
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	long *a=new long[n],*p=a;
	while(n--)scanf("%d",p++);
	while(m--)
	{
		int i,j,k;
		scanf("%d%d%d",&i,&j,&k);
		int N=j-i+1;
		long *b=new long[N],*q=b;
		p=a+i-1;
		while(N--)*(q++)=*(p++);
		sort(b,q);
		printf("%d\n",*(b+k-1));
		delete []b;
	}
	delete []a;
	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