2 条题解
-
0
对于本题,java必须运用快读否则将会超时: 不用快读:
import java.io.*; import java.util.*; public class Main { static TreeMap<Integer, Integer> tl = new TreeMap<>(), tr = new TreeMap<>(); public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int T = sc.nextInt(); while (T-- > 0) { char ch = sc.next().charAt(0); int l = sc.nextInt(); int r = sc.nextInt(); if (ch == '+') { tl.put(l, tl.getOrDefault(l, 0) + 1); tr.put(r, tr.getOrDefault(r, 0) + 1); } else { tl.put(l, tl.getOrDefault(l, 0) - 1); tr.put(r, tr.getOrDefault(r, 0) - 1); if (tl.get(l) == 0) tl.remove(l); if (tr.get(r) == 0) tr.remove(r); } System.out.println(tl.size() > 0 && tr.size() > 0 && tl.lastKey() > tr.firstKey() ? "YES" : "NO"); } } }
运用快读:
import java.io.*; import java.util.*; public class Main { static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static TreeMap<Integer, Integer> tl = new TreeMap<>(), tr = new TreeMap<>(); public static void solve() throws IOException { String[] str = bf.readLine().split(" "); char ch = str[0].charAt(0); int l = Integer.parseInt(str[1]); int r = Integer.parseInt(str[2]); if (ch == '+') { tl.put(l, tl.getOrDefault(l, 0) + 1); tr.put(r, tr.getOrDefault(r, 0) + 1); } else { tl.put(l, tl.getOrDefault(l, 0) - 1); tr.put(r, tr.getOrDefault(r, 0) - 1); if (tl.get(l) == 0) tl.remove(l); if (tr.get(r) == 0) tr.remove(r); } bw.write(tl.size() > 0 && tr.size() > 0 && tl.lastKey() > tr.firstKey() ? "YES\n" : "NO\n"); } public static void main(String[] args) throws IOException { int T = Integer.parseInt(bf.readLine()); while (T-- > 0) { solve(); } bw.close(); } }
信息
- ID
- 593
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 21
- 已通过
- 7
- 上传者