Advertisement
Guest User

JAPC1002 Setter Solution

a guest
May 2nd, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Codechef
  5. {
  6.  
  7. static FastIO f;
  8. static TreeSet<Integer> h;
  9.  
  10. public static void main(String args[]) throws IOException
  11. {
  12. f = new FastIO();
  13. int t = f.ni(), n;
  14.  
  15. while(t-->0)
  16. {
  17. n = f.ni();
  18. h = new TreeSet<>();
  19.  
  20. while(n-->0)
  21. {
  22. if(f.ni() == 1)
  23. h.add(f.ni());
  24. else
  25. f.out(ceil(f.ni()) + "\n");
  26. }
  27. }
  28.  
  29. f.flush();
  30. }
  31.  
  32. public static int ceil(int n)
  33. {
  34. Integer a = h.ceiling(n);
  35.  
  36. if(a == null)
  37. return -1;
  38.  
  39. return a;
  40. }
  41.  
  42. public static class FastIO
  43. {
  44. BufferedReader br;
  45. BufferedWriter bw, be;
  46. StringTokenizer st;
  47.  
  48. public FastIO()
  49. {
  50. br = new BufferedReader(new InputStreamReader(System.in));
  51. bw = new BufferedWriter(new OutputStreamWriter(System.out));
  52. be = new BufferedWriter(new OutputStreamWriter(System.err));
  53. st = new StringTokenizer("");
  54. }
  55.  
  56. private void read() throws IOException
  57. {
  58. st = new StringTokenizer(br.readLine());
  59. }
  60.  
  61. public String ns() throws IOException
  62. {
  63. while(!st.hasMoreTokens())
  64. read();
  65. return st.nextToken();
  66. }
  67.  
  68. public int ni() throws IOException
  69. {
  70. return Integer.parseInt(ns());
  71. }
  72.  
  73. public long nl() throws IOException
  74. {
  75. return Long.parseLong(ns());
  76. }
  77.  
  78. public float nf() throws IOException
  79. {
  80. return Float.parseFloat(ns());
  81. }
  82.  
  83. public double nd() throws IOException
  84. {
  85. return Double.parseDouble(ns());
  86. }
  87.  
  88. public char nc() throws IOException
  89. {
  90. return ns().charAt(0);
  91. }
  92.  
  93. public int[] nia(int n) throws IOException
  94. {
  95. int[] a = new int[n];
  96. for(int i = 0; i < n; i++)
  97. a[i] = ni();
  98.  
  99. return a;
  100. }
  101.  
  102. public long[] nla(int n) throws IOException
  103. {
  104. long[] a = new long[n];
  105. for(int i = 0; i < n; i++)
  106. a[i] = nl();
  107.  
  108. return a;
  109. }
  110.  
  111. public char[] nca() throws IOException
  112. {
  113. return ns().toCharArray();
  114. }
  115.  
  116. public void out(String s) throws IOException
  117. {
  118. bw.write(s);
  119. }
  120.  
  121. public void flush() throws IOException
  122. {
  123. bw.flush();
  124. be.flush();
  125. }
  126.  
  127. public void err(String s) throws IOException
  128. {
  129. be.write(s);
  130. }
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement