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

Posted tingtin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 r?l+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);
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);
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     

 

 


以上是关于ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study的主要内容,如果未能解决你的问题,请参考以下文章

ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath

ACM-ICPC 2018 徐州赛区网络预赛 J Maze Designer

ACM-ICPC 2018 徐州赛区网络预赛(9.9)

ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

ACM-ICPC 2018 徐州赛区网络预赛 A. Hard to prepare

ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE