3038: Seven minutes of God's problem 2 [line tree violence]

Source: Internet
Author: User

3038: God's problem seven minutes 2 time limit:3 Sec Memory limit:128 MB
submit:1210 solved:536
[Submit] [Status] [Discuss] Description

Xlk that "God made the seven minutes of the problem" is not very enjoyable, so there is the second part.
"In the first minute, X says, to have a sequence, a positive integer sequence is given."
The second minute, L said, to be able to modify, so there is a number of each number in the square (the next rounding) operation.
The third minute, K said, to be able to query, so there is to seek a number of operations.
Four minutes, Rainbow Meow said, if Noip difficulty, so there is the data range.
Five minutes, the poet said, to have rhyme, so there is time limit and memory limit.
Six minutes, and the snow said, to save things, so there is a guarantee in the process and the final result does not exceed the 64-bit signed integer type of the range of the limit.
The first seven minutes, the problem was finally finished, however, the god of the cows do not want to write the problem of the program. "
--seven minutes of God's problems • Part II
So this sacred mission is yours.

Input

The first line is an integer n, which represents the number of numbers in the sequence.
The second row n positive integers that represent the number in the initial state of the sequence.
The third line, an integer m, indicates that there is an M operation.
The next m line is three integers per line k,l,r,k=0 for each number in [l,r] squared (rounded down), and K=1 is asking for the sum of each number in [L,r].

Output

For the inquiry operation, each line outputs an answer.

Sample Input10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
Sample Output19
7
6
HINT

1: For 100% of the data, 1<=n<=100000,1<=l<=r<=n, the number in the series is greater than 0, and no more than 1e12.

2: Data does not guarantee l<=r if l>r, please exchange l,r, thank you!

Source

Poetize4

With bzoj3211

A very fast loglogn with a reduced root opening?

All 1, no need to keep rooting.

So Col=1 says an interval is not necessary to continue to open the root (=0 or = 1)

The data range is 1e12 ah ah ah ah oh the whole long long

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#defineMid ((l+r) >>1)#defineLC X<<1#defineRC X<<1|1#defineLson X<<1,l,mid#defineRson X<<1|1,mid+1,rConst intn=1e5+5; typedefLong Longll;inline ll Read () {CharC=getchar (); ll x=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN,Q,OP,QL,QR;structnode{intCol;    ll sum; Node (): Col (0), SUM (0) {}}t[n<<2];inlinevoidMergeintx) {T[x].sum=t[lc].sum+t[rc].sum; T[x].col=t[lc].col&T[rc].col;}voidBuildintXintLintR) {    if(l==R) {T[x].sum=read (); if(t[x].sum==1|| t[x].sum==0) t[x].col=1; }Else{build (Lson);        Build (Rson);    Merge (x); }}voidSEGSQR (intXintLintRintQlintqr) {    if(T[x].col)return; if(l==R) {T[x].sum=(LL) sqrt (t[x].sum); if(t[x].sum==1|| t[x].sum==0) t[x].col=1; }Else{        if(ql<=mid) Segsqr (LSON,QL,QR); if(mid<qr) segsqr (RSON,QL,QR);    Merge (x); }}ll Segque (intXintLintRintQlintqr) {    if(QL&LT;=L&AMP;&AMP;R&LT;=QR)returnt[x].sum; Else{ll ans=0; if(Ql<=mid) ans+=Segque (LSON,QL,QR); if(MID&LT;QR) ans+=Segque (RSON,QL,QR); returnans; }}intMain () {//freopen ("In.txt", "R", stdin);n=read (); Build (1,1, N); Q=read ();  while(q--) {op=read (); Ql=read (); qr=read (); if(ql>qr) swap (QL,QR); if(op==1) printf ("%lld\n", Segque (1,1, N,QL,QR)); ElseSEGSQR (1,1, N,QL,QR); }}

3038: Seven minutes of God's problem 2 [line tree violence]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.