首页 > 代码库 > 【UVA】11992 - Fast Matrix Operations(线段树模板)

【UVA】11992 - Fast Matrix Operations(线段树模板)

基本的线段树,需要注意的是由于有set和add操作,懒惰标记下推的时候,优先递推set,之后递推add,每次执行set操作将add标记清0

WA了好几次是因为计算那一段的时候出问题了,可笑的是我对着模板找了一个多小时的错。

#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;
#define lson pos << 1
#define rson pos << 1|1
typedef unsigned long long ULL;
typedef long long LL;
const int maxn = 1111111;
const int  INF = 1 << 30;
struct Node{
    int left,right;
    int max_value,min_value,sum_value;
    int col;
    int col2;
}tr[maxn << 2];
struct Ans{
    int min_value;
    int max_value;
    int sum_value;
    Ans(int a = INF,int b = 0,int c = 0):min_value(a),max_value(b),sum_value(c){};
};
int n,m,k;
void pushdown(int pos){
    if(tr[pos].col){
        int len1 = tr[lson].right - tr[lson].left + 1;
        int len2 = tr[rson].right - tr[rson].left + 1;
        tr[lson].sum_value += (tr[pos].col * len1);
        tr[lson].max_value +=  tr[pos].col;
        tr[lson].min_value +=  tr[pos].col;
        tr[rson].sum_value += (tr[pos].col * len2);
        tr[rson].max_value +=  tr[pos].col;
        tr[rson].min_value +=  tr[pos].col;
        tr[lson].col += tr[pos].col;
        tr[rson].col += tr[pos].col;
        tr[pos].col = 0;
    }
    return ;
}
void pushdown2(int pos){
    if(tr[pos].col2 >= 0){
        int len1 = tr[lson].right - tr[lson].left + 1;
        int len2 = tr[rson].right - tr[rson].left + 1;
        tr[lson].sum_value = http://www.mamicode.com/(tr[pos].col2 * len1);>

【UVA】11992 - Fast Matrix Operations(线段树模板)