[HAOI2014]贴海报

Posted xayata

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[HAOI2014]贴海报相关的知识,希望对你有一定的参考价值。

http://cogs.pro:8080/cogs/problem/problem.php?pid=1682

线段树单点修改,单点查询

#include <bits/stdc++.h>

using namespace std;
const int N = 1e7 + 10;

#define gc getchar()
#define lson jd << 1
#define rson jd << 1| 1 

int W[N << 2];
bool O[1010];
int js;

inline int read(){
    int x = 0, f = 1; char c = gc;
    while(c < 0 || c > 9) {if(c == -) f = -1; c = gc;}
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, c = gc;
    return x * f;
}

void Sec_G(int l, int r, int jd, int x, int y, int g){
    if(x <= l && r <= y) {W[jd] = g; return ;}
    if(W[jd]) {W[lson] = W[jd], W[rson] = W[jd], W[jd] = 0;    }
    int mid = (l + r) >> 1;
    if(x <= mid) Sec_G(l, mid, lson, x, y, g);
    if(y > mid) Sec_G(mid + 1, r, rson, x, y, g);
}

void dfs_tree(int l, int r, int jd){
    if(l == r) {O[W[jd]] = 1; return ;}
    if(W[jd]) {W[lson] = W[jd]; W[rson] = W[jd];}
    int mid = (l + r) >> 1;
    dfs_tree(l, mid, lson);
    dfs_tree(mid + 1, r, rson);
}

int main()
{
    freopen("ha14d.in", "r", stdin);
    freopen("ha14d.out", "w", stdout);
    int n = read(), T = read();
    while(T --){
        js ++;
        int x = read(), y = read();
        Sec_G(1, n, 1, x, y, js);
    }
    dfs_tree(1, n, 1);
    int answer(0);
    for(int i = 1; i <= 1001; i ++) if(O[i]) answer ++;
    cout << answer;
    return 0;    
}

 

以上是关于[HAOI2014]贴海报的主要内容,如果未能解决你的问题,请参考以下文章

[haoi2014]贴海报

cogs1682. [HAOI2014]贴海报 x

[HAOI2014]贴海报

洛谷 3740 [HAOI2014]贴海报

luogu 3740 [HAOI2014] 贴海报

题解 P3740 [HAOI2014]贴海报