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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| #include <iostream> #include <algorithm> #include <map> #include <cstdio> #define ls(x) (x << 1) #define rs(x) (x << 1 | 1) #define int long long
using namespace std;
const int N = 5e5 + 10;
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
struct Vector { int x, y;
friend bool operator < (Vector A, Vector B) { return 1ll * A.x * B.y - 1ll * A.y * B.x > 0; } friend bool operator == (Vector A, Vector B) { return 1ll * A.x * B.y - 1ll * A.y * B.x == 0; } };
int n; pair<int, int> val[4 * N + 20];
struct Segementtree {
Segementtree (int _n) { n = _n; std::fill(val, val + 4 * N + 1, make_pair(0x3f3f3f3f, 0)); }
void resize(int _n) { n = _n; std::fill(val, val + 4 * N + 1, make_pair(0x3f3f3f3f, 0)); }
pair<int, int> operator [] (int i) { return val[i]; }
void change(int x, int y, pair<int, int> v, int u = 1, int l = 1, int r = n) { if (x <= l && r <= y) return val[u] = min(val[u], v), void(); int mid = (l + r) >> 1; if (x <= mid) change(x, y, v, ls(u), l, mid); if (y > mid) change(x, y, v, rs(u), mid + 1, r); }
pair<int, int> query(int x, int u = 1, int l = 1, int r = n) { if (l == r) return val[u]; pair<int, int> res = val[u]; int mid = (l + r) >> 1; if (x <= mid) res = min(res, query(x, ls(u), l, mid)); else res = min(res, query(x, rs(u), mid + 1, r)); return res; } };
int Q; Vector tmp[N]; int tot; Vector VL[N], VR[N], VX[N]; int op[N], l[N], r[N], u[N], d[N], x[N], y[N]; int pos[N], L[N], R[N], V[N]; int X[N]; pair<int, int> ansl[N], ansd[N]; map<int, int> Mapl, Mapd;
signed main() { scanf("%lld", &Q); for (int i = 1; i <= Q; ++i) { scanf("%lld", &op[i]); if (op[i] == 1) { scanf("%lld%lld%lld%lld", &l[i], &d[i], &r[i], &u[i]); tmp[++tot] = Vector{l[i], d[i]}; VL[i] = tmp[tot]; tmp[++tot] = Vector{l[i], u[i]}; VR[i] = tmp[tot]; } else { scanf("%lld%lld", &x[i], &y[i]); tmp[++tot] = Vector{x[i], y[i]}; VX[i] = tmp[tot]; } } sort(tmp + 1, tmp + tot + 1); for (int i = 1; i <= Q; ++i) { if (op[i] == 1) { L[i] = std::lower_bound(tmp + 1, tmp + tot + 1, VL[i]) - tmp; R[i] = std::lower_bound(tmp + 1, tmp + tot + 1, VR[i]) - tmp; V[i] = l[i]; } else { X[i] = std::lower_bound(tmp + 1, tmp + tot + 1, VX[i]) - tmp; } } Segementtree st(tot + 1); for (int i = 1; i <= Q; ++i) { if (op[i] == 1) { if (l[i] == 0) continue; st.change(L[i], R[i], make_pair(V[i], -i)); } else { if (x[i] == 0) continue; ansl[i] = st.query(X[i]); } } tot = 0; for (int i = 1; i <= Q; ++i) { if (op[i] == 1) { tmp[++tot] = Vector{r[i], d[i]}; VL[i] = tmp[tot]; tmp[++tot] = Vector{l[i], d[i]}; VR[i] = tmp[tot]; } else { tmp[++tot] = Vector{x[i], y[i]}; VX[i] = tmp[tot]; } } sort(tmp + 1, tmp + tot + 1); for (int i = 1; i <= Q; ++i) { if (op[i] == 1) { L[i] = lower_bound(tmp + 1, tmp + tot + 1, VL[i]) - tmp; R[i] = lower_bound(tmp + 1, tmp + tot + 1, VR[i]) - tmp; V[i] = d[i]; } else { X[i] = lower_bound(tmp + 1, tmp + tot + 1, VX[i]) - tmp; } } st.resize(tot + 1); for (int i = 1; i <= Q; ++i) { if (op[i] == 1) { if (d[i] == 0) continue; st.change(L[i], R[i], make_pair(V[i], -i)); } else { if (y[i] == 0) continue; ansd[i] = st.query(X[i]); } } for (int i = 1; i <= Q; ++i) { if (op[i] == 2) { if (1ll * ansl[i].first * y[i] == 1ll * x[i] * ansd[i].first) { printf("%lld\n", max(-ansl[i].second, -ansd[i].second)); } else if (1ll * ansl[i].first * y[i] < 1ll * x[i] * ansd[i].first) { printf("%lld\n", -ansl[i].second); } else { printf("%lld\n", -ansd[i].second); } } } return 0; }
|