UVA11983 - Weird Advertisement(扫描线)

UVA11983 - Weird Advertisement(扫描线)

题目链接

题目大意:给你n个覆盖矩形,问哪些整数点是被覆盖了k次。

题目大意:这题和hdu1542是一个题型,但是这题求的是覆盖k次的点,所以pushup里面就要改一下,具体的看代码把,大概的意思就是每次都是通过下面的两个孩子节点的覆盖信息更新父节点的覆盖信息。然后这题也是需要离散化建树。比较需要注意的是这题和hdu1542不一样的地方是边界,因为那题是求面积,边界并不需要考虑,而这题是求点的个数,边界上的点也是要算的。建树的时候考虑叶子节点范围的时候就要包括边界上的点。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define lson(x) (x<<1)
#define rson(x) ((x<<1) | 1)

const int maxn = 60005;
typedef long long ll;

struct Line {

    int x, y1, y2, flag;
    Line (int x, int y1, int y2, int flag) {

        this->x = x;
        this->y1 = y1;
        this->y2 = y2;
        this->flag = flag;
    }

    bool operator < (const Line & a) const {
        return x < a.x;
    }
};

struct Node {

    int l, r, add;
    ll s[12];
    void set (int l, int r, int add) {

        this->l = l;
        this->r = r;
        this->add = add;
    }
}node[maxn * 4];


vector<int> pos;
vector<Line> L;
int n, k;

void pushup(int u) {

    for (int i = 0; i <= k; i++)
        node[u].s[i] = 0L;

    int t;
    if (node[u].l == node[u].r) {
        t = min(k, node[u].add);
        node[u].s[t] = pos[node[u].l + 1] - pos[node[u].l]; 
    } else {
        for (int i = 0; i <= k; i++) {    
            t = min (i + node[u].add, k);
            node[u].s[t] += node[lson(u)].s[i] + node[rson(u)].s[i];
        }
    }
}

void build (int u, int l, int r) {

    node[u].set(l, r, 0);

    if (l == r) { 
        pushup(u);
        return;
    }

    int m = (l + r)>>1;
    build(lson(u), l, m);
    build(rson(u), m + 1, r);
    pushup(u);
}

void update (int u, int l, int r , int v) {

    if (l <= node[u].l && r >= node[u].r) {
        node[u].add += v;
        pushup(u);
        return;
    }

    int m = (node[u].l + node[u].r)>>1;
    if (l <= m)
        update (lson(u), l, r, v);
    if (r > m)
        update (rson(u), l, r, v);
    pushup(u);
}

void init () {

    int x1, y1, x2, y2;
    scanf ("%d%d", &n, &k);
    L.clear();
    pos.clear();

    for (int i = 0; i < n; i++) {

        scanf ("%d%d%d%d", &x1, &y1, &x2, &y2);

        L.push_back(Line(x1, y1, y2 + 1, 1));
        L.push_back(Line(x2 + 1, y1, y2 + 1, -1));
        pos.push_back(y1);
        pos.push_back(y2 + 1);
    }

    sort(L.begin(), L.end());
    sort(pos.begin(), pos.end());
    pos.erase (unique(pos.begin(), pos.end()), pos.end());

    build(1, 0, (int)pos.size() - 1);
}

ll solve () {

    init();
    ll ans = 0;

    int l, r;
    for (int i = 0; i < L.size() - 1; i++) {

        l = lower_bound(pos.begin(), pos.end(), L[i].y1) - pos.begin();    
        r = lower_bound(pos.begin(), pos.end(), L[i].y2) - pos.begin();

        update (1, l, r - 1, L[i].flag);
        ans += node[1].s[k] * (L[i + 1].x - L[i].x);  
    }
    return ans;    
}

int main () {

    int T;
    scanf ("%d", &T);

    for (int cas = 1; cas <= T; cas++)
        printf ("Case %d: %lld\n", cas, solve());
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"text/plain;charset=UTF-8" 是一个Content-Type的标识,用于指定请求或响应的内容类型。在引用和中提到的问题中,"text/plain;charset=UTF-8" 表示请求中的内容类型不受支持或响应中的内容类型不正确。 通常,"text/plain;charset=UTF-8" 表示纯文本内容,使用UTF-8编码。如果您在使用Postman发送POST请求时遇到此错误消息,可能是因为您没有正确设置请求的头部信息或请求体的内容类型。 要解决此问题,您可以尝试以下几种方法: 1. 在Postman中,确保您设置了正确的请求头部信息。您可以在请求头中添加"Content-Type: text/plain;charset=UTF-8",以指定请求的内容类型。 2. 检查您的请求体内容是否符合"text/plain;charset=UTF-8" 的格式要求。确保您正在发送的是纯文本,并使用UTF-8编码。 3. 如果您正在与某个API进行通信,请参考API文档,查看它所需的正确的内容类型。 需要注意的是,具体的解决方法可能因您的具体情况而有所不同。如果以上方法无法解决您的问题,建议您查看Postman的文档或联系API的提供方以获取更具体的帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Content type ‘text/plain;charset=UTF-8‘ not supported](https://blog.csdn.net/SmartYG/article/details/124824940)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [weird-text](https://download.csdn.net/download/weixin_42097450/15884138)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [RestTemplate远程调用,响应结果中的响应头为content-type:text/plain;charset=utf-8,且数据类型转换失败](https://blog.csdn.net/Staba/article/details/124442200)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值