1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include <bits/stdc++.h> #define x first #define y second #define MAX_N 200000 #define mid ((s+t)>>1) using namespace std; typedef long long lnt; typedef pair<int,int> pnt; template <class T> inline void read(T &w) { w = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (w *= 10) += f*(c-'0'); } int n, m; lnt ans[MAX_N+5]; int p[MAX_N+5], q[MAX_N+5]; pnt qry[MAX_N+5]; vector <pnt*> tr[MAX_N<<2]; pnt* sta[MAX_N+5]; struct operation {pnt p; int l, r;} opr[MAX_N+5]; pnt operator - (const pnt &a, const pnt &b) {return pnt(a.x-b.x, a.y-b.y);} bool operator < (const pnt &a, const pnt &b) {return a.x == b.x ? a.y < b.y : a.x < b.x;} lnt operator * (const pnt &a, const pnt &b) {return 1LL*a.x*b.x+1LL*a.y*b.y;} lnt operator / (const pnt &a, const pnt &b) {return 1LL*a.x*b.y-1LL*a.y*b.x;} bool cmp (const operation &a, const operation &b) {return a.p < b.p;} void insert(int v, int s, int t, int l, int r, pnt *p) { if (s >= l && t <= r) {tr[v].push_back(p); return;} if (l <= mid) insert(v<<1, s, mid, l, r, p); if (r >= mid+1) insert(v<<1|1, mid+1, t, l, r, p); } void bi_solve(int v, int s, int t) { if (s == t) { p[s] = s; for (int i = 0; i < (int)tr[v].size(); i++) ans[s] = max(ans[s], qry[s]*(*tr[v][i])); return; } bi_solve(v<<1, s, mid), bi_solve(v<<1|1, mid+1, t); for (int i = s, p1 = s, p2 = mid+1; i <= t; i++) q[i] = (p2 > t || (p1 <= mid && qry[p[p1]]/qry[p[p2]] <= 0)) ? p[p1++] : p[p2++]; for (int i = s; i <= t; i++) p[i] = q[i]; int tp = 0; for (int i = 0; i < (int)tr[v].size(); sta[++tp] = tr[v][i++]) while (tp > 1 && ((*sta[tp])-(*sta[tp-1]))/((*tr[v][i])-(*sta[tp-1])) >= 0) tp--; if (!tp) return; for (int i = s, c = 1; i <= t; i++) { while (c < tp && qry[p[i]]*(*sta[c+1]) > qry[p[i]]*(*sta[c])) c++; ans[p[i]] = max(ans[p[i]], qry[p[i]]*(*sta[c])); } } int main() { int T; read(T); while (T--) { int opt; read(opt); if (opt == 1) { int xx, yy; read(xx), read(yy); opr[++n].p = pnt(xx, yy); opr[n].l = m+1, opr[n].r = -1; } if (opt == 2) { int id; read(id); opr[id].r = m; } if (opt == 3) { int xx, yy; read(xx), read(yy); qry[++m] = pnt(xx, yy); } } sort(opr+1, opr+n+1, cmp); for (int i = 1; i <= n; i++) { if (opr[i].r == -1) opr[i].r = m; if (opr[i].l > opr[i].r) continue; insert(1, 1, m, opr[i].l, opr[i].r, &opr[i].p); } bi_solve(1, 1, m); for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]); return 0; }
|