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
| #include <bits/stdc++.h> #define R 40000 #define P1 39989 #define P2 1000000000 #define INF 0x3f3f3f3f #define mid ((s+t)>>1) using namespace std; typedef double dnt; template <class T> inline void read(T &x) { x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } struct line {int id; dnt k, b;} tr[R<<2]; dnt calc(line l, int x) {return l.k*x+l.b;} line max(line a, line b, int x) { dnt val1 = calc(a, x), val2 = calc(b, x); if (val1 == val2) return a.id < b.id ? a : b; return val1 > val2 ? a : b; } void insert(int v, int s, int t, line L) { if (!tr[v].id) {tr[v] = L; return;} line a = tr[v], b = L; dnt sa = calc(a, s), sb = calc(b, s); dnt ta = calc(a, t), tb = calc(b, t); if (sa >= sb && ta >= tb) {tr[v] = a; return;} if (sa <= sb && ta <= tb) {tr[v] = b; return;} dnt p = (a.b-b.b)/(b.k-a.k); if (sa > sb) { if (p <= (dnt)mid) insert(v<<1, s, mid, a), tr[v] = b; if (p > (dnt)mid) insert(v<<1|1, mid+1, t, b),tr[v] = a; } else { if (p <= (dnt)mid) insert(v<<1, s, mid, b), tr[v] = a; if (p > (dnt)mid) insert(v<<1|1, mid+1, t, a), tr[v] = b; } } void modify(int v, int s, int t, int l, int r, line L) { if (s >= l && t <= r) {insert(v, s, t, L); return;} if (l <= mid) modify(v<<1, s, mid, l, r, L); if (r >= mid+1) modify(v<<1|1, mid+1, t, l, r, L); } line query(int v, int s, int t, int x) { if (s == t) return tr[v]; line ret; if (x <= mid) ret = query(v<<1, s, mid, x); if (x >= mid+1) ret = query(v<<1|1, mid+1, t, x); return max(tr[v], ret, x); } int main() { int T, n = 0; read(T), tr[0].b = (dnt)-INF; for (int lst = 0; T; T--) { int opt; read(opt); if (opt == 0) { int x; read(x), x = (x+lst-1)%P1+1; line res = query(1, 1, R, x); printf("%d\n", lst = res.id); } if (opt == 1) { int x0, y0, x1, y1; dnt k, b; read(x0), x0 = (x0+lst-1)%P1+1; read(y0), y0 = (y0+lst-1)%P2+1; read(x1), x1 = (x1+lst-1)%P1+1; read(y1), y1 = (y1+lst-1)%P2+1; if (x0 > x1) swap(x0, x1), swap(y0, y1); if (x0 == x1) k = 0, b = max(y0, y1); else k = 1.0*(y0-y1)/(x0-x1), b = y0-k*x0; modify(1, 1, R, x0, x1, (line){++n, k, b}); } } return 0; }
|