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(); } }
-
0
判断最左边的右端点和最右边的左端点 如果小于,则不相交
#include <iostream> #include <vector> #include <set> using namespace std; #define int long long const int mod=1e+7; signed main() { iostream::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; multiset<int> l, r; for (int i = 1; i <= n; i++) { char c; cin >> c; int x, y; cin >> x >> y; if (c == '+') { l.insert(x); r.insert(y); } else { l.erase(l.find(x)); r.erase(r.find(y)); } if (l.size() > 1 && (*r.begin() < *l.rbegin())) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
- 1
信息
- ID
- 593
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 21
- 已通过
- 7
- 上传者