Submission #1197976

#TimeUsernameProblemLanguageResultExecution timeMemory
1197976JooDdaeWorst Reporter 2 (JOI16_worst_reporter2)C++20
0 / 100
5 ms9792 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], chk2[200200]; map<int, int> mp[200200]; int lz[800800]; Node t[800800]; 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 = upper_bound(p+1, p+1+n, y) - p; chk[y] = 1, chk2[x] = 1, mp[c[y]].erase(d[y]); update(x, x, INF), update(1, id-1, -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; } for(int i=1;i<=4*n;i++) t[i] = {INF, 0}; for(int i=1, j=1;i<=n;i++) if(!chk[i]) { while(t[1][0] == 1) { int u = t[1][1]; while(chk[j]) j++; match(u, j); } auto it = mp[a[i]].lower_bound(b[i]); if(it != mp[a[i]].end()) { match(i, it->second); continue; } update(i, i, p[i]-INF); } 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...