Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a2oj;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.util.Arrays;
- import java.util.Map;
- import java.util.SortedSet;
- import java.util.StringTokenizer;
- import java.util.TreeMap;
- import java.util.TreeSet;
- /**
- * Created by Rakshit on 17/1/17.
- * Java is Love and Code is Beautiful..
- */
- public class Query{
- static class InputReader
- {
- public BufferedReader reader;
- public StringTokenizer tok;
- public InputReader(InputStream inputStream)
- {
- reader =new BufferedReader(new InputStreamReader(inputStream));
- tok=null;
- }
- public InputReader(String inputFile) throws FileNotFoundException
- {
- reader=new BufferedReader(new FileReader(inputFile));
- tok=null;
- }
- public String nextLine()
- {
- String c="";
- try
- {
- c+=reader.readLine();
- }
- catch(IOException e)
- {
- throw new RuntimeException(e);
- }
- return c;
- }
- public String next()
- {
- while(tok==null || !tok.hasMoreTokens())
- {
- try
- {
- tok=new StringTokenizer(nextLine());
- }
- catch(Exception e)
- {
- throw new RuntimeException(e);
- }
- }
- return tok.nextToken();
- }
- public int nextInt()
- {
- return Integer.parseInt(next());
- }
- public long nextLong()
- {
- return Long.parseLong(next());
- }
- public double nextDouble()
- {
- return Double.parseDouble(next());
- }
- }
- public static void main(String args[])
- {
- InputStream inputstream=System.in;
- OutputStream outputstream=System.out;
- InputReader in=new InputReader(inputstream);
- PrintWriter out=new PrintWriter (outputstream);
- Task solver=new Task();
- solver.solve(in,out);
- }
- static class Task
- {
- public final int INF =100000000;
- public void solve(InputReader in , PrintWriter out)
- {
- int n=in.nextInt();
- int m=in.nextInt();
- SortedSet<Integer> check=new TreeSet();
- int a[]=new int [n];
- int b[]=new int [m];
- for(int i=0 ;i<n ;i++)
- {
- a[i]=in.nextInt();
- }
- for(int i=0 ;i<m ;i++)
- {
- b[i]=in.nextInt();
- check.add(b[i]);
- }
- Arrays.sort(a);
- int res[]=new int [m];
- int l=check.size();
- Map<Integer,Integer> store=new TreeMap();
- Map<Integer,Integer> good=new TreeMap();
- for(int i=0 ;i<n ;i++)
- {
- good.put(a[i],i);
- // for(Map.Entry<Integer,Integer>entry:good.entrySet())
- // {
- // out.println(entry.getKey()+" "+entry.getValue());
- // }
- }
- // for(Map.Entry<Integer,Integer>entry:good.entrySet())
- // {
- // out.println(entry.getKey()+" "+entry.getValue());
- // }
- int s;
- Integer[] c=check.toArray(new Integer[check.size()]);
- for(int i=0 ;i<l ;i++)
- {
- if(good.containsKey(c[i]))
- {
- store.put(c[i],good.get(c[i])+1);
- }
- else
- {
- s=Arrays.binarySearch(a,c[i]);
- s=-(s+1);
- store.put(c[i],s);
- }
- }
- for(int i=0 ;i<m ;i++)
- {
- res[i]=store.get(b[i]);
- }
- for(int i=0 ;i<m ;i++)
- {
- out.print(res[i]+" ");
- }
- out.flush();
- }
- public long fac(int n)
- {
- long f[]=new long [n+1];
- f[0]=1;
- for(int i=1 ;i<n+1 ;i++)
- {
- f[i]=i*f[i-1];
- }
- return f[n];
- }
- public long c(int n,int a,int b)
- {
- return fac(n)/(fac(a)*fac(b));
- }
- }
- }
Add Comment
Please, Sign In to add comment