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

这个题本来就没打算让这么样的算法过的

Posted by frkstyc at 2007-05-11 12:07:31 on Problem 2104
In Reply To:这题时限卡太死了吧,离散化+radix sort,TLE, 不管怎么改参数就是不过... Posted by:qiqilrq at 2007-05-11 12:02:08
> #include <iostream>
> #include <list>
> using namespace std;
> 
> const int MIN = 50000;
> const int MID = 20002;
> int A[MID];
> int C[2 * MID];
> int R[MIN];
> 
> int main()
> {
> 	int i, j, p, N, M;
> 	int st, ed, K;
> 	scanf("%d%d", &N, &M);
> 	for(i=1; i<=N; i++) {
> 		scanf("%d", A+i);
> 	}
> 	for(i=1; i<=M; i++) {
> 		list <int> L[2*MID];
> 		int lt=MID, rt=MID;	//left , right
> 		int k;
> 		memset(C, 0, 2*MID*sizeof(int));
> 		
> 		scanf("%d%d%d",&st, &ed, &K);
> 		for(j=st; j<=ed; j++)
> 		{
> 			p=A[j]/MIN + MID;
> 			if(A[j]<0) p--;
> 			C[p]++;
> 			if(p<lt) lt=p;
> 			if(p>rt) rt=p;
> 		    L[p].push_back(A[j] - (p-MID)*MIN);
> 		}
> 		for(j=lt;K-C[j] > 0 && j<=rt; j++)
> 		{
> 			    K-=C[j];
> 		}
> 		//radixSort(j);
> 		memset(R, 0, MIN*sizeof(int));
> 		list <int> ::iterator lit;
> //		printf("list element: ");
> 		for(lit=L[j].begin(); lit!=L[j].end(); ++lit)
> 		{
> 			R[*lit]++; 
> //			printf("%d ", *lit);
> 		}
> //		puts("");
> 		for(k=0; k<MIN; k++)
> 		{
> //          printf("R[%d]: %d \n",k, R[k]);
> 			if(K-R[k] > 0)
> 				K-=R[k];
> 			else break;
> 		}
> 		printf("%d\n", k + MIN*(j-MID));
> 	}
> 
> 	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