제출 #1197995

#제출 시각아이디문제언어결과실행 시간메모리
1197995JooDdaeWorst Reporter 2 (JOI16_worst_reporter2)C++20
100 / 100
288 ms30080 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using Node = array<int, 2>; #define mid ((l+r) >> 1) const int INF = 1e9; int n, a[200200], b[200200], c[200200], d[200200], p[200200], chk[200200]; map<int, int> mp[200200]; int lz[800800]; Node t[800800]; Node build(int node = 1, int l = 1, int r = n) { if(l == r) return t[node] = {INF, l}; return t[node] = min(build(node*2, l, mid), build(node*2+1, mid+1, r)); } void lazy_update(int node, int l, int r) { if(lz[node]) { t[node][0] += lz[node]; if(l != r) lz[node*2] += lz[node], lz[node*2+1] += lz[node]; lz[node] = 0; } } void update(int nl, int nr, int val, int node = 1, int l = 1, int r = n) { lazy_update(node, l, r); if(nr < l || r < nl) return; if(nl <= l && r <= nr) { lz[node] += val; lazy_update(node, l, r); return; } update(nl, nr, val, node*2, l, mid), update(nl, nr, val, node*2+1, mid+1, r); t[node] = min(t[node*2], t[node*2+1]); } int ans; void match(int x, int y) { if(a[x] == c[y]) ans++; auto id = lower_bound(p+1, p+1+n, y) - p; chk[y] = 1, mp[c[y]].erase(d[y]); update(x, x, INF), update(x+1, n, 1), update(id, n, -1); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i=1;i<=n;i++) cin >> a[i] >> b[i]; for(int i=1;i<=n;i++) cin >> c[i] >> d[i]; for(int i=1;i<=n;i++) { p[i] = p[i-1]; while(p[i] < n && d[p[i]+1] >= b[i]) p[i]++; mp[c[i]][d[i]] = i; } build(); for(int i=1, j=1;i<=n;i++) { while(t[1][0] == 1) { while(chk[j]) j++; match(t[1][1], j); } update(i, i, p[i]-i+1-INF); auto it = mp[a[i]].lower_bound(b[i]); if(it != mp[a[i]].end()) match(i, it->second); } cout << n-ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...