1568是3165的弱化版,发的代码是3165的
这道题完全没想出来,是看wyl大神的题解http://hi.baidu.com/wyl8899/item/2deafd3a376ef2d46d15e998
对我完全是一个思维上的突破,之前线段树打的标记基本都是代表整个区间的性质
而这道题区间上的标记只是部分优的线段,通过从叶子一步一步的走到根,得出这个点的最大值

  1 const n=39989;
  2       p=1000000009;
  3 type node=record
  4        k,b:double;
  5      end;
  6 
  7 var tree:array[0..4*n] of longint;
  8     a:array[0..100010] of node;
  9     ans,x0,x1,y0,y1,t,m,ch:longint;
 10 
 11 procedure swap(var a,b:longint);
 12   var c:longint;
 13   begin
 14     c:=a;
 15     a:=b;
 16     b:=c;
 17   end;
 18 
 19 function cal(i,x:longint):double;
 20   begin
 21     exit(a[i].k*x+a[i].b);
 22   end;
 23 
 24 procedure ins(i,l,r,k:longint);
 25   var m:longint;
 26       p:double;
 27   begin
 28     if tree[i]=0 then
 29     begin
 30       tree[i]:=k;
 31       exit;
 32     end;
 33     if cal(k,l)>cal(tree[i],l) then swap(tree[i],k);
 34     if (l=r) or (a[tree[i]].k=a[k].k) then exit;
 35     p:=(a[tree[i]].b-a[k].b)/(a[k].k-a[tree[i]].k);
 36     if (p<l) or (p>r) then exit;
 37     m:=(l+r) shr 1;
 38     if (p<=m) then
 39     begin
 40       ins(i*2,l,m,tree[i]);
 41       tree[i]:=k;
 42     end
 43     else ins(i*2+1,m+1,r,k);
 44   end;
 45 
 46 procedure work(i,l,r:longint);
 47   var m:longint;
 48   begin
 49     if (x0<=l) and (x1>=r) then
 50       ins(i,l,r,t)
 51     else begin
 52       m:=(l+r) shr 1;
 53       if x0<=m then work(i*2,l,m);
 54       if m<x1 then work(i*2+1,m+1,r);
 55     end;
 56   end;
 57 
 58 function ask(i,l,r:longint):longint;
 59   var m,p:longint;
 60   begin
 61     if l=r then exit(tree[i])
 62     else begin
 63       m:=(l+r) shr 1;
 64       if x0<=m then p:=ask(i*2,l,m)
 65       else p:=ask(i*2+1,m+1,r);
 66       if cal(p,x0)>cal(tree[i],x0) then exit(p) else exit(tree[i]);
 67     end;
 68   end;
 69 
 70 begin
 71   readln(m);
 72   while m>0 do
 73   begin
 74     dec(m);
 75     read(ch);
 76     if ch=1 then
 77     begin
 78       readln(x0,y0,x1,y1);
 79       x0:=(x0+ans-1) mod n+1;
 80       x1:=(x1+ans-1) mod n+1;
 81       y0:=(y0+ans-1) mod p+1;
 82       y1:=(y1+ans-1) mod p+1;
 83       if x0>x1 then
 84       begin
 85         swap(x0,x1);
 86         swap(y0,y1);
 87       end;
 88       inc(t);
 89       if x0<>x1 then
 90       begin
 91         a[t].k:=(y1-y0)/(x1-x0);
 92         a[t].b:=y1-a[t].k*x1;
 93       end
 94       else begin
 95         if y1>y0 then a[t].b:=y1 else a[t].b:=y0;
 96       end;
 97       work(1,1,n);
 98     end
 99     else begin
100       readln(x0);
101       x0:=(x0+ans-1) mod n+1;
102       ans:=ask(1,1,n);
103       writeln(ans);
104     end;
105   end;
106 end.
View Code

 

posted on 2015-03-30 21:54  acphile  阅读(156)  评论(0编辑  收藏  举报