Offline, then divided by time, each vector has a time of occurrence [L, R], directly inserted into the time segment tree (a vector only affects the O (LOGN) Order of magnitude of the segment tree node). Make a convex hull and then two points on each node in the segment tree. Time complexity O (nlog^2n)
---------------------------------------------------------------------------
#include <cstdio>#include <cctype>#include <cstring>#include <algorithm>using namespace std;typedef long Long ll;#define V (x) v[p[x]]#define C (x) v[c[x]]#define Q (x) q[_q[x]]#define K (A, B) ((double) (A.Y-B.Y)/(a.x-b.x))const int MAXN = 200009;int N, T, qn, vn, Pn, CN;int P[MAXN], _Q[MAXN], C[MAXN];Double LK[MAXN], RK[MAXN];ll ANS[MAXN];int buf[20];inline int getint () {char C = getchar ();For (;!isdigit (c); c = GetChar ());int ret = 0;For (; IsDigit (c); c = GetChar ())ret = ret * + C-' 0 ';return ret;}inline void Putint (ll x) {if (!x) {puts ("0");} else {int n = 0;For (; x; x/=) buf[n++] = x%;while (n--) Putchar (buf[n] + ' 0 ');puts ("");}}struct Q {int p, x, y;} Q[MAXN]; struct V {int x, Y, L, R;} V[MAXN];struct L {int p;l* NXT;} LPOOL[MAXN *, *lpt = Lpool;inline void Addl (l*&t) {lpt->p = T;lpt->nxt = t;t = lpt++;}struct Node {Node *LC, *RC;l* v;} POOL[MAXN << 1], *pt = Pool, *root;void Modify (node* t, int l, int r) {if (v[t].l <= l && R <= v[t].r) {Addl (t->v);} else {int m = (L + r) >> 1;if (v[t].l <= m) Modify (T->LC, L, m);if (M < V[T].R) Modify (T->RC, M + 1, R);}}void Build (node* t, int l, int r) {if (l! = r) {int m = (L + r) >> 1;Build (T->LC = pt++, L, m);Build (T->RC = pt++, M + 1, R);}}bool CMP (const int &L, const int &r) {return v[l].x < v[r].x | | (v[l].x = = v[r].x && v[l].y < V[R].Y);} void Solve (node* t, int l, int r) {if (l! = r) {int m = (L + r) >> 1;Solve (T->LC, L, m);Solve (T->RC, M + 1, R);}PN = cn = 0;For (l* o = t->v; o; o = o->nxt) p[pn++] = o->p;if (!PN) return;sort (p, p + pn, CMP);c[cn++] = p[0];for (int i = 1; i < PN; i++) {while (CN && V (i). x = = C (cn-1). x) cn--;while (cn > 1 && K (V (i), C (cn-1)) > K (c (cn-1), C (cn-2))) cn--;c[cn++] = p[i];}lk[0] = 1e30, rk[cn-1] = -1e30;for (int i = 1; I < CN; i++)Lk[i] = rk[i-1] = K (c (i), C (i-1));for (int i = l; I <= R; i++) if (~_q[i]) {int _l = 0, _r = cn-1;Double k = -1.0 * Q (i). x/q (i). Y;While (_l <= _r) {int m = (_l + _r) >> 1;Ans[_q[i]] = max (Ans[_q[i]), LL (C (M). x) * Q (i). x + ll (c (m). Y) * Q (i). y);if (K < lk[m] && Rk[m] < k) {Ans[_q[i]] = max (Ans[_q[i]), LL (C (M). x) * Q (i). x + ll (c (m). Y) * Q (i). y);Break ;}(K < lk[m] && K < rk[m])? _l = m + 1: _r = m-1;}}}void Work () {Build (Root = pt++, 1, N);For (T = 0; T < VN; t++) Modify (Root, 1, N);pn = 0;Solve (Root, 1, N);for (int i = 0; i < qn; i++) Putint (Ans[i]);}void Init () {N = Getint ();qn = vn = 0;memset (_q,-1, sizeof _q);for (int i = 1; I <= N; i++) {int t = getint ();if (t = = 3) {_q[i] = qn;q[qn].x = Getint (), q[qn].y = Getint ();Q[QN++].P = i;} else if (t = = 1) {v[vn].x = Getint (), v[vn].y = Getint ();V[VN].L = i, V[VN++].R = N;} elsev[getint ()-1].R = i;}memset (ans, 0, sizeof ans);}Init ();Work ();return 0;}
---------------------------------------------------------------------------
4311: Vector time limit: Sec Memory limit: MB
Submit: Solved: 26
[Submit] [Status] [Discuss] Description you want to maintain a vector collection that supports the following: 1. Insert a vector (x, y) 2. Delete the inserted vector 3. Query the maximum value of the current collection and (x, y) dot product. If current is an empty set output 0
Input the first line to enter an integer n, indicating the number of operations next n lines, each line first an integer t to denote the type, if t=1, the input vector (x, y), if t=2, the input ID indicates the deletion of the ID vector, otherwise input (x, y), the query and vector (x, y) dot product maximum is what. Ensure that a vector is deleted only once, without deleting the vector that has not been inserted
Output for each t=3 query, export an answer
Sample Input5
1 3 3
1 1 4
3 3 3
2 1
3 3 3Sample Output18
theHINT
n<=200000 1<=x,y<=10^6
Source
Bzoj 4311: Vector (divided by time + line tree)