TallestCows

题目大意:给定n个数字,其中已知某一个最大,并告知一些关系“哪些数字是小于某些区间端点的”,求合法序列下,数字的最大值。

对于区间处理问题,考虑差分,在需要操作的区间首端点处以及尾端点+1或者-1处进行标记处理一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* By Youngore
* Time:22.10.17
*/
#include <cstdio>
#include <map>
#include <iostream>
using namespace std;
const int N = 1e4 + 66;

int n, p, h, m;
int d[N], c[N];
map<pair<int,int>, bool>existed;

inline int youngore()
{
int i; scanf ("%d%d%d%d", &n, &p, &h, &m);
for (i = 1; i <= m; ++ i)
{
int x, y; scanf ("%d%d", &x, &y);
if (x > y) swap(x, y);
if (existed[make_pair(x, y)]) continue;
existed[make_pair(x, y)] = true;
d[x + 1] -= 1, d[y] += 1;
}
for (i = 1; i <= n; ++ i)
{
c[i] = c[i - 1] + d[i];
printf ("%d\n", h + c[i]);
}
return 0;
}

int thestars = youngore();

signed main() {;}