[BZOJ2716] [Violet 3] Angel Doll
Question Description
Input
Output
Input example
The first test point, I don't take it to the page = =
Output example
Ditto
Data size and conventions
= = The range given in the title is wrong ... Turn in the re ... I have a visual about N, M≤600000,xi, yi≤107.
Exercises
cnbb! person
1.) Data super large, time limit of the SEC, the topic of malicious card evaluation machine!
2.) cannot be optimized with any read-in.
3.) The data range is back to the wrong!
4.) kd Tree template-deletion problem. "The only thing that's serious is this one.
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <stack > #include <vector> #include <queue> #include <cstring> #include <string> #include <map > #include <set>using namespace std;const int buffersize = 1 << 16;char buffer[buffersize], *head, *TAIL;INL ine Char Getchar () {if (Head = = Tail) {int L = fread (buffer, 1, buffersize, stdin); Tail = (Head = buffer) + L; } return *head++;} int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 1200010#define oo 40000000int n, m;int Root, Lc[maxn], Rc[maxn];bool cur;struct Node {int x[2], mx[2], mn[2]; BOOL operator < (const node& t) const {return x[cur]! = T.x[cur]? X[cur] < T.x[cur]: X[cur^1] < t.x[cur^1] ; }int operator * (const node& t) const {return abs (X[0] -t.x[0]) + ABS (X[1]-t.x[1]); }} ns[maxn];void maintain (int o) {int l = Lc[o], r = rc[o];for (int i = 0; i < 2; i++) {Ns[o].mx[i] = max (max (ns[l].mx[i ], Ns[r].mx[i]), ns[o].x[i]); Ns[o].mn[i] = min (min (ns[l].mn[i], ns[r].mn[i]), ns[o].x[i]);} return;} void Build (int& o, int L, int R, bool cur) {if (L > R) {o = 0; return;} int M = L + R >> 1; o = M; Cur = Cur; Nth_element (ns + L, NS + M, NS + R + 1), build (Lc[o], L, M-1, cur ^ 1); Build (Rc[o], M + 1, R, cur ^ 1); return maintain (o);} Node x;void ins (int& o, bool cur) {if (!o) Ns[o = ++n] = x;else {if (Ns[o].x[cur] < x.x[cur]) Ins (Rc[o], cur ^ 1); Els E Ins (Lc[o], cur ^ 1);} return maintain (o);} int calc (int b) {int sum = 0;for (int i = 0; i < 2; i++) {if (X.x[i] < ns[b].mn[i]) sum + = Ns[b].mn[i]-X.x[i];else I F (X.x[i] > Ns[b].mx[i]) sum + = X.x[i]-ns[b].mx[i];} return sum;} int query (int o) {int l = Lc[o], r = Rc[o], ans = ns[o] * x;int d1 = Calc (l), d2 = Calc (r), if (D1 < D2) {if (ans > D1) ans = min (ans, query(l)); if (ans > d2) ans = min (ans, query (R));} else {if (ans > d2) ans = min (ans, query (R)), if (ans > D1) ans = min (ans, query (L));} return ans;} int main () {//freopen ("data.in", "R", stdin),//freopen ("Data.out", "w", stdout); ns[0].mx[0] = ns[0].mx[1] =-oo;ns[0].mn [0] = ns[0].mn[1] = oo;scanf ("%d%d", &n, &m); for (int i = 1; I <= n; i++) scanf ("%d%d", &ns[i].x[0], &ns [i].x[1]); Build (root, 1, N, 0),//for (int i = 1; I <= n; i++) printf ("%d%d%d%d%d%d\n", ns[i].x[0], ns[i].x[1], ns[i ].mx[0], ns[i].mx[1], ns[i].mn[0], ns[i].mn[1]);//for (int i = 1; I <= n; i++) printf ("%d%d\n", Lc[i], rc[i]); int CNT = 0;while (m--) {int TP = read (), x.x[0] = Read (), x.x[1] = Read (), if (tp = = 1) {Ins (root, 0); Cnt++;if (CNT = = 10000) build (root, 1, n, 0);} if (tp = = 2) printf ("%d\n", query (Root));} return 0;}
[BZOJ2716] [Violet 3] Angel Doll