裸题。
#include<bits/stdc++.h>
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline void Read(int& x){
char c=nc();
for(;c<'0'||c>'9';c=nc());
for(x=0;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=nc());
}
const int N=100010;
const int M=40010;
const double Eps=1e-10;
struct Line{
double k,b;
}a[N];
int k,n,m,p;
int c[M<<2];
int Ans;
int x,y,z;
inline int Get1(int x){
return (x+Ans-1)%39989+1;
}
inline int Get2(int x){
return (x+Ans-1)%1000000000+1;
}
inline double Calc(int id,int x){
return a[id].k*x+a[id].b;
}
inline double Abs(double x){
return x<0?-x:x;
}
inline bool Cmp(int x,int y,int z){
if(!x)return 1;if(!y)return 0;
double t1=Calc(x,z),t2=Calc(y,z);
if(Abs(t1-t2)<Eps)return x>y;
return t1<t2;
}
void Modify(int x,int l,int r,int y){
if(!c[x])c[x]=y;
if(Cmp(c[x],y,l))swap(c[x],y);
if(l==r||Abs(a[c[x]].k-a[y].k)<Eps)return;
double pos=(a[y].b-a[c[x]].b)/(a[c[x]].k-a[y].k);
if(pos<l||pos>r)return;
int Mid=l+r>>1;
if(pos<=Mid)Modify(x<<1,l,Mid,c[x]),c[x]=y;else Modify(x<<1|1,Mid+1,r,y);
}
void Update(int x,int l,int r,int L,int R,int y){
if(l>R||r<L)return;
if(l>=L&&r<=R){
Modify(x,l,r,y);
return;
}
int Mid=l+r>>1;
Update(x<<1,l,Mid,L,R,y);Update(x<<1|1,Mid+1,r,L,R,y);
}
int Query(int x,int l,int r,int y){
if(l==r)return c[x];
int Mid=l+r>>1,t;
if(y<=Mid)t=Query(x<<1,l,Mid,y);
else t=Query(x<<1|1,Mid+1,r,y);
if(Cmp(t,c[x],y))return c[x];
return t;
}
int main(){
Read(n);
for(int i=1;i<=n;i++){
Read(k);
if(!k){
Read(x);
x=Get1(x);
Ans=Query(1,1,M,x);
printf("%d\n",Ans);
}else{
Read(x);Read(y);Read(z);Read(k);
x=Get1(x);y=Get2(y);z=Get1(z);k=Get2(k);
m++;
if(x==z)a[m].k=0,a[m].b=max(y,k);else
a[m].k=(double)(y-k)/(x-z),a[m].b=-a[m].k*x+y;
if(x>z)swap(x,z);
Update(1,1,M,x,z,m);
}
}
return 0;
}