void Update(int rt, int l, int r, int x, int y, int val) ///区间更新,求和;
{
if(x <= l && y >= r)
{
a[rt] += val * (r - l + 1);
lazy[rt] += val;
return;
}
if(lazy[rt])
{
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
a[rt << 1] += ((l + r) / 2 - l + 1) * lazy[rt];
a[rt << 1 | 1] += (r - (l + r) / 2) * lazy[rt];
lazy[rt] = 0;
}
int mid = (l + r) >> 1;
if(mid >= x)
Update(rt << 1, l, mid, x, y, val);
if(mid < y)
Update(rt << 1 | 1, mid + 1, r, x, y, val);
a[rt] = a[rt << 1] + a[rt << 1 | 1];
}
ll Query(int rt, int l, int r, int x, int y)
{
if(x <= l && y >= r)
return a[rt];
if(lazy[rt])
{
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
a[rt << 1] += ((l + r) / 2 - l + 1) * lazy[rt];
a[rt << 1 | 1] += (r - (l + r) / 2) * lazy[rt];
lazy[rt] = 0;
}
int mid = (l + r) >> 1;
ll sum = 0;
if(mid >= x)
sum += Query(rt << 1, l, mid, x, y);
if(y > mid)
sum += Query(rt << 1 | 1, mid + 1, r, x, y);
return sum;
}
void Update(int rt, int l, int r, int i, int val) ///单点更新,找最大值
{
if(l == r)
{
a[rt] = val;
return;
}
int mid = (l + r) >> 1;
if(i <= mid)
Update(rt << 1, l, mid, i, val);
if(i > mid)
Update(rt << 1 | 1, mid + 1, r, i, val);
a[rt] = max(a[rt << 1], a[rt << 1 | 1]);
}
int Query(int rt, int l, int r, int x, int y)
{
if(l >= x && y >= r)
return a[rt];
int mid = (l + r) >> 1, ans = 0;
if(mid >= x)
ans = max(Query(rt << 1, l, mid, x, y), ans);
if(y > mid)
ans = max(Query(rt << 1 | 1, mid + 1, r, x, y), ans);
return ans;
}
void Update(int rt, int l, int r, int i, int val) ///单点更新,求和;
{
if(l == r)
{
a[rt] = val;
return;
}
int mid = (l + r) >> 1;
if(i <= mid)
Update(rt << 1, l, mid, i, val);
if(i > mid)
Update(rt << 1 | 1, mid + 1, r, i, val);
a[rt] = a[rt << 1] + a[rt << 1 | 1];
}
int Query(int rt, int l, int r, int x, int y)
{
if(x <= l && y >= r)
return a[rt];
int mid = (l + r) >> 1, ans = 0;
if(mid >= x)
ans += Query(rt << 1, l, mid, x, y);
if(y > mid)
ans += Query(rt << 1 | 1, mid + 1, r, x, y);
return ans;
}