Nyoj 1073 min value

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.