[李超线段树] BZOJ 3165: [Heoi2013]Segment
2017-12-14 13:02
309 查看
Solution
裸题。。。刚开始求线段交点求错了,心态崩了
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int N = 101010; const int M1 = 39989; const int M2 = 1000000000; typedef pair<int, int> Pairs; inline char get(void) { static char buf[100000], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, 100000, stdin); if (S == T) return EOF; } return *S++; } template<typename T> inline void read(T &x) { static char c; x = 0; int sgn = 0; for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1; for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0'; if (sgn) x = -x; } int info[N << 2]; double k , b ; int n, m, opt, ans; int x1, z1, x2, z2; double mx; inline bool cmp(int i1, int i2, int x0) { double y1 = k[i1] * x0 + b[i1], y2 = k[i2] * x0 + b[i2]; return y1 + eps < y2; } inline double cross(int i1, int i2) { return (b[i2] - b[i1]) / (k[i1] - k[i2]); } inline void Insert(int o, int l, int r, int L, int R, int id) { if (l >= L && r <= R) { int d1 = cmp(info[o], id, l), d2 = cmp(info[o], id, r); if (d1 && d2) return (void)(info[o] = id); if (!d1 && !d2) return; if (l == r) return; int mid = (l + r) >> 1; double pos = cross(id, info[o]); if (pos <= mid) { if (d2) Insert(o << 1, l, mid, L, R, info[o]); else Insert(o << 1, l, mid, L, R, id); if (d2) info[o] = id; } else { if (d1) Insert(o << 1 | 1, mid + 1, r, L, R, info[o]); else Insert(o << 1 | 1, mid + 1, r, L, R, id); if (d1) info[o] = id; } return; } int mid = (l + r) >> 1; if (L <= mid) Insert(o << 1, l, mid, L, R, id); if (R > mid) Insert(o << 1 | 1, mid + 1, r, L, R, id); } inline void Query(int o, int l, int r, int x0) { if (k[info[o]] * x0 + b[info[o]] - eps > mx) { mx = k[info[o]] * x0 + b[info[o]]; ans = info[o]; } if (fabs(k[info[o]] * x0 + b[info[o]] - mx) < eps && info[o] < ans) { ans = info[o]; } if (l == r) return; int mid = (l + r) >> 1; if (x0 <= mid) Query(o << 1, l, mid, x0); else Query(o << 1 | 1, mid + 1, r, x0); } int main(void) { freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); read(n); while (n--) { read(opt); if (opt) { read(x1); read(z1); read(x2); read(z2); x1 = (x1 + ans - 1) % M1 + 1; x2 = (x2 + ans - 1) % M1 + 1; z1 = (z1 + ans - 1) % M2 + 1; z2 = (z2 + ans - 1) % M2 + 1; if (x1 > x2) swap(x1, x2), swap(z1, z2); k[++m] = (double)(z2 - z1) / (x2 - x1); b[m] = z1 - x1 * k[m]; Insert(1, 1, M1, x1, x2, m); } else { mx = -1e18; read(x1); x1 = (x1 + ans - 1) % M1 + 1; Query(1, 1, M1, x1); printf("%d\n", ans); } } return 0; }
相关文章推荐
- [李超线段树] BZOJ3165 [Heoi2013]. Segment
- [bzoj3165][Heoi2013]Segment——李超线段树
- 【BZOJ 3165】 [Heoi2013]Segment 李超线段树
- 【李超线段树】BZOJ3165 [Heoi2013]Segment
- BZOJ 3165 Heoi2013 Segment 线段树
- BZOJ_3165_[Heoi2013]Segment_线段树
- bzoj 3165: [Heoi2013]Segment 线段树
- 【bzoj3165】[Heoi2013]Segment 神奇的线段树
- 【bzoj3165】【HEOI2013】【Segment】【线段树】
- [线段树] BZOJ 3165: [Heoi2013]Segment
- 【BZOJ 3165】【HEOI 2013】Segment
- BZOJ3165 [Heoi2013]Segment
- BZOJ3165: [Heoi2013]Segment
- BZOJ 3165: [Heoi2013]Segment
- 3165: [Heoi2013]Segment 线段树 标记永久化
- 李超线段树 [Heoi2013]Segment
- bzoj 3165: [Heoi2013]Segment
- BZOJ3165 : [Heoi2013]Segment
- BZOJ 3165: [Heoi2013]Segment 标记永久化
- 【李超线段树】BZOJ3165(Heoi2013)[Segment]题解