Search
 
SCRIPT & CODE EXAMPLE
 

CPP

segment tree lazy propogation

void push(int v) {
    t[v*2] += lazy[v];
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        t[v] += addend;
        lazy[v] += addend;
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return -INF;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return max(query(v*2, tl, tm, l, min(r, tm)), 
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: C++ selectin file location using Win32 API 
Cpp :: max in c++ with three elements 
Cpp :: how to find the sum of elements in a stack in cpp 
Cpp :: stack using cpp 
Cpp :: fsafdsfdsaf 
Cpp :: c++ cout update percentage 
Cpp :: what is stdoutread in c++ 
Cpp :: what is vector capacity in c++ 
Cpp :: run program until ctrl-d c++ 
Cpp :: c++ string to const char* 
Cpp :: nodeafternode 
Cpp :: Write C++ program that will ask to choose from three cases. 
Cpp :: c++ program to convert kelvin to celsius 
Cpp :: what are manipulators in c++ 
Cpp :: two dimensional matrix using oops concept 
Cpp :: store binary data in buffer 
Cpp :: c pointer syntax 
Cpp :: Remove the jth object from the subset 
Cpp :: c++ to assembly 
Cpp :: cpp console progressbar 
Cpp :: C is widely used for systems-level software and embedded systems development. 
Cpp :: C++ concept simple requirements 
Cpp :: is there interfaces in c++ like 
Cpp :: gcd of two number in c++ stl 
Cpp :: reference variablesr in c++ 
Cpp :: c++ ascii value 
Cpp :: type casting in cpp 
Cpp :: declare a variable in cpp 
Cpp :: x += c++ 
Cpp :: opengl text rendering with 3d rendering 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =