• ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study


    •  262144K
     

    Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i].

    Unfortunately, the longer he learns, the fewer he gets.

    That means, if he reads books from ll to rr, he will get a[l] * L + a[l+1] *(L-1) + …… + a[r-1] *2 + a[r](L is the length of [ l, r ] that equals to rl+1).

    Now Ryuji has qq questions, you should answer him:

    1. If the question type is 1, you should answer how much knowledge he will get after he reads books [ lr ].

    2. If the question type is 2, Ryuji will change the ith book's knowledge to a new value.

    Input

    First line contains two integers nn and qq (nq100000).

    The next line contains n integers represent a[i](a[i]1e9) .

    Then in next qq line each line contains three integers ab, c, if a = 1, it means question type is 1, and b, ccrepresents [ lr ]. if a =2 , it means question type is 2 , and bb, cc means Ryuji changes the bth book' knowledge to cc

    Output

    For each question, output one line with one integer represent the answer.

    样例输入

    5 3
    1 2 3 4 5
    1 1 3
    2 5 0
    1 4 5

    样例输出

    10
    8

    题目来源

    ACM-ICPC 2018 徐州赛区网络预赛

     

     1 #define  ull unsigned  long  long 
     2 #define ll  long  long 
     3 #define  N  100009
     4 #define  lowbit(x) x&(-x)
     5 ull c1[N],c2[N];
     6 int n,q;
     7 void   update1(int x,ull num)
     8 {
     9     while(x<=n)
    10     {
    11         c1[x]+=num;
    12         x+=lowbit(x);
    13     }
    14 }
    15 ull getsum1(int  x)
    16 {
    17     ull sum=0;
    18     while(x>0)
    19     {
    20         sum+=c1[x];
    21         x-=lowbit(x);
    22     }
    23     return  sum;
    24 }
    25 void   update2(int x,ull num)
    26 {
    27     while(x<=n)
    28     {
    29         c2[x]+=num;
    30         x+=lowbit(x);
    31     }
    32 }
    33 ull getsum2(int  x)
    34 {
    35     ull sum=0;
    36     while(x>0)
    37     {
    38         sum+=c2[x];
    39         x-=lowbit(x);
    40     }
    41     return  sum;
    42 }
    43 int  main()
    44 {
    45     scanf("%d%d",&n,&q);
    46     ull x;
    47     for(int i=1;i<=n;i++)
    48     {
    49         scanf("%lld",&x);
    50         update1(i,x);
    51         update2(i,1ull*(n-i+1)*x);//在前面加个 ull  保证整体是ull 的
    52     }
    53     int op,l,r;
    54     while(q--)
    55     {
    56         scanf("%d%d%d",&op,&l,&r);
    57         if(op==1)
    58         {
    59             ull ans1=1ull*(n-r)*(getsum1(r)-getsum1(l-1));
    60             ull ans2=getsum2(r)-getsum2(l-1);
    61             printf("%lld
    ",ans2-ans1);//"u"  是unsigned   int 
    62         }
    63         else{
    64             ull temp=getsum1(l)-getsum1(l-1);
    65             update1(l,1ull*(r-temp) );
    66             update2(l,1ull*(r-temp)*(n-l+1)) ;
    67         }
    68     }
    69     return   0;
    70 }
    71     
    72     
    73     

     

     
  • 相关阅读:
    java中&和&&是怎么运算的
    struts中ActionForward 使用mapping.findForward如何传递get参数
    EL表达式_详解
    JSTL标签_详解
    inner join, left join, right join, full join 的区别
    CentOS7部署FastDFS+nginx模块
    一个实例明白AutoResetEvent和 ManulResetEvent的用法
    C#防止在画面上闪烁的Button
    C#中给Label控件设置BackgroundImage属性
    浅析C#异步操作
  • 原文地址:https://www.cnblogs.com/tingtin/p/9615071.html
Copyright © 2020-2023  润新知