struct Info {//一定要初始化
ll mn = 1e18;
int siz = 1;
int pos = 0;
Info(int x) {
mn = x;
}
Info () {
}
};
struct Tag{//与Info分开,防止更新把lazy带上
ll add = 0;
};
Info merge (const Info &a, const Info &b) {
Info c;
if(a.mn < b.mn) c = a;
else c = b;
return c;
}
struct segtree {
#define ls (u << 1)
#define rs (u << 1 | 1)
int n;
segtree(int n) {
init(n);
};
vector<Info> info;
vector<Tag> tag;
vector<int> a;
void init(int n) {
this->n = n;
info.resize(n << 2);
tag.resize(n << 2);
a.resize(n << 1);
}
void push_up(int u) {
info[u] = merge(info[ls], info[rs]);
}
void build(int u, int l, int r) {
if (l == r) {
info[u] = Info(a[l]);//填值
return ;
}
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
push_up(u);
}
void settag(int u, int k) {//处理数据
info[u].mn += k;
tag[u].add += k;
}
void push_down(int u) {
if (tag[u].add != 0) {
settag(ls, tag[u].add);
settag(rs, tag[u].add);
tag[u].add = 0;
}
}
void update(int u, int l, int r, int pos, int k) {
if (l == r) {
info[u] = Info(k);
return;
}
push_down(u);
int mid = l + r >> 1;
if (pos <= mid) update(ls, l, mid, pos, k);
else update(rs, mid + 1, r, pos, k);
push_up(u);
}
void update(int u, int l, int r, int x, int y, int k) {
if (x <= l && r <= y) {
settag(u, k);
return;
}
push_down(u);
int mid = l + r >> 1;
if (x <= mid) update(ls, l, mid, x, y, k);
if (mid < y) update(rs, mid + 1, r, x, y, k);
push_up(u);
}
Info query(int u, int l, int r, int x, int y) {
if (x <= l && r <= y) return info[u];
push_down(u);
int mid = l + r >> 1;
if (y <= mid) return query(ls, l, mid, x, y);
else if (mid < x) return query(rs, mid + 1, r, x, y);
else return merge(query(ls, l, mid, x, y), query(rs, mid + 1, r, x, y));
}
void update(int pos, int v) {
update(1, 1, n, pos, v);
}
void update(int x, int y, int k) {
update(1, 1, n, x, y, k);
}
Info query(int l, int r) {
return query(1, 1, n, l, r);
}
Info query(int pos) {
return query(1, 1, n, pos, pos);
}
};