YWHHDJSer @ 2024-09-03 11:19:10
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define inf 1e9
int a,in,ans,cnt,h,i,j,k;
struct node0
{
long double kk,bb;
}line[200002];
struct node1
{
int left,right,num;
}tree[200002];
il void pre(int &x)
{
x=(x+ans-1)%39989+1;
}
il int cmp(long double x,long double y)
{
if(x-y>=0)
{
if(x-y<1e-9)
{
return 0;
}
else
{
return 1;
}
}
else
{
if(x-y>-1e-9)
{
return 0;
}
else
{
return -1;
}
}
}
il void adlin(int x1,int y1,int x2,int y2)
{
cnt++;
if(x1==x2)
{
line[cnt]={0.0,(long double)max(y1,y2)};
}
else
{
line[cnt].kk=(y2-y1)*1.0/(x2-x1);
line[cnt].bb=y1-line[cnt].kk*x1;
}
}
il long double got(int x,int y)
{
return x*line[y].kk+line[y].bb;
}
il long double fid(int x,int y)
{
return (line[y].bb-line[x].bb)/(line[x].kk-line[y].kk);
}
il int lft(int x)
{
return x<<1;
}
il int iht(int x)
{
return x<<1|1;
}
void maktre(int x,int lt,int rt)
{
tree[x].left=lt;
tree[x].right=rt;
if(lt==rt)
{
return;
}
ri me=(lt+rt)>>1;
maktre(lft(x),lt,me);
maktre(iht(x),me+1,rt);
}
void adtre(int x,int lt,int rt,int y)
{
ri me=(tree[x].left+tree[x].right)>>1;
if(lt<=tree[x].left&&tree[x].right<=rt)
{
if(!tree[x].num)
{
tree[x].num=y;
return;
}
register long double l1=got(tree[x].left,y),l2=got(tree[x].left,tree[x].num),r1=got(tree[x].right,y),r2=got(tree[x].right,tree[x].num);
if(cmp(l1,l2)<=0&&cmp(r1,r2)<=0)
{
return;
}
if(cmp(l1,l2)>0&&cmp(r1,r2)>0)
{
tree[x].num=y;
return;
}
if(cmp(l1,l2)>0)
{
if(cmp(fid(y,tree[x].num),me)<=0)
{
adtre(lft(x),lt,rt,y);
}
else
{
adtre(iht(x),lt,rt,tree[x].num);
tree[x].num=y;
}
}
else
{
if(cmp(fid(y,tree[x].num),me)>0)
{
adtre(iht(x),lt,rt,y);
}
else
{
adtre(lft(x),lt,rt,tree[x].num);
tree[x].num=y;
}
}
return;
}
if(lt<=me)
{
adtre(lft(x),lt,rt,y);
}
if(rt>me)
{
adtre(iht(x),lt,rt,y);
}
}
il int foudstr(int x,int pl)
{
if(tree[x].left==tree[x].right)
{
return tree[x].num;
}
ri me=(tree[x].left+tree[x].right)>>1,rn;
if(pl<=me)
{
rn=foudstr(lft(x),pl);
}
else
{
rn=foudstr(iht(x),pl);
}
if(cmp(got(pl,rn),got(pl,tree[x].num))<0)
{
rn=tree[x].num;
}
if(cmp(got(pl,rn),got(pl,tree[x].num))==0)
{
rn=min(rn,tree[x].num);
}
return rn;
}
int main()
{
// cout<<(double)-1000000000.0;
scanf("%d",&a);
line[0]={0.0,-inf};
maktre(1,1,40000);
while(a--)
{
scanf("%d",&in);
if(!in)
{
scanf("%d",&h);
pre(h);
// cout<<h<<'\n';
ans=foudstr(1,h);
// cout<<"k="<<h<<'\n';
printf("%d\n",ans);
}
else
{
scanf("%d%d%d%d",&h,&i,&j,&k);
pre(h),pre(i),pre(j),pre(k);
if(h>j)
{
swap(h,j);
swap(i,k);
}
// cout<<h<<' '<<i<<' '<<j<<' '<<k<<'\n';
adlin(h,i,j,k);
adtre(1,h,j,cnt);
}
}
return 0;
}
/*
114
1 1 1 20 20
1 1 19 20 0
0 10
*/
Sub1WA#3,Sub2全WA。
by YWHHDJSer @ 2024-09-03 12:11:30
一组Hack:
5
1 1 20 14 8
1 1 13 20 20
1 1 20 6 18
1 1 20 20 9
0 1
by YWHHDJSer @ 2024-09-04 14:33:47