码迷,mamicode.com
首页 > 其他好文 > 详细

3211: 花神游历各国

时间:2015-02-02 00:30:34      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

3211: 花神游历各国

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 1042  Solved: 381
[Submit][Status]

Description

 

Input

 

Output

每次x=1时,每行一个整数,表示这次旅行的开心度

 

Sample Input

4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output

101

11

11

HINT

 

对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9


 

 

Source

 
题解:嗯哼!!!果然是加强版的数据,可惜还是一遍AC了(HansBug:^_^,咦?最近phile呢?),其实和“上帝造题的7分钟2”基本上一样,就是它的强化版,重点在于处理优化掉一些不必要的操作即可(比如当某区间内的数字全部<=1呵呵呵),具体不再赘述,详见我的代码模板:线段树5(传送门在此)
 
 1 var
 2    i,j,k,l,m,n:longint;
 3    a,b:array[0..1000000] of int64;
 4 function max(x,y:longint):longint;inline;
 5          begin
 6               if x>y then max:=x else max:=y;
 7          end;
 8 function min(x,y:longint):longint;inline;
 9          begin
10               if x<y then min:=x else min:=y;
11          end;
12 
13 procedure built(z,x,y:longint);inline;
14           begin
15                if (x=y) then
16                   begin
17                        read(a[z]);
18                        if a[z]<=1 then b[z]:=1 else b[z]:=0;
19                   end
20                else
21                    begin
22                         built(z*2,x,(x+y) div 2);
23                         built(z*2+1,(x+y) div 2+1,y);
24                         a[z]:=a[z*2]+a[z*2+1];
25                         if (b[z*2]=1) and (b[z*2+1]=1) then b[z]:=1 else b[z]:=0;
26                    end;
27           end;
28 function op(z,x,y,l,r:longint):int64;inline;
29          var a2,a3:int64;
30          begin
31               if l>r then exit(0);
32               if b[z]=1 then exit(0);
33               if (x=l) and (y=r) and (l=r) then
34                  begin
35                       a2:=a[z];
36                       a[z]:=trunc(sqrt(a[z]));
37                       if a[z]<=1 then b[z]:=1;
38                       exit(a[z]-a2);
39                  end;
40               a2:=op(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2));
41               a3:=op(z*2+1,(x+y) div 2+1,y,max((x+y) div 2+1,l),r);
42               a[z]:=a[z]+a2+a3;
43               if (b[z*2]=1) AND (b[z*2+1]=1) then b[z]:=1;
44               exit(a2+a3);
45          end;
46 function cal(z,x,y,l,r:longint):int64;inline;
47          var a2,a3:int64;
48          begin
49               if l>r then exit(0);
50               if (x=l) and (y=r) then exit(a[z]);
51               a2:=cal(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2));
52               a3:=cal(z*2+1,(x+y) div 2+1,y,max((x+y) div 2+1,l),r);
53               exit(a2+a3);
54          end;
55 begin
56      readln(n);
57      built(1,1,n);
58      readln;
59      readln(m);
60      for i:=1 to m do
61          begin
62               readln(j,k,l);
63               case j of
64                    1:writeln(cal(1,1,n,k,l));
65                    2:op(1,1,n,k,l);
66               end;
67          end;
68      readln;
69 end.
70        

 

3211: 花神游历各国

标签:

原文地址:http://www.cnblogs.com/HansBug/p/4266586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!