Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.StringTokenizer;
- import java.util.TreeMap;
- public class SettingExam {
- static class FloorPair {
- int queryIdx;
- int val;
- public FloorPair(int queryIdx, int val) {
- this.queryIdx = queryIdx;
- this.val = val;
- }
- }
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int y = 0;
- int[][] queries = new int[n][2]; // first idx for type, 2nd idx for val/res
- // 0 -> add, 1 -> remove, -1 -> floor
- TreeMap<Integer, Integer> freqs = new TreeMap<>();
- ArrayList<FloorPair>[] floors = new ArrayList[n + 1];
- for (int i = 0; i < queries.length; i++) {
- queries[i][0] = -1;
- queries[i][1] = -1;
- }
- for (int i = 0; i < floors.length; i++) {
- floors[i] = new ArrayList<>();
- }
- for (int i = 0; i < n; i++) {
- String type = sc.next();
- switch (type) {
- case "floor":
- floors[sc.nextInt()].add(new FloorPair(i, sc.nextInt()));
- break;
- case "add":
- queries[i][0] = 0;
- queries[i][1] = sc.nextInt();
- break;
- case "remove":
- queries[i][0] = 1;
- queries[i][1] = sc.nextInt();
- break;
- }
- }
- int ver = 0;
- for (int i = 0; i < queries.length; i++) {
- int type = queries[i][0];
- int val = queries[i][1];
- switch (type) {
- case 0: // add
- freqs.put(val ^ y, freqs.getOrDefault(val, 0) + 1);
- ver++;
- break;
- case 1: // remove
- int prev = freqs.getOrDefault(val, -1);
- if (prev != -1) {
- if (prev == 1)
- freqs.remove(val);
- else
- freqs.put(val, prev - 1);
- }
- ver++;
- break;
- default: // floor
- y = Math.max(0, val);
- if (val <= -1) {
- System.out.println("No Questions");
- } else {
- System.out.println(val);
- }
- break;
- }
- for (FloorPair p : floors[ver]) {
- Integer f = freqs.floorKey(p.val);
- if (f != null) {
- queries[p.queryIdx][1] = f;
- }
- }
- }
- }
- static class Scanner {
- StringTokenizer st;
- BufferedReader br;
- public Scanner(InputStream s) {
- br = new BufferedReader(new InputStreamReader(s));
- }
- public String next() throws IOException {
- while (st == null || !st.hasMoreTokens())
- st = new StringTokenizer(br.readLine());
- return st.nextToken();
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- public long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- public String nextLine() throws IOException {
- return br.readLine();
- }
- public double nextDouble() throws IOException {
- String x = next();
- StringBuilder sb = new StringBuilder("0");
- double res = 0, f = 1;
- boolean dec = false, neg = false;
- int start = 0;
- if (x.charAt(0) == '-') {
- neg = true;
- start++;
- }
- for (int i = start; i < x.length(); i++)
- if (x.charAt(i) == '.') {
- res = Long.parseLong(sb.toString());
- sb = new StringBuilder("0");
- dec = true;
- } else {
- sb.append(x.charAt(i));
- if (dec)
- f *= 10;
- }
- res += Long.parseLong(sb.toString()) / f;
- return res * (neg ? -1 : 1);
- }
- public boolean ready() throws IOException {
- return br.ready();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement