H-can you answer these queries?
Time limit:2000ms Memory limit:65768kb 64bit IO format:%i64d &%i64u
Submit Status Practice HDU 4027
Description
A lot of battleships of evil is arranged in a line before the battle. Our commander decides-to-use we secret weapon to eliminate the battleships. Each of the battleships can is marked a value of endurance. For every attack of We secret weapon, it could decrease the endurance of a consecutive part of battleships by make their Endurance to the square root of it original value of endurance. During the series of Attack of our secret weapon, the commander wants to evaluate the effect of the weapon, so he asks you For help.
You is asked to answer the queries, the sum of the endurance of a consecutive part of the battleship line.
Notice that square root operation should is rounded down to integer.
Input
The input contains several test cases, terminated by EOF.
For each test case, the first line contains a single integer n, denoting there is n battleships of evil in a line. (1 <= N <= 100000)
The second line contains N integers Ei, indicating the endurance value of all battleship from the beginning of the line T o the end. You can assume this sum of all endurance value are less than 2 63.
The next line contains an integer M, denoting the number of actions and queries. (1 <= M <= 100000)
For the following M lines, each line contains three integers T, X and Y. The t=0 denoting the action of the secret weapon, which would decrease the endurance value of the battleships between the X -th and y-th battleship, inclusive. The t=1 denoting the commander which ask for the sum of the endurance value of the battleship between a D y-th, inclusive.
Output
For each test case, print the case number at the first line. Then print one to each query. And remember follow a blank line after each test case.
Sample Input
10
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 Output
Case #1:
19
7
6
At first think of each open root to update to the leaf node, will definitely time out, but the root of the root to a speed is very fast, only need to add a delay mark, that is already all one of the interval will not be updated downward
That saves you time.
#include <bits/stdc++.h> #include <iostream> #include <cmath> #include <cstring> #include <string> #include <cstdlib> #include <cstdio> #include <map> #include <algorithm>using namespace Std;const int Maxn=100011;const int inf=999999999, #define Lson (rt<<1), L,m#define Rson (rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,n) for (int i=0;i< (n); i++) Template<class t>inline T Read (t&x) {char C; while ((C=getchar ()) <=32); BOOL Ok=false; if (c== '-') Ok=true,c=getchar (); for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 '; if (OK) x=-x; return x;} Template<class t> inline void Read_ (t&x,t&y) {read (x); Read (y);} Template<class t> inline void read__ (t&x,t&y,t&z) {read (x); Read (y); Read (z);} Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x; if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');} Template<class T>inline void Writeln (T x) {write (x); Putchar (' \ n ');} -------IO template------typedef long LONG ll;struct node{ll inv;///0 is not open with the number, >=1, indicating the opening with the number LL sum;} p[maxn<< 2];void Build (int rt,int l,int R) {p[rt].inv=1; p[rt].sum=0; if (l==r) {read (p[rt].sum); P[rt].inv=1; Return } build (Lson); Build (Rson); P[rt].sum=p[rt<<1].sum+p[rt<<1|1].sum;} void update (int rt,int l,int r,int x,int y) {//printf ("%d%d%d%d%d\n", rt,l,r,x,y); if (l==r) {if (P[RT].INV) {p[rt].sum= (int) sqrt (p[rt].sum); if (p[rt].sum==1) p[rt].inv=0; } return; } if (l==x&&y==r&&p[rt].inv==0) {return; }//if (P[RT].INV)//{//p[rt<<1].inv=p[rt<<1|1].inv=p[rt].inv;//p[rt].inv=0;//} if (y<=m) update (LSON,X,Y); else if (x>m) update (RSON,X,Y); else {update (LSON,X,M); Update (RSON,M+1,Y); } p[rt].sum=p[rt<<1].sum+p[rt<<1|1].sum; P[RT].INV=P[RT<<1].INV+P[RT<<1|1].INV;} LL query (int rt,int l,int r,int x,int y) {if (l==x&&y==r) {return p[rt].sum; } if (y<=m) return query (lson,x,y); else if (x>m) return query (rson,x,y); else {return query (lson,x,m) +query (rson,m+1,y); }}int Main () {int n,m; Freopen ("In.txt", "R", stdin); int Cas=1; while (~SCANF ("%d", &n)) {printf ("Case #%d:\n", cas++); Build (1,1,n); int a,b,c; Read (m); while (m--) {read__ (a,b,c); printf ("%d%d%d\n", a,b,c); if (b>c) swap (B,C); if (a==0) {update (1,1,N,B,C); } else {writeln (query (1,1,n,b,c)); }} printf ("\ n"); } return 0;}
H-can you answer these queries? HDU 4027 (segment tree + delay marker + open root speed)