BZOJ 3211)

Source: Internet
Author: User

Time Limit: 5 Sec Memory Limit: 128 MB
Submit: 52 Solved: 24
[Submit] [Status] [Discuss]
Description


Input


Output
Each time x = 1, each line has an integer, indicating the pleasure of the trip.

Sample Input
4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4


Sample Output

101

11

11


HINT
For 100% of data, n ≤ 100000, m ≤ 200000, data [I] is non-negative and less than 10 ^ 9

 

Source
SPOJ2713 data has been enhanced

 

Do not hesitate.

However, the line segment tree does not support the start of the range, but 10 ^ 9 is equal to the power of 5 to reach 1 -_-

Therefore, there is no pressure on MAXN * 5 for brute force modification.

Whether to use a line segment tree to store a segment requires an open party (2-Yes, 1-No) + brute force Modification

No pressure


[Cpp] # include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <iostream>
# Include <algorithm>
# Include <functional>
# Include <cmath>
# Include <cctype>
Using namespace std;
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <n; I ++)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define Forp (x) for (int p = pre [x]; p = next [p])
# Define RepD (I, n) for (int I = n; I> = 0; I --)
# Define MAXN (200000 + 10)
# Define MAXM (400000 + 10)
# Define Lson (x <1)
# Define Rson (x <1) + 1)
Int n, m, a [MAXN * 2] = {0}, B [MAXN * 2] = {0 };
Long sum [MAXN * 2];
Void update (int x)
{
If (B [Lson] = 2 | B [Rson] = 2) B [x] = 2;
Else B [x] = 1;
Sum [x] = sum [Lson] + sum [Rson];
}
Void build (int x, int l, int r)
{
If (l = r)
{
Scanf ("% d", & a [x]); sum [x] = a [x];
If (a [x] <= 1) B [x] = 1;
Else B [x] = 2;
}
If (l> = r) return;
Int m = (l + r)> 1;
Build (Lson, l, m );
Build (Rson, m + 1, r );
Update (x );
}
Void pushdown (int x, int l, int r)
{
If (B [x] <= 1) return;
If (l = r)
{
A [x] = sum [x] = sqrt (a [x]);
If (a [x] <= 1) B [x] = 1;
Return;
}
Int m = (l + r)> 1;
Pushdown (Lson, l, m );
If (m <r) pushdown (Rson, m + 1, r );
Update (x );
}
Void change (int x, int l, int r, int L, int R)
{
If (B [x] <= 1) return;
Int m = (l + r)> 1;
If (L <= l & r <= R)
{
Pushdown (x, l, r );
Return;
}
If (L <= m) change (Lson, l, m, L, R );
If (m <R) change (Rson, m + 1, r, L, R );
Update (x );
}
Long qur (int x, int l, int r, int L, int R)
{
Int m = (l + r)> 1;
If (L <= l & r <= R)
{
Return sum [x];
}
Long ans = 0;
If (L <= m) ans + = qur (Lson, l, m, L, R );
If (m <R) ans + = qur (Rson, m + 1, r, L, R );
Return ans;
}
 
Int main ()
{
// Freopen ("bzoj3211.in", "r", stdin );
// Freopen (". out", "w", stdout );
Scanf ("% d", & n );
Build (1, 1, n );
Scanf ("% d", & m );
For (I, m)
{
Int x, l, r;
Scanf ("% d", & x, & l, & r );
If (x = 1) printf ("% lld \ n", qur (1, 1, n, l, r ));
Else change (1, 1, n, l, r );
}
Return 0;
}

# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <iostream>
# Include <algorithm>
# Include <functional>
# Include <cmath>
# Include <cctype>
Using namespace std;
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <n; I ++)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define Forp (x) for (int p = pre [x]; p = next [p])
# Define RepD (I, n) for (int I = n; I> = 0; I --)
# Define MAXN (200000 + 10)
# Define MAXM (400000 + 10)
# Define Lson (x <1)
# Define Rson (x <1) + 1)
Int n, m, a [MAXN * 2] = {0}, B [MAXN * 2] = {0 };
Long sum [MAXN * 2];
Void update (int x)
{
If (B [Lson] = 2 | B [Rson] = 2) B [x] = 2;
Else B [x] = 1;
Sum [x] = sum [Lson] + sum [Rson];
}
Void build (int x, int l, int r)
{
If (l = r)
{
Scanf ("% d", & a [x]); sum [x] = a [x];
If (a [x] <= 1) B [x] = 1;
Else B [x] = 2;
}
If (l> = r) return;
Int m = (l + r)> 1;
Build (Lson, l, m );
Build (Rson, m + 1, r );
Update (x );
}
Void pushdown (int x, int l, int r)
{
If (B [x] <= 1) return;
If (l = r)
{
A [x] = sum [x] = sqrt (a [x]);
If (a [x] <= 1) B [x] = 1;
Return;
}
Int m = (l + r)> 1;
Pushdown (Lson, l, m );
If (m <r) pushdown (Rson, m + 1, r );
Update (x );
}
Void change (int x, int l, int r, int L, int R)
{
If (B [x] <= 1) return;
Int m = (l + r)> 1;
If (L <= l & r <= R)
{
Pushdown (x, l, r );
Return;
}
If (L <= m) change (Lson, l, m, L, R );
If (m <R) change (Rson, m + 1, r, L, R );
Update (x );
}
Long qur (int x, int l, int r, int L, int R)
{
Int m = (l + r)> 1;
If (L <= l & r <= R)
{
Return sum [x];
}
Long ans = 0;
If (L <= m) ans + = qur (Lson, l, m, L, R );
If (m <R) ans + = qur (Rson, m + 1, r, L, R );
Return ans;
}

Int main ()
{
// Freopen ("bzoj3211.in", "r", stdin );
// Freopen (". out", "w", stdout );
Scanf ("% d", & n );
Build (1, 1, n );
Scanf ("% d", & m );
For (I, m)
{
Int x, l, r;
Scanf ("% d", & x, & l, & r );
If (x = 1) printf ("% lld \ n", qur (1, 1, n, l, r ));
Else change (1, 1, n, l, r );
}
Return 0;
}

 

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.