1 #pragma comment(linker, "/STACK:16777216")
5 typedef long long int64
;
12 struct Segment
*ch
[2];
13 } pool
[maxn
*8],*T
,*nil
;
15 typedef struct Segment Segment
;
17 void down(Segment
*T
) {
19 T
->ch
[0]->add
+=T
->add
;
20 T
->ch
[1]->add
+=T
->add
;
21 T
->ch
[0]->sum
+=((T
->ch
[0]->r
- T
->ch
[0]->l
+ 1)*T
->add
);
22 T
->ch
[1]->sum
+=((T
->ch
[1]->r
- T
->ch
[1]->l
+ 1)*T
->add
);
27 Segment
* Init(int l
, int r
) {
28 Segment
*T
=&pool
[cnt
++];
32 scanf("%lld",&T
->sum
);
33 T
->ch
[0]=T
->ch
[1]=nil
;
38 T
->ch
[1]=Init(mid
+1,r
);
39 T
->sum
= T
->ch
[0]->sum
+ T
->ch
[1]->sum
;
43 int64
Query(Segment
*T
, int l
, int r
) {
44 if (l
<= T
->l
&& T
->r
<= r
) return T
->sum
;
46 int mid
=(T
->l
+ T
->r
)>>1;
48 if (l
<=mid
) res
+=Query(T
->ch
[0],l
,r
);
49 if (r
>mid
) res
+=Query(T
->ch
[1],l
,r
);
53 void Modify(Segment
*T
, int l
, int r
, int64 val
) {
54 if (l
<= T
->l
&& T
->r
<= r
) {
55 T
->sum
+=(T
->r
- T
->l
+ 1)*val
;
60 int mid
=(T
->l
+ T
->r
)>>1;
61 if (l
<=mid
) Modify(T
->ch
[0],l
,r
,val
);
62 if (r
>mid
) Modify(T
->ch
[1],l
,r
,val
);
63 T
->sum
= T
->ch
[0]->sum
+ T
->ch
[1]->sum
;
74 scanf(" %c %d %d",&opt
,&l
,&r
);
77 printf("%lld\n",Query(T
,l
,r
));