CPU monitoring segment tree bare title

LINK: bzoj3064  this question is very good yards 20min stop to think about when it is found wrong with a little pit ...

Was it really hard to write but this is indeed a bare tree line of questions ... I think I write should be no big problem, but the very idea of ​​disorder if it is to write your own words so in order to be able to write this blog is to organize your thoughts a.

QXY: Inquiry from X to Y within this period of time the highest utilization rate of CPU 
AXY: inquiry of the events listed before from X to Y within this period of time the CPU utilization rate reached the highest 
PXYZ: a listed event makes this event from X within this period of time to increase the CPU usage Y Z 
cxyz: a listed event makes this event from X to Y within this period of time the CPU usage becomes Z 

4 asked to observe if there is no second asking so then it will be a segment tree maintains two markers and maintenance interval maximum value of good writing.

You can mark made permanent? The school should think about whether the marks made permanent mark seems a bit complicated two interfere with each other, but should be no big problem but with the most value range is not so good to write the history of the most value for multiple markers and influence each other and Maintenance it should be recommended pushdown can not do a little better.

To sum up the lazy tag segment tree and permanent marking of which are selected from good to write about which one is recommended to write code complexity lazy tag is not too high.

Consider how to maintain the history of the most value of this z might be negative if a simple open a mark mx represents the history value, then for a range of modifications consideration mark one thing pushdown not pass it a range covered call back directly add tags are overwritten What value can then history will be wrong most of the value of the tag inside its sub-tree should be updated out.

Now not been updated so that point of view is quite right, of course, there is also another case interval coverage mark covering the original mark so most historical value will be some big problems. How to solve the above circumstances I think the mark when the mark is then covered with a first covered then be passed down to cover the pass mark to make mark at first, although the current value is no major impact on history, but most values ​​are it is possible to update a need to do so again down, I suddenly realized that a more serious questions about the merger add mark every time we obviously can not down to his son as complex abnormally large 4n each operation close to the complexity ratio ordinary array simulate a higher degree of complexity.

add marks the merger will affect the original add something bigger now consolidated on a smaller but significantly more likely to add the most value this updated historical value or a history of error. But also consider how further down the time to maintain the mark. We set a time addmax again pass under a set tagmax Chin Chuan Chuan then again I think this is very stable under standard degree of complexity, then nlogn seems to be more than two-thirds of the almost constant.

Probably this is a cancer thing finished before we know it is correct or not is a rational look right. Within an 32-bit signed integer answer int 2 ^ 31-1 if only 31 have to open long long by doubling over large constant can not look at it ...

A little bit high difficulty crash codes do not know how to write in accordance with the above ideas there are some details to be processed ah I was really uncomfortable serving this segment tree cancer What good maintenance interval value history really suits ...

And bar the 30min still feel this is not the person to write something pushdown and down down inside I think it will also require a mass transfer coverage son to be the next pass covering something so under so my idea is not desirable or look at how to write dalao it I the collapse of the 200+ code somehow flawed place.

What I should be a little misunderstanding about this mark is I get in trouble correct solution to a problem is to solve the guitar like a teacher proposed labeling consolidation method. Heart very collapse.

Kyrgyzstan stick about the teacher's explanations:

When new to this kind of problem, the difficulty of this example may be higher, so let's ignore the interval assignment.
Consider the use of conventional labeled lazy solved, if only first interrogation interval maximum value, to use the surface only this interval plus or minus a lazy labeled (with  A D D  shown) can be solved.
Now consider asking the maximum interval historical maximum. We define a new kind of lazy tag: history's largest subtraction mark (with Pre representation). This definition is labeled: a timing mark to pass from this node at the current time to this period, the nodes Add tag value reaches a maximum value over.
Now consider the second  i  reached its son nodes under the mark  L  , it is not difficult to find markers that can be merged: P R & lt E L = max ( P R & lt E L , A D D L + P R & lt E i ) , A D D L = A D D L + A D D I; Prel = max (Prel, Addl + Prei), Addl Addi + = Addl. As for the maximum information update history section is also similar to the merge flag, only the face of the current maximum range you want to add Prei then compared to the original historical maximum.
Now back to the original question, we observe in the process of modification operations, are affected by changes to a node: If a node does not occur under the pass mark, then the beginning it has been affected by plus or minus operating range, then we can use the above Pre recorded mark as described, up to a certain time, the node is marked impact interval coverage a, then in this case the number of all the nodes are made identical, all the modifications after subtraction interval and then, is this node , covering the operation section is no different.
Thus each node label can be divided into two parts: The first part is a subtraction section, the second section part is covered. So we can use  ( the X- , the y- )  to represent the history of the most value for the tag, which is defined as the current range in the first stage the biggest plus or minus mark is  the X- the X-, marking the largest coverage in the second stage is  the y- the y-. Obviously, this tag can be merged with updates.
We will use this most traditional of lazy labeling methods to solve this problem, the time complexity of  O ( m log the n- )  .

