Title Description
A two-dimensional plane has \ (n\) a trapezoid, satisfies:
The bottom edge of all trapezoid is on the straight line \ (y=0\) .
The upper and lower edges of all trapezoid are on the straight line \ (y=1\) .
No two points have the same coordinates.
You can select any number of trapezoid at once, must meet these trapezoid 22 overlap, then delete these trapezoid.
Ask you at least several times can delete all trapezoid.
\ (N\leq {10}^5\)
Exercises
Discretization of the coordinates first.
Defines \ (a\) A collection of all the trapezoidal elements.
We define a strict partial order on \ (a\) : two trapezoidal \ (a<b\) when and only if \ (a\) and \ (b\) do not overlap and \ (a\) in \ (b\) to the left.
So every time you delete a rectangle, it's a reverse chain.
So the problem is to ask for the smallest anti-chain coverage.
According to the duality theorem of the Dilworth theorem, there are: Minimum anti-chain cover number \ (=\) longest chain length
So we just have to ask for the longest chain length.
This thing can be done by DP.
\[f_i=\max_{a12j<a11i,a22j<a21i}f_j+1\]
\ (a11,a12,a21,a22\) represents the horizontal axis of the two ends of a trapezoidal top edge, and the horizontal axis of the two ends of the bottom edge.
You can sort all the trapezoid by \ (a11\) , maintain a heap with \ (a12\) as the keyword, take the elements of the team out to \ (a22\) position,\ (f_j\) Inserts a value into the tree array, and then queries the answer in the tree-like array.
Time complexity:\ (O (n\log n) \)
Code
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <utility>using namespaceStdtypedefpair<int,int> pii;priority_queue<pii,vector<pii>,greater<pii> > Q;structp{intA11,a12,a21,a22;}; P a[100010];intCMP (P a,p b) {returnA.A11<B.A11;}intf[100010];intc[100010];intm=0;intd[200010];voidAddintXintV) { for(; x<=m;x+=x&-x) C[x]=max (c[x],v);}intQueryintx) {ints=0; for(; x;x-=x&-x) S=max (s,c[x]);returns;}intMain () {#ifndef Online_judgeFreopen ("B.in","R", stdin); Freopen ("B.out","W", stdout);#endif intN,i; scanf"%d", &n); for(i=1; i<=n;i++) {scanf ("%d%d%d%d", &a[i].a11,&a[i].a12,&a[i].a21,&a[i].a22); D[++m]=a[i].a21; D[++m]=a[i].a22; } sort (d+1, d+m+1); for(i=1; i<=n;i++) {A[i].a21=lower_bound (d+1, d+m+1, A[I].A21)-D; A[i].a22=lower_bound (d+1, d+m+1, a[i].a22)-D; } sort (A+1, A+n+1, CMP);intans=0; for(i=1; i<=n;i++) {Q.push (PII (a[i].a12,i)); while(!q.empty () &&q.top (). First<a[i].a11) {PII x=q.top (); Q.pop (); Add (A[x.second].a22,f[x.second]); } f[i]=query (A[I].A21)+1; Ans=max (Ans,f[i]); } printf ("%d\n", ans);return 0;}
"XSY2727" Remove Dilworth theorem heap tree-like array DP