Nekopedia @ 2024-01-03 21:44:07
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
ll rd(){
ll x = 0, f = 1; char c = getchar();
while(! isdigit(c)){if(c == '-')f = - f; c = getchar();}
while(isdigit(c)){x = (x << 3) + (x << 1) + (c ^ 48); c = getchar();}
return x * f;
}
const int N = 1e5 + 5, modx = 39989, mody = 1e9;
const db eps = 1e-7;
int n, cnt;
#define ls x << 1
#define rs x << 1 | 1
struct line{
int id;
db k, b;
int l, r, op;
void make_line(int i, db x1, db y1, db x2, db y2){
l = x1, r = x2; id = i;
k = x1 != x2 ? (y1 - y2) / (x1 - x2) : 0;
if(k)b = y1 - k * x1; else b = max(y1, y2);
op = 0;
}
}sgt[N << 2];
struct qwq{
db sum; int num;
};
db calc(line l, int pos){
return l.k * pos + l.b;
}
int cross(line a, line b){
return floor((a.b - b.b) / (b.k - a.k));
}
void mdfy(int x, int l, int r, line k){
if(k.l <= l and r <= k.r){
if(! sgt[x].op)sgt[x] = k, sgt[x].op = 1;
else if(calc(k, l) - calc(sgt[x], l) > eps and calc(k, r) - calc(sgt[x], r) > eps)sgt[x] = k;
else if(calc(k, l) - calc(sgt[x], l) > eps or calc(k, r) - calc(sgt[x], r) > eps){
int mid = l + r >> 1;
if(calc(k, mid) - calc(sgt[x], mid) > eps)swap(sgt[x], k);
if(mid - cross(sgt[x], k) > eps)mdfy(ls, l, mid, k);
else mdfy(rs, mid + 1, r, k);
}
}
else{
int mid = l + r >> 1;
if(k.l <= mid)mdfy(ls, l, mid, k);
if(k.r > mid)mdfy(rs, mid + 1, r, k);
}
}
qwq qry(int x, int l, int r, int pos){
db res = calc(sgt[x], pos); int ans = sgt[x].id;
if(l == r)return {res, ans};
int mid = l + r >> 1; qwq tmp;
if(pos <= mid){
tmp = qry(ls, l, mid, pos);
if(res > tmp.sum)tmp = {res, ans};
}
else{
tmp = qry(rs, mid + 1, r, pos);
if(res > tmp.sum)tmp = {res, ans};
}
return tmp;
}
signed main(){
n = rd(); int ans = 0;
for(int i = 1; i <= n; ++i){
int op = rd(), pos, x1, x2, y1, y2;
if(! op){
pos = (rd() + ans - 1) % modx + 1;
printf("%d\n", ans = qry(1, 1, n, pos).num);
}
else{
x1 = (rd() + ans - 1) % modx + 1;
y1 = (rd() + ans - 1) % mody + 1;
x2 = (rd() + ans - 1) % modx + 1;
y2 = (rd() + ans - 1) % mody + 1;
line tmp; tmp.make_line(++cnt, x1, y1, x2, y2);
mdfy(1, 1, n, tmp);
}
}
return 0;
}
by Jeefy @ 2024-01-04 10:42:11
你这写法太容易错了,建议换一个板子。
https://www.luogu.com.cn/paste/xf9nm13c
推销我的 /doge
by Nekopedia @ 2024-01-04 23:03:10
@Jeefy 谢谢你qwq