Submission #1221620

#TimeUsernameProblemLanguageResultExecution timeMemory
1221620duckindogWorst Reporter 2 (JOI16_worst_reporter2)C++20
100 / 100
151 ms17136 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200'000 + 10; int n; pair<int, int> h1[N], h2[N]; const int MAX = 1'000'000'000; namespace IT { int f[N << 2], lazy[N << 2]; void update(int s, int l, int r, int u, int v, int x) { if (v < l || u > r) return; if (u <= l && r <= v) { f[s] += x; lazy[s] += x; return; } int mid = (l + r) >> 1; update(s << 1, l, mid, u, v, x); update(s << 1 | 1, mid + 1, r, u, v, x); f[s] = min(f[s << 1], f[s << 1 | 1]) + lazy[s]; } int query(int s, int l, int r, int u, int v) { if (v < l || u > r) return MAX; if (u <= l && r <= v) return f[s]; int mid = (l + r) >> 1; return min(query(s << 1, l, mid, u, v), query(s << 1 | 1, mid + 1, r, u, v)) + lazy[s]; } } vector<int> save[N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = n; i >= 1; --i) cin >> h1[i].first >> h1[i].second; for (int i = n; i >= 1; --i) cin >> h2[i].first >> h2[i].second; vector<int> allValue; { // discrete for (int i = 1; i <= n; ++i) { allValue.push_back(h2[i].second); } sort(allValue.begin(), allValue.end()); allValue.erase(unique(allValue.begin(), allValue.end()), allValue.end()); for (int i = 1; i <= n; ++i) { h1[i].second = lower_bound(allValue.begin(), allValue.end(), h1[i].second) - allValue.begin() + 1; h2[i].second = upper_bound(allValue.begin(), allValue.end(), h2[i].second) - allValue.begin(); } } const int m = allValue.size(); int answer = 0; for (int i = 1, it = 1; i <= n; ++i) { const auto& [color, point] = h2[i]; while (it <= n && h1[it].second <= point) { save[h1[it].first].push_back(h1[it].second); IT::update(1, 1, m, h1[it].second, m, 1); it += 1; } if (save[color].size() && IT::query(1, 1, m, save[color].back(), m) > 0) { IT::update(1, 1, m, save[color].back(), m, -1); save[color].pop_back(); } else { IT::update(1, 1, m, point, m, -1); answer += 1; } } cout << answer << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...