LOJ 2279「SCOI2007」降雨量

早就听闻过 BZOJ 上这道题的神贴了,虽然 BZOJ 现在没了...

显然就是线段树来维护一下区间最值,修改都不需要。
但是...
细节一车,对着下的两个样例检查才找到没考虑到的问题。
主要注意一下询问的\(x\),\(y\)数据没有给出的情况就可以了。
思维难度不大,主要是细节

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
using namespace std;

const int N = 50005;
int n, Q;
struct data {
int x, r;
bool operator < (const data &a) const {
return x < a.x;
}
} q[N];
map<int, int> m;

int mi[N << 2];
#define lson (p << 1)
#define rson (p << 1 | 1)
#define mid ((l + r) >> 1)
void build(int p, int l, int r) {
if (l == r) {
mi[p] = q[l].r;
return;
}
build(lson, l, mid);
build(rson, mid + 1, r);
mi[p] = max(mi[lson], mi[rson]);
}
int qry(int p, int l, int r, int L, int R) {
if (l > R || r < L) return -1000000007;
if (l >= L && r <= R) return mi[p];
return max(qry(lson, l, mid, L, R), qry(rson, mid + 1, r, L, R));
}

int main() {
// freopen("2.in", "r", stdin);
// freopen("2.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &q[i].x, &q[i].r);
}
sort(q + 1, q + 1 + n);
for (int i = 1; i <= n; i++) m[q[i].x] = i;
build(1, 1, n);
scanf("%d", &Q);
for (int i = 1; i <= Q; i++) {
int x, y; //x, y 是年份
scanf("%d %d", &y, &x);
if (!m[y] && !m[x]) {
puts("maybe");
continue;
}
if (!m[x]) {
int px = upper-bound(q + 1, q + n + 1, (data){x, 0}) - q - 1;
int py = m[y];
if (px - py <= 1) {
if (q[py].r <= q[px].r && px != py) puts("false");
else puts("maybe");
continue;
}
int z = qry(1, 1, n, py + 1, px);
if (z >= q[py].r) puts("false");
else puts("maybe");
continue;
}
bool fl = (m[y] != 0);
if (!fl) {
int py = lower-bound(q + 1, q + n + 1, (data){y, 0}) - q;
int px = m[x];
if (px - py <= 1) {
if (q[py].r >= q[px].r && px != py) puts("false");
else puts("maybe");
continue;
}
int z = qry(1, 1, n, py, px - 1);
if (z >= q[px].r) puts("false");
else puts("maybe");
continue;
}
int py = m[y], px = m[x];
if (q[py].r < q[px].r) {puts("false");continue;}
if (px - py <= 1) {if (x - y == px - py) puts("true"); else puts("maybe");continue;}
int z = qry(1, 1, n, py + 1, px - 1);
if (z >= q[px].r) puts("false");
else if (x - y == px - py) puts("true");
else puts("maybe");
}
return 0;
}

LOJ 2279「SCOI2007」降雨量
https://widsnoy.top/posts/e2cd/
作者
widsnoy
发布于
2020年8月31日
许可协议