Surface
Topic Portal
Solution
Considering the conversion of complement sets, we only ask for the correct maximum number
Clearly, something that is clearly wrong can be ruled out directly.
For \ ((x, y) \) the same position must be equal
Then we can put the \ ((x, y) \) equal and in a class of
Then consider the (x, y) \) How to convert, is clearly the number in the entire column corresponding to the interval, for \ ([x+1,n-y]\)
Combine the intervals equally, and the rest are unequal.
Then just pick as many disjoint intervals as you can.
Sort the left endpoint and then use the tree array to refine the DP
Time complexity:\ (O (n\ log\ n) \)
Code
#include <bits/stdc++.h> #define N 100010using namespace std;template <typename node> void Chkmax (node &x , node y) {x = max (x, y);} Template <typename node> void chkmin (node &x, node y) {x = min (x, y);} Template <typename node> void Read (node &x) {x = 0; int f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) x = x * ten + C-' 0 ', C = GetChar (); x *= F;} struct Node {int L, r, V; BOOL operator < (const Node &a) Const {if (l! = A.L) return L < A.L; return R < A.R; }} A[n], B[n];int N, tot, Len, f[n], dp[n];int lowbit (int x) {return x &-X;} BOOL CMP (Node A, Node B) {return A.L! = B.L | | A.R! = B.R;} int query (int x) {int ret = 0; for (int i = x; i; i-= Lowbit (i)) Chkmax (ret, f[i]); return ret;} void Modify (int x, int v) {for (int i = x; i <= n; i + = Lowbit (i)) Chkmax (F[i], v);} int main () {read (n); for (int i = 1; I <= N; i++) {int x, y; Read (x), read (y); if (x + y < n) a[++tot] = (Node) {x + 1, n-y, 0}; } sort (A + 1, a + tot + 1); Node las = a[1]; int sum = 1; for (int i = 2; I <= tot; i++) if (CMP (A[i], las) {B[++len] = las, b[len].v = sum; Las = a[i], sum = 1; } else sum++; B[++len] = las; B[LEN].V = sum; int ans = 0; for (int i = 1; I <= len; i++) chkmin (B[I].V, B[I].R-B[I].L + 1); Sort (b + 1, B + len + 1); for (int i = 1; I <= len; i++) {Dp[i] = query (B[I].L-1) + b[i].v; Modify (B[I].R, dp[i]); Chkmax (ans, dp[i]); } cout << N-ans << "\ n"; return 0;}
Bzoj 2298 [Haoi2011]problem a dp+ tree-like array