void solve() { int n = nextInt(); int m = nextInt(); int l = 1; int r = n; for (int i = 0; i < m; i++) { nextToken(); nextToken(); String s = nextToken(); nextToken(); int k = nextInt(); if (s.equals("left")) { r = Math.min(r, k - 1); } else { l = Math.max(l, k + 1); } } if (l > r) { out.println(-1); } else { out.println(r - l + 1); } }
void solve() { int n = nextInt(); HashMap<Long, Integer>[] hm = new HashMap[33]; for (int i = 0; i < hm.length; i++) { hm[i] = new HashMap<Long, Integer>(); } boolean[] allows = new boolean[n]; for (int i = 0; i < n; i++) { String s = nextToken(); nextToken(); String ip = nextToken(); if (ip.indexOf("/") == -1) { ip = ip + "/32"; } allows[i] = s.equals("allow"); int p = ip.indexOf("/"); String s1 = ip.substring(0, p); String s2 = ip.substring(p + 1); int e = Integer.parseInt(s2); long r = ipToInteger(s1); r &= ~((1L << (32 - e)) - 1); if (!hm[e].containsKey(r)) hm[e].put(r, i); // System.err.println("Query " + i + " = " + r); } int m = nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < m; i++) { String ip = nextToken(); long r = ipToInteger(ip); int min = Integer.MAX_VALUE; // System.err.println("Cur = " + i); for (int j = 0; j <= 32; j++) { long e = r; e &= ~((1L << (32 - j)) - 1); // System.err.println(e + " " + j); if (hm[j].containsKey(e)) { min = Math.min(min, hm[j].get(e)); } } if (min == Integer.MAX_VALUE || allows[min]) { sb.append("A"); } else { sb.append("D"); } } out.println(sb); }