zoukankan      html  css  js  c++  java
  • 3211: 花神游历各国

    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        
  • 相关阅读:
    Regionals 2012 :: Asia
    计算几何专题
    简单几何(凸包+多边形面积) POJ 3348 Cows
    简单几何(求凸包点数) POJ 1228 Grandpa's Estate
    简单几何(凸包+枚举) POJ 1873 The Fortified Forest
    简单几何(极角排序) POJ 2007 Scrambled Polygon
    Codeforces Round #328 (Div. 2)
    简单几何(直线求交点) POJ 2074 Line of Sight
    简单几何(点的位置) POJ 1584 A Round Peg in a Ground Hole
    简单几何(线段相交)+模拟 POJ 3449 Geometric Shapes
  • 原文地址:https://www.cnblogs.com/HansBug/p/4266586.html
Copyright © 2011-2022 走看看