标签:
经典的splay维护凸壳,但是看了看zky学长的题解最后决定写线段树维护标记永久化。
Round1考到了这个之后一直没有理解标记永久化,CTSC也因为自己的缺陷丢掉了一些部分分,so sad
看来以后不懂的东西要及时学啊QwQ
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { double k, b; bool p; node(int xa = 0, int ya = 0, int xb = 0, int yb = 0, bool num = 0) { p = num; if (xa == xb) {k = 0; b = max(ya, yb);} else {k = (ya - yb) / (xa - xb); b = ya - xa * k;} } double get(int x) {return k * x + b;} }; bool lessthan(node A, node B, double x) { if (!A.p) return 1; double na = A.get(x), nb = B.get(x); return na == nb ? A.p < B.p : na < nb; } int n = 50000; node T[200003]; node Q(int rt, int l, int r, int pos) { if (l == r) return T[rt]; node tmp; int mid = (l + r) >> 1; tmp = (pos <= mid) ? Q(rt << 1, l, mid, pos) : Q(rt << 1 | 1, mid + 1, r, pos); return lessthan(T[rt], tmp, pos) ? tmp : T[rt]; } void ins2(int rt, int l, int r, node se) { if (!T[rt].p) {T[rt] = se; return;} if (lessthan(T[rt], se, l)) swap(T[rt], se); if (l == r || T[rt].k == se.k) return; //!!! double x = (T[rt].b - se.b) / (se.k - T[rt].k); int mid = (l + r) >> 1; if (x < l || x > r) return; if (x <= mid) ins2(rt << 1, l, mid, T[rt]), T[rt] = se; else ins2(rt << 1 | 1, mid + 1, r, se); } void ins1(int rt, int l, int r, int L, int R, node se) { if (L <= l && r <= R) {ins2(rt, l, r, se); return;} int mid = (l + r) >> 1; if (L <= mid) ins1(rt << 1, l, mid, L, R, se); if (R > mid) ins1(rt << 1 | 1, mid + 1, r, L, R, se); } int main() { double S, P; node tmp; int T, pos; scanf("%d", &T); char c[15]; while (~scanf("%s", c)) { if (c[0] == ‘Q‘) { scanf("%d", &pos); printf("%lld\n", (long long) (Q(1, 1, n, pos).get(pos) / 100 + 1e-8)); } else { scanf("%lf%lf", &S, &P); tmp.k = P; tmp.b = S - P; tmp.p = 1; ins1(1, 1, n, 1, n, tmp); } } return 0; }
Round2加油吧ovo
【BZOJ 1568】【JSOI 2008】Blue Mary开公司
标签:
原文地址:http://www.cnblogs.com/abclzr/p/5463539.html