#include<stdio.h>
#include<string.h>
#include<iostream>
#define maxn 100000 + 10
using namespace std;
int val[maxn];
struct Tree
{
int mark;
int total;
int left, right;
}tree[maxn*4];
int create(int root, int left, int right)
{
tree[root].left = left;
tre[root].right = right;
if (left == right)
return tree[root].total = val[left];
int mid = (a + b) / 2;
int a, b;
a = create(2*root, left, mid);
b = create(2*root+1, mid+1, right);
return tree[root].total = a + b;
}
int update(int root, int left, int right, int val) // 区间更新
{
update_mark(root);
if (tree[root].left > right || tree[root].right < left) // 当前区间和更新区间无交集。不作处理。
return tree[root].total;
if (left <= tree[root].left && tree[root].right <= right) // 没动延迟标记咋用的.这是当前区间完全包含在更新区间的时候。
{
tree[root].mark = val;
return tree[root].total = val * (tree[root].right - tree[root].left + 1);
}
int a = update(2*root, left, right, val);
int b = update(2*root+1, left, right, val);
return tree[root].total = a + b;
}
int calculate(int root, int left, int right) // 求区间和
{
update_mark(root);
if (tree[root].left > right || tree[root].right < left)
return 0;
if (left <= tree[root].left && tree[root].right <= right)
return tree[root].total;
int a = calculate(2*root, left, right);
int b = calculate(2*root+1, left, right);
return tree[root].total = a + b;
}
void update_mark(int root)
{
if (tree[root].mark)
{
tree[root].total = tree[root].mark * (tree[root].right - tree[root].left + 1);
if (tree[root].left != tree[root].root.right)
tree[root*2].mark = tree[root*2+1].mark = tree[root].mark;
tree[root].mark = 0;
}
}