WA #5,14,16,17 求调
查看原帖
WA #5,14,16,17 求调
489890
SFlyer楼主2024/3/28 22:50
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int M1 = 39989;
const int M2 = 1e9;
const int N = 1e5+5;
const ld eps = 1e-9;

struct line {
	ld k,b;
} p[N];

int cmp(ld x,ld y){
	if (x-y>eps){
		return 1;
	}
	if (y-x>eps){
		return -1;
	}
	return 0;
}

int cnt,s[N<<2];

ld cal(int id,ld x){
	return p[id].k*x+p[id].b;
}

void ins(int x0,int y0,int x1,int y1){
	cnt++;
	if (x0==x1){
		p[cnt].k=0;
		p[cnt].b=max(y0,y1);
	}
	else{
		p[cnt].k=1.*(y1-y0)/(x1-x0);
		p[cnt].b=y0-p[cnt].k*x0;
	}
}

void upd(int rt,int l,int r,int u){
	int &v=s[rt];
	int mid=l+r>>1;
	int bm=cmp(cal(u,mid),cal(v,mid));
	if (bm==1 || (!bm && u<v)){
		swap(u,v);
	}
	int bl=cmp(cal(u,l),cal(v,l));
	int br=cmp(cal(u,r),cal(v,r));
	if (bl==1 || (!bl && u<v)){
		upd(rt<<1,l,mid,u);
	}
	if (br==1 || (!br && u<v)){
		upd(rt<<1|1,mid+1,r,u);
	}
}

void upd(int rt,int cl,int cr,int l,int r,int u){
	if (l==r){
		
	}
	if (l<=cl && cr<=r){
		upd(rt,cl,cr,u);
		return;
	}
	int mid=cl+cr>>1;
	if (l<=mid){
		upd(rt<<1,cl,mid,l,r,u);
	}
	if (mid<r){
		upd(rt<<1|1,mid+1,cr,l,r,u);
	}
}

pair<int,int> lar(pair<int,int> x,pair<int,int> y){
	int t=cmp(x.first,y.first);
	if (t==-1){
		return y;
	}
	else if (t==1){
		return x;
	}
	return x.second<y.second?x:y; 
}

pair<int,int> qy(int rt,int l,int r,int d){
	if (r<d || d<l){
		return {0,0};
	}
	int mid=l+r>>1;
	ld res=cal(s[rt],d);
	if (l==r){
		return {res,s[rt]};
	}
	return lar({res,s[rt]},lar(qy(rt<<1,l,mid,d),qy(rt<<1|1,mid+1,r,d)));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,lsta=0;
	cin>>n;
	while (n--){
		int op;
		cin>>op;
		if (op==1){
			int x0,y0,x1,y1;
			cin>>x0>>y0>>x1>>y1;
			x0=(x0+lsta-1+M1)%M1+1;
			x1=(x1+lsta-1+M1)%M1+1;
			y0=(y0+lsta-1+M2)%M2+1;
			y1=(y1+lsta-1+M2)%M2+1;
			if (x0>x1){
				swap(x0,x1);
				swap(y0,y1);
			}
			ins(x0,y0,x1,y1);
			upd(1,1,M1,x0,x1,cnt);
		}
		else{
			int x;
			cin>>x;
			x=(x+lsta-1+M1)%M1+1;
			cout<<(lsta=qy(1,1,M1,x).second)<<"\n";
		}
	}
	return 0;
}
``
2024/3/28 22:50
加载中...