RT,前三个全部AC,在大数据的地方挂掉了/kk
求助dalao/kel
#include<cstdio>
typedef double db;
const int M=40000,mod1=39989,mod2=1e9;
int n,lst,cnt;
inline void mod(int&x,const int&Mod){
x=x+lst-1>=Mod?x+lst-Mod:x+lst;
}
struct line{
db k,b;int p;
line(const db&k=0,const int&x1=0,const int&y1=0,const int&p=0):k(k),b(y1-x1*k),p(p){}
inline db calc(const int&x)const{
return k*x+b;
}
inline bool empty()const{
return!p;
}
}t[M<<2];
inline void swap(line&a,line&b){
line c=a;a=b;b=c;
}
inline line max(const line&a,const line&b,const int&x){
return a.calc(x)>b.calc(x)+(a.p>b.p?1e-12:-1e-12)?a:b;
}
void pushdown(int u,int L,int R,line lie){
int mid=L+R>>1;
if(t[u].empty())t[u]=lie;
else{
if(lie.calc(mid)>t[u].calc(mid))swap(lie,t[u]);
if(lie.calc(L)>t[u].calc(L))pushdown(u<<1,L,mid,lie);
else if(lie.calc(R)>t[u].calc(R))pushdown(u<<1|1,mid+1,R,lie);
}
}
line Query(int u,int x,int L=1,int R=M){
if(L==R)return t[u];
int mid=L+R>>1;
if(x<=mid)return max(t[u],Query(u<<1,x,L,mid),x);
return max(t[u],Query(u<<1|1,x,mid+1,R),x);
}
void Modify(int u,int l,int r,line lie,int L=1,int R=M){
if(r<L||R<l)return;
if(l<=L&&R<=r)return pushdown(u,L,R,lie);
int mid=L+R>>1;
Modify(u<<1,l,r,lie,L,mid);
Modify(u<<1|1,l,r,lie,mid+1,R);
}
signed main(){
register int i,x1,y1,x2,y2,opt;
scanf("%d",&n);
for(i=1;i<=n;++i){
scanf("%d",&opt);
if(!opt){
scanf("%d",&x1);mod(x1,mod1);
printf("%d\n",lst=Query(1,x1).p);
}
else{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
mod(x1,mod1);mod(x2,mod1);
mod(y1,mod2);mod(y2,mod2);
if(x1>x2)x1^=x2^=x1^=x2,y1^=y2^=y1^=y2;
Modify(1,x1,x2,line(1.0*(y2-y1)/(x2-x1),x1,y1,++cnt));
}
}
}