码迷,mamicode.com
首页 > 其他好文 > 详细

[Luogu] 区间统计Tallest Cow

时间:2018-02-20 15:00:19      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:iostream   区间   ==   blog   for   max   sort   bool   class   

https://www.luogu.org/problemnew/show/P2879

差分 | 线段树

#include <iostream>
#include <cstdio>
#include <algorithm>

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

#define gc getchar()

struct Node {int l, r;}A[N];
int n, my, Maxh, R;
int H[N];

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

inline bool cmp(Node a, Node b) {
    return a.l == b.l ? a.r < b.r : a.l < b.l;
}

int main() {
    n = read();
    my = read();
    Maxh = read();
    R = read();
    for(int i = 1; i <= R; i ++) {
        int one = read(), tow = read();
        A[i].l = min(one, tow);
        A[i].r = max(one, tow);
    }
    sort(A + 1, A + R + 1, cmp);
    H[A[1].l + 1] += 1;
    H[A[1].r] -= 1;
    for(int i = 2; i <= R; i ++) {
        if(A[i].l == A[i - 1].l && A[i].r == A[i - 1].r) continue ;
        H[A[i].l + 1] += 1;
        H[A[i].r] -= 1;
    }
    int tmp = 0;
    for(int i = 1; i <= n; i ++) {
        tmp += H[i];
        cout << Maxh - tmp << endl;
    }
    return 0;
}

 

[Luogu] 区间统计Tallest Cow

标签:iostream   区间   ==   blog   for   max   sort   bool   class   

原文地址:https://www.cnblogs.com/shandongs1/p/8455213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!