IOI1998 Picture 线段树

该博客详细介绍了如何使用线段树解决IOI1998年的Picture问题。通过扫描线法,记录区间端点的覆盖情况和水平线数量,博主分析了在累加答案时要考虑线段覆盖的影响,并提供了AC代码实现。
摘要由CSDN通过智能技术生成

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1828

分析

扫描线法,线段树节点同时记录区间端点是否被覆盖,区间中有几条水平线,

累加答案时,注意线段会有覆盖,因此应加上变化量;

根据记录的水平线数量统计上水平线长度。

AC代码

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

inline int read() {
   
    int num = 0, flag = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
   
        if (c == '-') flag = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        num = num * 10 + c - '0', c = getchar();
    return flag * num;
}

const int maxn = 5e3 + 5;

struct Line {
   
    int x, y1, y2, k;

    bool operator < (const Line& rhs) const {
   
        return x < rhs.x;
    }
} line[2 * maxn];

int n, a[2 * maxn];

struct SegmentTree {
   
    int l, r, cnt, len, lf, rf, num;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值