Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- class Codechef
- {
- static FastIO f;
- static TreeMap<Interval, Integer> h;
- public static void main(String args[]) throws IOException
- {
- f = new FastIO();
- int t, n, q, i, j;
- Score s[];
- t = f.ni();
- while(t-->0)
- {
- h = new TreeMap<>(new Comparator<Interval>(){
- @Override
- public int compare(Interval a, Interval b)
- {
- if((a.l >= b.l && a.r <= b.r) || (a.l <= b.l && a.r >= b.r))
- return 0;
- return a.l-b.l;
- }
- });
- n = f.ni();
- q = f.ni();
- s = new Score[n];
- for(i = 0; i < n; i++)
- s[i] = new Score(f.ni(), f.ni());
- Arrays.sort(s, new Comparator<Score>(){
- @Override
- public int compare(Score a, Score b)
- {
- if(a.n == b.n)
- return a.p-b.p;
- return b.n-a.n;
- }
- });
- for(i = 0, j = 0; j < n; i = j)
- {
- while(j < n && s[j].equals(s[i]))
- j++;
- h.put(new Interval(i, j-1), j-i);
- }
- while(q-->0)
- {
- j = f.ni()-1;
- f.out(h.get(new Interval(j, j)) + "\n");
- }
- }
- f.flush();
- }
- static class Score
- {
- int n, p;
- Score(int x, int y)
- {
- n = x;
- p = y;
- }
- @Override
- public int hashCode()
- {
- return n^p;
- }
- @Override
- public boolean equals(Object obj)
- {
- Score that = (Score)obj;
- return n == that.n && p == that.p;
- }
- @Override
- public String toString()
- {
- return "[" + n + ", " + p + "]";
- }
- }
- static class Interval
- {
- int l, r;
- Interval(int x, int y)
- {
- l = x;
- r = y;
- }
- @Override
- public int hashCode()
- {
- return l^r;
- }
- @Override
- public boolean equals(Object obj)
- {
- Interval that = (Interval)obj;
- return l == that.l && r == that.r;
- }
- @Override
- public String toString()
- {
- return "[" + l + ", " + r + "]";
- }
- }
- public static class FastIO
- {
- BufferedReader br;
- BufferedWriter bw, be;
- StringTokenizer st;
- public FastIO()
- {
- br = new BufferedReader(new InputStreamReader(System.in));
- bw = new BufferedWriter(new OutputStreamWriter(System.out));
- be = new BufferedWriter(new OutputStreamWriter(System.err));
- st = new StringTokenizer("");
- }
- private void read() throws IOException
- {
- st = new StringTokenizer(br.readLine());
- }
- public String ns() throws IOException
- {
- while(!st.hasMoreTokens())
- read();
- return st.nextToken();
- }
- public int ni() throws IOException
- {
- return Integer.parseInt(ns());
- }
- public long nl() throws IOException
- {
- return Long.parseLong(ns());
- }
- public float nf() throws IOException
- {
- return Float.parseFloat(ns());
- }
- public double nd() throws IOException
- {
- return Double.parseDouble(ns());
- }
- public char nc() throws IOException
- {
- return ns().charAt(0);
- }
- public int[] nia(int n) throws IOException
- {
- int[] a = new int[n];
- for(int i = 0; i < n; i++)
- a[i] = ni();
- return a;
- }
- public long[] nla(int n) throws IOException
- {
- long[] a = new long[n];
- for(int i = 0; i < n; i++)
- a[i] = nl();
- return a;
- }
- public char[] nca() throws IOException
- {
- return ns().toCharArray();
- }
- public void out(String s) throws IOException
- {
- bw.write(s);
- }
- public void flush() throws IOException
- {
- bw.flush();
- be.flush();
- }
- public void err(String s) throws IOException
- {
- be.write(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement