BZOJ3211 Flora traveled countries (small fresh tree line)

Topic Portal


Subject description:

Flora countries like walking tour, by the way around the child burst competition. Flora has a tour route, it is linear, that is to say, all traveled the country in the shape of a line arrangement, each country has to spend God like a degree (of course, God does not necessarily like to spend all countries).

Every trip, God would choose to spend a tourist route, it was a bunch of countries, is continuous for some, the trip brings happy is the sum of the favorite in these countries, of course, like the flower of God in these countries program is not constant, sometimes sudden aversion to certain countries, so he likes to these countries of δ becomes δ (possibly Flora child burst OI in those countries, so bored) .

Flora is now given each itinerary, as well as changes in the degree of fun, happy to request a value Flore per trip.


Input formats:

The first row is an integer N , it expressed N countries;
second row of N integers separated by spaces, represents the initial of each country like;
third row is an integer M represents there are M pieces of information to be processed ;
fourth row to the last, each row of three like integers x, L, r , when x = 1 when asked the sum of x traveled country fun value r, i.e. [Sigma [delta] I (r ~ L) , when x = 2 when State l and r of each country like [delta] I becomes [delta] I .


Output formats:

Each x = 1 , the integer one per line. Happy representation of the trip.


Example:

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


Data range and tips:

For all data, 1≤n≤10 . 5 , 1≤m≤2 × 10 . 5 , 1≤l≤r≤n, 0 ≦ [delta] I ≦ 10 . 9 .

NOTE: It is recommended to use sqrt function, and rounded down.


A topic meaning: tree line opened with the interval, the interval sum.


 answer:

Section information does not update quickly, not use delay mark. (terrible)

But note that 10 9 up to 5 times open to change with the

So, each modification violence continues recursively until the current range of 0 or 1 is already full on return

It is not so handsome?


Code time:

#include<bits/stdc++.h>
#define L(x) x<<1
#define R(x) x<<1|1
using namespace std;
int n,m;
long long v[100001];
long long trsum[400001],trmax[400001];
void pushup(int x)
{
	trsum[x]=trsum[L(x)]+trsum[R(x)];
	trmax[x]=max(trmax[L(x)],trmax[R(x)]);
}
void build(int x,int l,int r)
{
	if(l==r)
	{
		trsum[x]=trmax[x]=v[l];
		return;
	}
	int mid=(l+r)>>1;
	build(L(x),l,mid);
	build(R(x),mid+1,r);
	pushup(x);
}
void change(int x,int l,int r,int L,int R)
{
	if(l==r)
	{
		trsum[x]=sqrt(trsum[x]);
		trmax[x]=sqrt(trmax[x]);
		return;
	}
	if(trmax[x]<=1)return;//注意这里为≤,其他跟普通线段树别无两样 
	int mid=(l+r)>>1;
	if(L<=mid)change(L(x),l,mid,L,R);
	if(R>mid)change(R(x),mid+1,r,L,R);
	pushup(x);
}
long long ask(int x,int l,int r,int L,int R)
{
	if(L<=l&&r<=R)return trsum[x];
	int mid=(l+r)>>1;
	long long rec=0;
	if(L<=mid)rec+=ask(L(x),l,mid,L,R);
	if(R>mid)rec+=ask(R(x),mid+1,r,L,R);
	return rec;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&v[i]);
	build(1,1,n);
	scanf("%d",&m);
	while(m--)
	{
		int op,l,r;
		scanf("%d%d%d",&op,&l,&r);
		if(op==1)printf("%lld\n",ask(1,1,n,l,r));
		else change(1,1,n,l,r);
	}
	return 0;
}

 cpp

rp ++

Guess you like

Origin www.cnblogs.com/wzc521/p/11015134.html