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

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

时间:2018-09-09 22:15:52      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:i++   lin   hang   bit   pad   read   theme   its   type   

  •  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\n",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

标签:i++   lin   hang   bit   pad   read   theme   its   type   

原文地址:https://www.cnblogs.com/tingtin/p/9615071.html

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