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)