1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
   | #include<iostream> #include<cstdio> #define ll long long using namespace std;
  const ll mo=39989,ymo=1e9,N=1e5;
  ll n,op,lastans,xa,ya,xb,yb,tot;
  double k[N+5],b[N+5];
  struct lcsgt{   ll best;   #define best(x) tree[x].best }tree[mo*4+5];
  inline double f(ll id,ll x) {return k[id]*x+b[id];}
  inline void ask(ll p,ll lp,ll rp,ll x) {   double fnow=f(lastans,x),fp=f(best(p),x);   if(fp>fnow||(fp==fnow&&best(p)<lastans)) {lastans=best(p);}   if(lp==rp) return;   ll mid=(lp+rp)>>1;   if(x<=mid) ask(p<<1,lp,mid,x);   if(x>mid) ask(p<<1|1,mid+1,rp,x); }
  inline void ins(ll p,ll lp,ll rp,ll l,ll r,ll now) {   ll mid=(lp+rp)>>1;   double fnow=f(now,mid),fp=f(best(p),mid);   if(lp>=l&&rp<=r) {     if(lp==rp) {if(fnow>fp) best(p)=now;return;}     if(k[now]>k[best(p)]) {       if(fnow>fp) {ins(p<<1,lp,mid,l,r,best(p));best(p)=now;}       else ins(p<<1|1,mid+1,rp,l,r,now);     }     else if(k[now]<k[best(p)]) {       if(fnow>fp) {ins(p<<1|1,mid+1,rp,l,r,best(p));best(p)=now;}       else ins(p<<1,lp,mid,l,r,now);     }     else if(b[now]>b[best(p)]) best(p)=now;     return;   }   if(l<=mid) ins(p<<1,lp,mid,l,r,now);   if(r>mid) ins(p<<1|1,mid+1,rp,l,r,now); }
  inline ll read() {   ll ret=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9') {if(ch=='-') f=-f;ch=getchar();}   while(ch>='0'&&ch<='9') {ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}   return ret*f; }
  inline void write(ll x) {   static char buf[22];static ll len=-1;   if(x>=0) {     do{buf[++len]=x%10+48;x/=10;}while(x);   }   else {     putchar('-');     do{buf[++len]=-(x%10)+48;x/=10;}while(x);   }   while(len>=0) putchar(buf[len--]); }
  inline void writeln(ll x) {   write(x);putchar('\n'); }
  int main() {
    n=read();
    while(n--) {     op=read();     if(op==0) {       ll K=read();K=(K+lastans-1+mo)%mo+1;       lastans=0;ask(1,1,mo,K);       writeln(lastans);     }     if(op==1) {       xa=read();ya=read();xb=read();yb=read();       xa=(xa+lastans-1+mo)%mo+1;xb=(xb+lastans-1+mo)%mo+1;       ya=(ya+lastans-1+ymo)%ymo+1;yb=(yb+lastans-1+ymo)%ymo+1;       if(xa>xb) {swap(xa,xb);swap(ya,yb);}       if(xa==xb) {k[++tot]=0;b[tot]=max(ya,yb);}       else {         k[++tot]=(double)(ya-yb)/(xa-xb);b[tot]=(double)(xa*yb-xb*ya)/(xa-xb);       }       ins(1,1,mo,xa,xb,tot);     }   }
    return 0; }
   |