In fact, I did not understand how God, but this problem is the question constantly thinking through my decision to copy it again ... (I learned a notation ...

//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<cctype>
#include<utility>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<deque>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<stack>
#include<string>
#include<cstring>
#define INF 1000000000000ll
#define ll long long
#define db double
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define l(p) t[p].l
#define r(p) t[p].r
#define sum(p) t[p].sum
#define mx(p) t[p].mx
#define zz p<<1
#define yy p<<1|1
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline ll read()
{
    ll x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const ll MAXN=100010;
ll n,m;
char ch;
struct wy
{
    ll l,r;
    ll mx;//历史最值
    ll sum;//当前最值
}t[MAXN<<2];
struct data
{
    ll x,y;
    data(ll a=0,ll b=-INF){x=a;y=b;}
    data operator +(const data &a){return data (max (-INF, x + Ax), max (y + a.x, ay));} 
    data Operator * ( const data & a) { return data (max (x, Ax), max (y, ay)); } 
} himself [MAXN << 2 ], ptag [MAXN << 2 ]; 
inline void pushup (ll p) 
{ 
    mx (p) = max (mx (ZZ), mx (yy)); 
    sum (p) = max (sum (ZZ), sum (yy)); 
} 
Inline void pushdown (ll p) 
{ 
    ptag [ZZ] = ptag [ZZ] * (God [ZZ] + ptag [p]); 
    Most [ZZ] = himself [ZZ] + issue [p]; 
    mx (ZZ)= max (mx (ZZ), max (sum (ZZ) + ptag [p] .x, ptag [p] .y)); 
    sum (ZZ) = max (sum (ZZ) + choice [p] .x, he [p] .y); 
    ptag [yy] = ptag [yy] * (God [yy] + ptag [p]); 
    Most [yy] = himself [yy] + issue [p]; 
    mx (yy) = max (mx (yy), max (sum (yy) + ptag [p] .x, ptag [p] .y)); 
    sum (yy) = max (sum (yy) + choice [p] .x, he [p] .y); 
    ptag [p] = himself [p] = data (); 
} 
Inline void build (ll p, ll l, ll r) 
{ 
    l (p) = l; r (p) = r;
    if (l == r) 
    { 
        mx (p) = read (); sum (p) =mx(p);
        return;
    }
    ll mid=(l+r)>>1;
    build(zz,l,mid);
    build(yy,mid+1,r);
    pushup(p);
}
inline void change(ll p,ll l,ll r,data a)
{
    if(l<=l(p)&&r>=r(p))
    {
        ntag[p]=ntag[p]+a;
        ptag[p]=ptag[p]*ntag[p];
        sum(p)=max(sum(p)+a.x,a.y);
        mx(p)=max(mx(p),sum(p));
        return;
    }
    ll mid=(l(p)+r(p))>>1;
    pushdown(p);
    if(l<=mid)change(zz,l,r,a);
    if(r>mid)change(yy,l,r,a);
    pushup(p);
}
inline ll ask(ll p,ll l,ll r,ll flag)
{
    if(l<=l(p)&&r>=r(p))return flag?mx(p):sum(p);
    pushdown(p);
    ll mid=(l(p)+r(p))>>1,ans=-INF,w=-INF;
    if(l<=mid)ans=ask(zz,l,r,flag);
    if(r>mid)w=ask(yy,l,r,flag);
    return max(ans,w);
}
signed main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    n=read();
    build(1,1,n);
    m=read();
    for(ll i=1;i<=m;++i)
    {
        ll x,y,z;
        ch=getc();
        while(ch!='Q'&&ch!='A'&&ch!='P'&&ch!='C')ch=getc();
        x=read();y=read();
        if(ch=='Q')printf("%lld\n",ask(1,x,y,0));
        if(ch=='A')printf("%lld\n",ask(1,x,y,1));
        if(ch=='P')z=read(),change(1,x,y,data(z,-INF));
        if(ch=='C')z=read(),change(1,x,y,data(-INF,z));
    }
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/chdy/p/11408881.html