Advertisement
Guest User

JAPC1005 Setter Solution

a guest
May 2nd, 2021
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Codechef
  5. {
  6.  
  7. static FastIO f;
  8. static TreeMap<Interval, Integer> h;
  9.  
  10. public static void main(String args[]) throws IOException
  11. {
  12. f = new FastIO();
  13.  
  14. int t, n, q, i, j;
  15. Score s[];
  16.  
  17. t = f.ni();
  18.  
  19. while(t-->0)
  20. {
  21. h = new TreeMap<>(new Comparator<Interval>(){
  22.  
  23. @Override
  24. public int compare(Interval a, Interval b)
  25. {
  26. if((a.l >= b.l && a.r <= b.r) || (a.l <= b.l && a.r >= b.r))
  27. return 0;
  28.  
  29. return a.l-b.l;
  30. }
  31. });
  32.  
  33. n = f.ni();
  34. q = f.ni();
  35. s = new Score[n];
  36.  
  37. for(i = 0; i < n; i++)
  38. s[i] = new Score(f.ni(), f.ni());
  39.  
  40. Arrays.sort(s, new Comparator<Score>(){
  41.  
  42. @Override
  43. public int compare(Score a, Score b)
  44. {
  45. if(a.n == b.n)
  46. return a.p-b.p;
  47.  
  48. return b.n-a.n;
  49. }
  50. });
  51.  
  52. for(i = 0, j = 0; j < n; i = j)
  53. {
  54. while(j < n && s[j].equals(s[i]))
  55. j++;
  56. h.put(new Interval(i, j-1), j-i);
  57. }
  58.  
  59. while(q-->0)
  60. {
  61. j = f.ni()-1;
  62. f.out(h.get(new Interval(j, j)) + "\n");
  63. }
  64. }
  65.  
  66. f.flush();
  67. }
  68.  
  69. static class Score
  70. {
  71. int n, p;
  72.  
  73. Score(int x, int y)
  74. {
  75. n = x;
  76. p = y;
  77. }
  78.  
  79. @Override
  80. public int hashCode()
  81. {
  82. return n^p;
  83. }
  84.  
  85. @Override
  86. public boolean equals(Object obj)
  87. {
  88. Score that = (Score)obj;
  89.  
  90. return n == that.n && p == that.p;
  91. }
  92.  
  93. @Override
  94. public String toString()
  95. {
  96. return "[" + n + ", " + p + "]";
  97. }
  98. }
  99.  
  100. static class Interval
  101. {
  102. int l, r;
  103.  
  104. Interval(int x, int y)
  105. {
  106. l = x;
  107. r = y;
  108. }
  109.  
  110. @Override
  111. public int hashCode()
  112. {
  113. return l^r;
  114. }
  115.  
  116. @Override
  117. public boolean equals(Object obj)
  118. {
  119. Interval that = (Interval)obj;
  120.  
  121. return l == that.l && r == that.r;
  122. }
  123.  
  124. @Override
  125. public String toString()
  126. {
  127. return "[" + l + ", " + r + "]";
  128. }
  129. }
  130.  
  131. public static class FastIO
  132. {
  133. BufferedReader br;
  134. BufferedWriter bw, be;
  135. StringTokenizer st;
  136.  
  137. public FastIO()
  138. {
  139. br = new BufferedReader(new InputStreamReader(System.in));
  140. bw = new BufferedWriter(new OutputStreamWriter(System.out));
  141. be = new BufferedWriter(new OutputStreamWriter(System.err));
  142. st = new StringTokenizer("");
  143. }
  144.  
  145. private void read() throws IOException
  146. {
  147. st = new StringTokenizer(br.readLine());
  148. }
  149.  
  150. public String ns() throws IOException
  151. {
  152. while(!st.hasMoreTokens())
  153. read();
  154. return st.nextToken();
  155. }
  156.  
  157. public int ni() throws IOException
  158. {
  159. return Integer.parseInt(ns());
  160. }
  161.  
  162. public long nl() throws IOException
  163. {
  164. return Long.parseLong(ns());
  165. }
  166.  
  167. public float nf() throws IOException
  168. {
  169. return Float.parseFloat(ns());
  170. }
  171.  
  172. public double nd() throws IOException
  173. {
  174. return Double.parseDouble(ns());
  175. }
  176.  
  177. public char nc() throws IOException
  178. {
  179. return ns().charAt(0);
  180. }
  181.  
  182. public int[] nia(int n) throws IOException
  183. {
  184. int[] a = new int[n];
  185. for(int i = 0; i < n; i++)
  186. a[i] = ni();
  187.  
  188. return a;
  189. }
  190.  
  191. public long[] nla(int n) throws IOException
  192. {
  193. long[] a = new long[n];
  194. for(int i = 0; i < n; i++)
  195. a[i] = nl();
  196.  
  197. return a;
  198. }
  199.  
  200. public char[] nca() throws IOException
  201. {
  202. return ns().toCharArray();
  203. }
  204.  
  205. public void out(String s) throws IOException
  206. {
  207. bw.write(s);
  208. }
  209.  
  210. public void flush() throws IOException
  211. {
  212. bw.flush();
  213. be.flush();
  214. }
  215.  
  216. public void err(String s) throws IOException
  217. {
  218. be.write(s);
  219. }
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement