kuangbin 线段树题解打印

这是一篇关于线段树在处理区间乘法问题上的应用,内容涉及如何使用线段树计算多个矩形覆盖区域内至少被覆盖两次的区域面积。题目描述给出,测试数据数量不超过100,每个数据包含1000个以内的矩形,矩形的边界坐标为浮点数,且限制在0到100000之间。输出要求保留两位小数。
摘要由CSDN通过智能技术生成
#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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值