#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#define inf 0x3f3f3f3f
#define cha 1e-6
#define ll long long
using namespace std;
const int maxn = 1e5 + 6;
ll node[270000],lazy[270000];
ll a[100005];
inline void lazyuild(ll s ,ll t,ll p ){
if(s==t){
node[p]=a[s];
return ;
}
ll m=(s+t)/2;
lazyuild(s,m,p*2), lazyuild(m+1,t,p*2+1);
node[p]=node[p*2]+node[(2*p)+1];
}
inline ll getsum(ll l,ll r,ll s ,ll t,ll p){
if(l<=s&&t<=r)
return node[p];
ll m=(s+t)/2,sum=0;
if(lazy[p]){
node[p*2]+=lazy[p]*(m-s+1), node[p*2+1]+=lazy[p]*(t-m);
lazy[p*2]+=lazy[p],lazy[p*2+1]+=lazy[p];
}
lazy[p]=0;
if(l<=m) sum+=getsum(l,r,s,m,p*2);
if(r>m) sum+=getsum(l,r,m+1,t,p*2+1);
return sum;
}
void updateplus(ll l, ll r, ll c, ll s, ll t, ll p) {
if (l <= s && t <= r) {
node[p] += (t - s + 1) * c, lazy[p] += c;
return;
}
ll m = (s + t)/2;
if (lazy[p])
node[p*2] += lazy[p]*(m-s+1), node[(p *2)+1] += lazy[p] * (t - m),
lazy[p *2] += lazy[p], lazy[(p*2)+1] += lazy[p];
lazy[p] = 0;
if (l <= m) updateplus(l, r, c, s, m, p *2);
if (r > m) updateplus(l, r, c, m + 1, t, (p *2)+1);
node[p] = node[p*2] + node[p*2+1];
}
inline void updatereplace(ll l,ll r,ll c,ll s,ll t ,ll p){
if(l<=s&&t<=r){
node[p]=(t-s+1)*c,lazy[p]=c;
return ;
}
ll m = (s + t)/2;
if (lazy[p])
node[p*2] += lazy[p]*(m-s+1), node[(p *2)+1] += lazy[p] * (t - m),
lazy[p *2] += lazy[p], lazy[(p*2)+1] += lazy[p];
lazy[p] = 0;
if (l <= m) updateplus(l, r, c
kuangbin 线段树题解打印
最新推荐文章于 2021-01-19 17:58:25 发布
这是一篇关于线段树在处理区间乘法问题上的应用,内容涉及如何使用线段树计算多个矩形覆盖区域内至少被覆盖两次的区域面积。题目描述给出,测试数据数量不超过100,每个数据包含1000个以内的矩形,矩形的边界坐标为浮点数,且限制在0到100000之间。输出要求保留两位小数。
摘要由CSDN通过智能技术生成