当初只会暴力,现在差不多觉得水了
显然离线处理,对输入的数排序然后会发现不管怎么修改都是结果总是单调不降的
对于每次处理,我们只要找到那段越界的即可
显然上线段树,话说jsoi这么喜欢线段树?
下面在bzoj上过不去,因为pascal编译器处理比较严格,可能某处爆了int64,我也懒得查了,本地是能过的

  1 type node=record
  2        mi,mx,att,mul,an:int64;
  3      end;
  4 
  5 var tree:array[0..100100*4] of node;
  6     ans,b,c:array[0..100100] of longint;
  7     a:array[0..100100] of int64;
  8     ch:array[0..100100] of char;
  9     m,f,t,i,n: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 procedure sort(l,r:longint);
 20   var i,j:longint;
 21       x,y:int64;
 22 
 23   begin
 24     i:=l;
 25     j:=r;
 26     x:=a[(l+r) shr 1];
 27     repeat
 28       while a[i]<x do inc(i);
 29       while x<a[j] do dec(j);
 30       if not(i>j) then
 31       begin
 32         y:=a[i]; a[i]:=a[j]; a[j]:=y;
 33         swap(c[i],c[j]);
 34         inc(i);
 35         dec(j);
 36       end;
 37     until i>j;
 38     if l<j then sort(l,j);
 39     if i<r then sort(i,r);
 40   end;
 41 
 42 procedure cal(i,x,y:longint;x1,x2,x3:int64);
 43   begin
 44     with tree[i] do
 45     begin
 46       mi:=mi*x1+x2*a[x]+x3;
 47       mx:=mx*x1+x2*a[y]+x3;
 48       mul:=mul*x1;
 49       att:=att*x1;
 50       an:=an*x1;
 51       att:=att+x2;
 52       an:=an+x3;
 53     end;
 54   end;
 55 
 56 procedure build(i,l,r:longint);
 57   var m:longint;
 58   begin
 59     tree[i].mi:=a[l];
 60     tree[i].mx:=a[r];
 61     tree[i].mul:=1;
 62     if l<>r then
 63     begin
 64       m:=(l+r) shr 1;
 65       build(i*2,l,m);
 66       build(i*2+1,m+1,r);
 67     end;
 68   end;
 69 
 70 procedure push(i,l,r:longint);
 71   var m:longint;
 72   begin
 73     m:=(l+r) shr 1;
 74     with tree[i] do
 75     begin
 76       cal(i*2,l,m,mul,att,an);
 77       cal(i*2+1,m+1,r,mul,att,an);
 78       mul:=1;
 79       att:=0;
 80       an:=0;
 81     end;
 82   end;
 83 
 84 procedure max(i,l,r:longint);
 85   var m:longint;
 86   begin
 87     if l=r then cal(i,l,l,0,0,t)
 88     else begin
 89       m:=(l+r) shr 1;
 90       push(i,l,r);
 91       if tree[i*2].mx>t then
 92       begin
 93         cal(i*2+1,m+1,r,0,0,t);
 94         max(i*2,l,m);
 95       end
 96       else max(i*2+1,m+1,r);
 97       tree[i].mx:=tree[i*2+1].mx;
 98       tree[i].mi:=tree[i*2].mi;
 99     end;
100   end;
101 
102 procedure min(i,l,r:longint);
103   var m:longint;
104   begin
105     if l=r then cal(i,l,l,0,0,f)
106     else begin
107       m:=(l+r) shr 1;
108       push(i,l,r);
109       if tree[i*2+1].mi<f then
110       begin
111         cal(i*2,l,m,0,0,f);
112         min(i*2+1,m+1,r);
113       end
114       else min(i*2,l,m);
115       tree[i].mx:=tree[i*2+1].mx;
116       tree[i].mi:=tree[i*2].mi;
117     end;
118   end;
119 
120 procedure ask(i,l,r:longint);
121   var m:longint;
122   begin
123     if l=r then
124       ans[c[l]]:=tree[i].mx
125     else begin
126       m:=(l+r) shr 1;
127       push(i,l,r);
128       ask(i*2,l,m);
129       ask(i*2+1,m+1,r);
130     end;
131   end;
132 
133 begin
134   readln(m,f,t);
135   for i:=1 to m do
136     readln(ch[i],b[i]);
137   readln(n);
138   for i:=1 to n do
139   begin
140     readln(a[i]);
141     if a[i]>t then a[i]:=t;
142     if a[i]<f then a[i]:=f;
143     c[i]:=i;
144   end;
145   sort(1,n);
146   build(1,1,n);
147   for i:=1 to m do
148     if ch[i]='+' then
149     begin
150       cal(1,1,n,1,0,b[i]);
151       if tree[1].mx>t then max(1,1,n);
152     end
153     else if ch[i]='-' then
154     begin
155       cal(1,1,n,1,0,-b[i]);
156       if tree[1].mi<f then min(1,1,n);
157     end
158     else if ch[i]='*' then
159     begin
160       cal(1,1,n,b[i],0,0);
161       if tree[1].mx>t then max(1,1,n);
162     end
163     else begin
164       cal(1,1,n,1,b[i],0);
165       if tree[1].mx>t then max(1,1,n);
166     end;
167   ask(1,1,n);
168   for i:=1 to n do
169     writeln(ans[i]);
170 end.
171 
172  
View Code

 

posted on 2015-04-04 22:43  acphile  阅读(249)  评论(0编辑  收藏  举报