-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF4D.cpp
99 lines (98 loc) · 1.72 KB
/
CF4D.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
#include<algorithm>
using namespace std;
struct node {
int w = 0, h = 0, id = 0;
node* last = nullptr;
bool friend operator <(node a, node b) {
return ((a.w < b.w) || ((a.w == b.w) && (a.h > b.h)));
}
}arr[5001];
node * line[5001];
int n, num = 0, W, H, len = 0;
inline int read() {
char ch = getchar();
int f = 1, x = 0;
while (ch<'0' || ch>'9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0'&&ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f * x;
}
int lower(node a) {
int l = 1, r = len;
while (r - l > 1) {
int b = line[(l + r) / 2]->h;
if (b >= a.h) {
r = (l + r) / 2;
}
else {
l = (l + r) / 2;
}
}
if (line[l]->h >= a.h) {
return l;
}
else {
return r;
}
}
int main() {
n = read();
W = read();
H = read();
for (int i = 1;i <= n;i++) {
int a = read(), b = read();
if ((a > W) && (b > H)) {
arr[++num].id = i;
arr[num].w = a;
arr[num].h = b;
}
}
sort(arr + 1, arr + 1 + num);
for (int i = 1;i <= num;i++) {
int a = arr[i].w;
int b = arr[i].h;
if ((line[len] != nullptr) && (a == (line[len]->w))) {
if (b == line[len]->h) {
continue;
}
else {
int p = lower(arr[i]);
arr[i].last = line[p - 1];
line[p] = &(arr[i]);
}
}
else {
if ((line[len] == nullptr) || (b > line[len]->h)) {
arr[i].last = line[len];
line[++len] = &(arr[i]);
}
else {
if (b == line[len]->h) {
continue;
}
else {
int p = lower(arr[i]);
arr[i].last = line[p - 1];
line[p] = &(arr[i]);
}
}
}
}
cout << len << endl;
if (len) {
for (int i = len;i > 1;i--) {
line[i - 1] = line[i]->last;
}
for (int i = 1;i <= len;i++) {
cout << line[i]->id << " ";
}
}
return 0;
}