biyi_mouse @ 2024-12-29 10:32:48
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, int> PDI;
const int N = 100010, Mod1 = 39989, Mod2 = 1e9;
const double eps = 1e-9;
int n, m;
struct line {
double k, b;
} lines[N];
int cnt;
struct Stree {
int l, r, lz;
} tr[N * 4];
double calc(int t, int x) {
return lines[t].k * x + lines[t].b;
}
int cmp(double a, double b) {
if (a - b > eps) return 1;
else if (a - b < eps) return -1;
else return 0;
}
void build(int u, int l, int r) {
tr[u] = {l, r};
if (l == r) return;
int mid = l + r >> 1;
build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r);
}
void add(int x_0, int y_0, int x_1, int y_1) {
cnt ++;
if (x_0 == x_1) lines[cnt] = {0, max(y_0, y_1)};
else lines[cnt].k = 1.0 * (y_1 - y_0) / (x_1 - x_0), lines[cnt].b = y_0 - lines[cnt].k * x_0;
}
void upd(int u, int f) {
int &g = tr[u].lz, mid = tr[u].l + tr[u].r >> 1;
int bmid = cmp(calc(g, mid), calc(f, mid));
if (bmid == -1 || (!bmid && g < f)) swap(g, f);
int bl = cmp(calc(g, tr[u].l), calc(f, tr[u].l)), br = cmp(calc(g, tr[u].r), calc(f, tr[u].r));
if (bl == -1 || (bl == 0 && g < f)) upd(u << 1, f);
if (br == -1 || (br == 0 && f < g)) upd(u << 1 | 1, f);
}
void modify(int u, int l, int r, int f) {
if (l <= tr[u].l && tr[u].r <= r) {
upd(u, f);
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid) modify(u << 1, l, r, f);
if (r > mid) modify(u << 1 | 1, l, r, f);
}
PDI pmax(PDI a, PDI b) {
if (cmp(a.first, b.first) == -1) return b;
else if (cmp(a.first, b.first) == 1) return a;
else return a.second < b.second ? a : b;
}
PDI query(int u, int d) {
if (tr[u].r < d || d < tr[u].l) return {0, 0};
double res = calc(tr[u].lz, d);
if (tr[u].l == tr[u].r) return {res, tr[u].lz};
return pmax({res, tr[u].lz}, pmax(query(u << 1, d), query(u << 1 | 1, d)));
}
int main() {
scanf("%d", &m);
int last = 0;
build(1, 1, Mod1);
while (m --) {
int op; scanf("%d", &op);
if (!op) {
int x; scanf("%d", &x);
x = (x + last - 1 + Mod1) % Mod1 + 1;
last = query(1, x).second;
printf("%d\n", last);
} else {
int x_0, y_0, x_1, y_1;
scanf("%d%d%d%d", &x_0, &y_0, &x_1, &y_1);
x_0 = (x_0 + last - 1 + Mod1) % Mod1 + 1, y_0 = (y_0 + last - 1 + Mod2) % Mod2 + 1;
x_1 = (x_1 + last - 1 + Mod1) % Mod1 + 1, y_1 = (y_1 + last - 1 + Mod2) % Mod2 + 1;
if (x_0 > x_1) swap(x_0, x_1), swap(y_0, y_1);
add(x_0, y_0, x_1, y_1);
modify(1, x_0, x_1, cnt);
}
}
return 0;
}
by biyi_mouse @ 2024-12-29 10:33:33
3
1 1 2 2 1
1 1 1 1 2
0 1
正确输出
1
我的输出
2
by biyi_mouse @ 2024-12-29 11:10:54