Minimum time limit:MS | Memory limit:65535 KB Difficulty:3
-
Describe
-
Enter n number,m query.
Each query gives a number x.
Requirements: the number of x in the number of times before each query output . (I for the second query)
You can assume that M <= N,Xi <= xi+1 <= xi+2 <= .... <= xm (XM <= N).
-
-
Input
-
-
Line0:t
Line1:n,m
Line2 ... LINEN+1:NUM1,......, Numn
Linen+2 ... Linen+2+m:x1,......, XM
N < 30000, num < 2000000000
-
-
Output
-
-
each query outputs a small number of first I, a single row.
Please refer to the sample for detailed format.
-
-
Sample input
-
-
17 43 1-4 2 8-1000 21 2 6 6
-
-
Sample output
-
3312
AC Code:
#include <stdio.h>#defineINF 2000000000inta[30005];voidQuicksortintLeftintRight );intMain () {intt,m,n,i,j,k; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&M); for(i=0; i<n;i++) scanf ("%d",&A[i]); for(i=0; i<m;i++) {scanf ("%d",&k); Quicksort (0, K-1);//Fast row printf ("%d\n", A[i]);//I Small Value}}return 0;}voidQuicksortintLeftintRight ) { inti,j,t,temp; if(Left >Right ) { return; } I=Left ; J=Right ; T=A[left]; while(I! =j) { while(A[j]>= t && i<j) {J--; } while(A[i]<= t && i<j) {I++; } if(I <j) {Temp=A[i]; A[i]=A[j]; A[J]=temp; }} A[left]=A[i]; A[i]=T; Quicksort (Left,i-1); Quicksort (i+1, right); return;}
Optimize code Next Update:
Nyoj 1073 min value