Pig eat watermelon (Wmelon)

Source: Internet
Author: User
Tags gcd

Pig eat watermelon (Wmelon) Title Description

One day, the greedy pig came to a big orchard, the orchard has n (n≤100000) A big watermelon, the quality of each watermelon is not greater than the length of the whole type (longint), and the quality of each watermelon is different. Pig very bored, first put all the watermelon by small to large, and then choose M (m≤l00000) A quality is Ki watermelon, please help him to eat the watermelon to find out.

Input

Enter N in line 1th, and then enter n integers for the following n lines;
Then enter M, and then the following m lines, one integer ki per line.

Output

Output m lines, one integer per line, indicating the position of Ki in this n number after reordering.

Sample input
31321231451123
Sample output
1
Analysis: The first sort, after the order of the sequence of values and coordinates directly map with a map of the good;
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<ext/rope>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineVI vector<int>#definePII pair<int,int>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e5+Ten;Const intdis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;using namespace__gnu_cxx;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p;p=p*p;q>>=1;}returnF;}intN,m;map<ll,int>A;ll B[MAXN];intMain () {inti,j,k,t; scanf ("%d",&N); Rep (I,0, N-1) scanf ("%lld",&B[i]); Sort (b,b+N); Rep (I,0, N-1) a[b[i]]=i+1; scanf ("%d",&m);  while(m--) scanf ("%lld", &b[0]), printf ("%d\n", a[b[0]]); //System ("pause");    return 0;}

Pig eat watermelon (Wmelon)

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.