/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 2e5 + 10;
struct event
{
int tim, type, idx;
event(int _tim = 0, int _type = 0, int _idx = 0)
{
tim = _tim;
type = _type;
idx = _idx;
}
bool operator < (const event &e) const
{
if (tim != e.tim)
return tim < e.tim;
return type > e.type;
}
};
unordered_map < int, int > mx, revx;
unordered_map < int, int > my, revy;
struct point
{
int x, y;
point(int _x = 0, int _y = 0)
{
x = _x;
y = _y;
}
void input()
{
cin >> x >> y;
}
void print()
{
cout << revx[x] << " " << revy[y] << endl;
}
};
struct rectangle
{
point A, B;
rectangle()
{
A = point();
B = point();
}
void input()
{
A.input();
B.input();
}
} r[maxn];
int n, k;
void input()
{
cin >> n >> k;
for (int i = 1; i <= n; i ++)
r[i].input();
}
vector < int > pos_x, pos_y;
bool inside(pair < int, int > cur, rectangle rec)
{
if (cur.first >= rec.A.x && cur.first <= rec.B.x &&
cur.second >= rec.A.y && cur.second <= rec.B.y)
return true;
return false;
}
void solve1()
{
int min_x = 1e9, max_x = 1, min_y = 1e9, max_y = 1;
for (int i = 1; i <= n; i ++)
{
min_x = min(min_x, r[i].B.x);
max_x = max(max_x, r[i].A.x);
min_y = min(min_y, r[i].B.y);
max_y = max(max_y, r[i].A.y);
}
cout << revx[min_x] << " " << revy[min_y] << endl;
}
int used[maxn];
pair < point, point > solve2()
{
int min_x = 1e9, max_x = 1, min_y = 1e9, max_y = 1;
for (int i = 1; i <= n; i ++)
{
if (used[i])
continue;
min_x = min(min_x, r[i].B.x);
max_x = max(max_x, r[i].A.x);
min_y = min(min_y, r[i].B.y);
max_y = max(max_y, r[i].A.y);
}
if (min_x > max_x && min_y > max_y)
{
return {point(max_x, max_y), point(max_x, max_y)};
}
vector < point > cell;
cell.push_back(point(min_x, min_y));
cell.push_back(point(min_x, max_y));
cell.push_back(point(max_x, min_y));
cell.push_back(point(max_x, max_y));
///cout << min_x << " " << max_x << " " << min_y << " " << max_y << endl;
for (point d : cell)
for (point f : cell)
{
bool done = true;
for (int i = 1; i <= n; i ++)
{
if (used[i])
continue;
if (!inside({d.x, d.y}, r[i]) && !inside({f.x, f.y}, r[i]))
{
done = false;
break;
}
}
if (done)
{
return {d, f};
/**cout << d.x << " " << d.y << endl;
cout << f.x << " " << f.y << endl;
return;*/
}
}
return {point(-1, -1), point(-1, -1)};
}
struct sol3
{
point A, B, C;
sol3(point _A, point _B, point _C)
{
A = _A;
B = _B;
C = _C;
}
};
sol3 solve3()
{
//for (int i = 1; i <= n; i ++)
// cout << r[i].A.x << " " << r[i].A.y << " " << r[i].B.x << " " << r[i].B.y << endl;
int min_x = 1e9, max_x = 1, min_y = 1e9, max_y = 1;
for (int i = 1; i <= n; i ++)
{
if (used[i])
continue;
min_x = min(min_x, r[i].B.x);
max_x = max(max_x, r[i].A.x);
min_y = min(min_y, r[i].B.y);
max_y = max(max_y, r[i].A.y);
}
vector < point > cell;
cell.push_back(point(min_x, min_y));
cell.push_back(point(min_x, max_y));
cell.push_back(point(max_x, min_y));
cell.push_back(point(max_x, max_y));
for (point cur : cell)
{
for (int i = 1; i <= n; i ++)
{
if (used[i])
continue;
if (inside({cur.x, cur.y}, r[i]))
used[i] = 2;
}
pair < point, point > ans = solve2();
for (int i = 1; i <= n; i ++)
{
if (used[i] == 2)
used[i] = 0;
}
if (ans.first.x == -1)
continue;
return sol3(cur, ans.first, ans.second);
/**cout << cur.x << " " << cur.y << endl;
cout << ans.first.x << " " << ans.first.y << endl;
cout << ans.second.x << " " << ans.second.y << endl;
return;*/
}
return sol3(point(-1, -1), point(-1, -1), point(-1, -1));
}
void solve4()
{
int min_x = 1e9, max_x = 1, min_y = 1e9, max_y = 1;
for (int i = 1; i <= n; i ++)
{
min_x = min(min_x, r[i].B.x);
max_x = max(max_x, r[i].A.x);
min_y = min(min_y, r[i].B.y);
max_y = max(max_y, r[i].A.y);
}
if (min_x > max_x)
swap(min_x, max_x);
if (min_y > max_y)
swap(min_y, max_y);
vector < point > cell;
cell.push_back(point(min_x, min_y));
cell.push_back(point(min_x, max_y));
cell.push_back(point(max_x, min_y));
cell.push_back(point(max_x, max_y));
for (point cur : cell)
{
for (int i = 1; i <= n; i ++)
{
if (used[i])
continue;
if (inside({cur.x, cur.y}, r[i]))
used[i] = 3;
}
sol3 ans = solve3();
for (int i = 1; i <= n; i ++)
{
if (used[i] == 3)
used[i] = 0;
}
if (ans.A.x == -1)
continue;
cout << revx[cur.x] << " " << revy[cur.y] << endl;
ans.A.print();
ans.B.print();
ans.C.print();
return;
/**cout << cur.x << " " << cur.y << endl;
cout << ans.first.x << " " << ans.first.y << endl;
cout << ans.second.x << " " << ans.second.y << endl;
return;*/
}
for (int y = min_y; y <= max_y; y ++)
{
point cur(min_x, y);
for (int i = 1; i <= n; i ++)
{
if (used[i])
continue;
if (inside({cur.x, cur.y}, r[i]))
used[i] = 3;
}
sol3 ans = solve3();
for (int i = 1; i <= n; i ++)
{
if (used[i] == 3)
used[i] = 0;
}
if (ans.A.x == -1)
continue;
cout << revx[cur.x] << " " << revy[cur.y] << endl;
ans.A.print();
ans.B.print();
ans.C.print();
return;
/**cout << cur.x << " " << cur.y << endl;
cout << ans.first.x << " " << ans.first.y << endl;
cout << ans.second.x << " " << ans.second.y << endl;
return;*/
}
}
void compress()
{
vector < int > px;
for (int i = 1; i <= n; i ++)
{
px.push_back(r[i].A.x);
px.push_back(r[i].B.x);
}
sort(px.begin(), px.end());
for (int i = 0; i < 2 * n; i ++)
{
///cout << px[i] << " " << i << endl;
mx[px[i]] = i + 1, revx[i + 1] = px[i];
}
//for (int i = 1; i <= 2 * n; i ++)
// cout << i << " " << rev[i] << endl;
for (int i = 1; i <= n; i ++)
{
r[i].A.x = mx[r[i].A.x];
r[i].B.x = mx[r[i].B.x];
}
vector < int > py;
for (int i = 1; i <= n; i ++)
{
py.push_back(r[i].A.y);
py.push_back(r[i].B.y);
}
sort(py.begin(), py.end());
for (int i = 0; i < 2 * n; i ++)
my[py[i]] = i + 1, revy[i + 1] = py[i];
for (int i = 1; i <= n; i ++)
{
r[i].A.y = my[r[i].A.y];
r[i].B.y = my[r[i].B.y];
}
}
void solve()
{
input();
compress();
if (k == 1)
solve1();
if (k == 2)
{
pair < point, point > ans = solve2();
ans.first.print();
ans.second.print();
}
if (k == 3)
{
sol3 res = solve3();
res.A.print();
res.B.print();
res.C.print();
}
if (k == 4)
{
solve4();
}
}
int main()
{
///freopen("test.txt", "r", stdin);
solve();
return 0;
}
/**
634025969 413050209
458184763 724583533
351907664 172518940
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
4700 KB |
Output is correct |
4 |
Correct |
6 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
4852 KB |
Output is correct |
4 |
Correct |
5 ms |
4856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
7 ms |
4688 KB |
Output is correct |
4 |
Correct |
5 ms |
4700 KB |
Output is correct |
5 |
Correct |
5 ms |
4700 KB |
Output is correct |
6 |
Correct |
5 ms |
4668 KB |
Output is correct |
7 |
Correct |
5 ms |
4696 KB |
Output is correct |
8 |
Correct |
5 ms |
4700 KB |
Output is correct |
9 |
Correct |
7 ms |
4700 KB |
Output is correct |
10 |
Correct |
5 ms |
4700 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
5 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
4700 KB |
Output is correct |
4 |
Correct |
5 ms |
4700 KB |
Output is correct |
5 |
Correct |
5 ms |
4692 KB |
Output is correct |
6 |
Correct |
5 ms |
4700 KB |
Output is correct |
7 |
Correct |
5 ms |
4700 KB |
Output is correct |
8 |
Correct |
5 ms |
4680 KB |
Output is correct |
9 |
Correct |
5 ms |
4952 KB |
Output is correct |
10 |
Correct |
5 ms |
4700 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
5 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
4700 KB |
Output is correct |
14 |
Correct |
57 ms |
4700 KB |
Output is correct |
15 |
Correct |
5 ms |
4956 KB |
Output is correct |
16 |
Correct |
5 ms |
4956 KB |
Output is correct |
17 |
Correct |
93 ms |
4932 KB |
Output is correct |
18 |
Correct |
6 ms |
4952 KB |
Output is correct |
19 |
Correct |
5 ms |
4696 KB |
Output is correct |
20 |
Correct |
152 ms |
4952 KB |
Output is correct |
21 |
Correct |
5 ms |
4700 KB |
Output is correct |
22 |
Correct |
6 ms |
4956 KB |
Output is correct |
23 |
Correct |
63 ms |
4696 KB |
Output is correct |
24 |
Correct |
5 ms |
4700 KB |
Output is correct |
25 |
Correct |
5 ms |
4736 KB |
Output is correct |
26 |
Correct |
6 ms |
4956 KB |
Output is correct |
27 |
Correct |
5 ms |
4956 KB |
Output is correct |
28 |
Correct |
6 ms |
4956 KB |
Output is correct |
29 |
Correct |
5 ms |
4700 KB |
Output is correct |
30 |
Correct |
5 ms |
4700 KB |
Output is correct |
31 |
Correct |
46 ms |
4916 KB |
Output is correct |
32 |
Correct |
41 ms |
4696 KB |
Output is correct |
33 |
Correct |
64 ms |
4696 KB |
Output is correct |
34 |
Correct |
28 ms |
4956 KB |
Output is correct |
35 |
Correct |
71 ms |
4696 KB |
Output is correct |
36 |
Correct |
142 ms |
4700 KB |
Output is correct |
37 |
Correct |
52 ms |
4956 KB |
Output is correct |
38 |
Correct |
78 ms |
4792 KB |
Output is correct |
39 |
Correct |
168 ms |
4916 KB |
Output is correct |
40 |
Correct |
125 ms |
4956 KB |
Output is correct |
41 |
Correct |
13 ms |
4952 KB |
Output is correct |
42 |
Correct |
84 ms |
4700 KB |
Output is correct |
43 |
Correct |
103 ms |
4932 KB |
Output is correct |
44 |
Correct |
71 ms |
4712 KB |
Output is correct |
45 |
Correct |
6 ms |
4956 KB |
Output is correct |
46 |
Correct |
95 ms |
4696 KB |
Output is correct |
47 |
Correct |
131 ms |
4700 KB |
Output is correct |
48 |
Correct |
123 ms |
4916 KB |
Output is correct |
49 |
Correct |
69 ms |
4956 KB |
Output is correct |
50 |
Correct |
47 ms |
4924 KB |
Output is correct |
51 |
Correct |
131 ms |
4956 KB |
Output is correct |
52 |
Correct |
115 ms |
4696 KB |
Output is correct |
53 |
Correct |
51 ms |
4696 KB |
Output is correct |
54 |
Correct |
47 ms |
4700 KB |
Output is correct |
55 |
Correct |
119 ms |
4952 KB |
Output is correct |
56 |
Correct |
119 ms |
4924 KB |
Output is correct |
57 |
Correct |
114 ms |
4912 KB |
Output is correct |
58 |
Correct |
112 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
4700 KB |
Output is correct |
4 |
Correct |
6 ms |
4700 KB |
Output is correct |
5 |
Correct |
671 ms |
81980 KB |
Output is correct |
6 |
Correct |
658 ms |
82184 KB |
Output is correct |
7 |
Correct |
618 ms |
82100 KB |
Output is correct |
8 |
Correct |
595 ms |
81880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
4852 KB |
Output is correct |
4 |
Correct |
5 ms |
4856 KB |
Output is correct |
5 |
Correct |
605 ms |
82056 KB |
Output is correct |
6 |
Correct |
615 ms |
81924 KB |
Output is correct |
7 |
Correct |
607 ms |
82136 KB |
Output is correct |
8 |
Correct |
589 ms |
82092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
7 ms |
4688 KB |
Output is correct |
4 |
Correct |
5 ms |
4700 KB |
Output is correct |
5 |
Correct |
5 ms |
4700 KB |
Output is correct |
6 |
Correct |
5 ms |
4668 KB |
Output is correct |
7 |
Correct |
5 ms |
4696 KB |
Output is correct |
8 |
Correct |
5 ms |
4700 KB |
Output is correct |
9 |
Correct |
7 ms |
4700 KB |
Output is correct |
10 |
Correct |
5 ms |
4700 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
5 ms |
4700 KB |
Output is correct |
13 |
Correct |
642 ms |
82176 KB |
Output is correct |
14 |
Correct |
680 ms |
82100 KB |
Output is correct |
15 |
Correct |
690 ms |
82392 KB |
Output is correct |
16 |
Correct |
878 ms |
82140 KB |
Output is correct |
17 |
Correct |
793 ms |
82368 KB |
Output is correct |
18 |
Correct |
652 ms |
82368 KB |
Output is correct |
19 |
Correct |
649 ms |
82352 KB |
Output is correct |
20 |
Correct |
732 ms |
82632 KB |
Output is correct |
21 |
Correct |
770 ms |
82148 KB |
Output is correct |
22 |
Correct |
694 ms |
82336 KB |
Output is correct |
23 |
Correct |
681 ms |
82104 KB |
Output is correct |
24 |
Correct |
638 ms |
82100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
4700 KB |
Output is correct |
4 |
Correct |
5 ms |
4700 KB |
Output is correct |
5 |
Correct |
5 ms |
4692 KB |
Output is correct |
6 |
Correct |
5 ms |
4700 KB |
Output is correct |
7 |
Correct |
5 ms |
4700 KB |
Output is correct |
8 |
Correct |
5 ms |
4680 KB |
Output is correct |
9 |
Correct |
5 ms |
4952 KB |
Output is correct |
10 |
Correct |
5 ms |
4700 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
5 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
4700 KB |
Output is correct |
14 |
Correct |
57 ms |
4700 KB |
Output is correct |
15 |
Correct |
5 ms |
4956 KB |
Output is correct |
16 |
Correct |
5 ms |
4956 KB |
Output is correct |
17 |
Correct |
93 ms |
4932 KB |
Output is correct |
18 |
Correct |
6 ms |
4952 KB |
Output is correct |
19 |
Correct |
5 ms |
4696 KB |
Output is correct |
20 |
Correct |
152 ms |
4952 KB |
Output is correct |
21 |
Correct |
5 ms |
4700 KB |
Output is correct |
22 |
Correct |
6 ms |
4956 KB |
Output is correct |
23 |
Correct |
63 ms |
4696 KB |
Output is correct |
24 |
Correct |
5 ms |
4700 KB |
Output is correct |
25 |
Correct |
5 ms |
4736 KB |
Output is correct |
26 |
Correct |
6 ms |
4956 KB |
Output is correct |
27 |
Correct |
5 ms |
4956 KB |
Output is correct |
28 |
Correct |
6 ms |
4956 KB |
Output is correct |
29 |
Correct |
5 ms |
4700 KB |
Output is correct |
30 |
Correct |
5 ms |
4700 KB |
Output is correct |
31 |
Correct |
46 ms |
4916 KB |
Output is correct |
32 |
Correct |
41 ms |
4696 KB |
Output is correct |
33 |
Correct |
64 ms |
4696 KB |
Output is correct |
34 |
Correct |
28 ms |
4956 KB |
Output is correct |
35 |
Correct |
71 ms |
4696 KB |
Output is correct |
36 |
Correct |
142 ms |
4700 KB |
Output is correct |
37 |
Correct |
52 ms |
4956 KB |
Output is correct |
38 |
Correct |
78 ms |
4792 KB |
Output is correct |
39 |
Correct |
168 ms |
4916 KB |
Output is correct |
40 |
Correct |
125 ms |
4956 KB |
Output is correct |
41 |
Correct |
13 ms |
4952 KB |
Output is correct |
42 |
Correct |
84 ms |
4700 KB |
Output is correct |
43 |
Correct |
103 ms |
4932 KB |
Output is correct |
44 |
Correct |
71 ms |
4712 KB |
Output is correct |
45 |
Correct |
6 ms |
4956 KB |
Output is correct |
46 |
Correct |
95 ms |
4696 KB |
Output is correct |
47 |
Correct |
131 ms |
4700 KB |
Output is correct |
48 |
Correct |
123 ms |
4916 KB |
Output is correct |
49 |
Correct |
69 ms |
4956 KB |
Output is correct |
50 |
Correct |
47 ms |
4924 KB |
Output is correct |
51 |
Correct |
131 ms |
4956 KB |
Output is correct |
52 |
Correct |
115 ms |
4696 KB |
Output is correct |
53 |
Correct |
51 ms |
4696 KB |
Output is correct |
54 |
Correct |
47 ms |
4700 KB |
Output is correct |
55 |
Correct |
119 ms |
4952 KB |
Output is correct |
56 |
Correct |
119 ms |
4924 KB |
Output is correct |
57 |
Correct |
114 ms |
4912 KB |
Output is correct |
58 |
Correct |
112 ms |
4696 KB |
Output is correct |
59 |
Correct |
620 ms |
89672 KB |
Output is correct |
60 |
Correct |
641 ms |
89784 KB |
Output is correct |
61 |
Correct |
720 ms |
89784 KB |
Output is correct |
62 |
Correct |
720 ms |
89744 KB |
Output is correct |
63 |
Correct |
704 ms |
89744 KB |
Output is correct |
64 |
Correct |
645 ms |
89724 KB |
Output is correct |
65 |
Correct |
714 ms |
89892 KB |
Output is correct |
66 |
Correct |
705 ms |
89724 KB |
Output is correct |
67 |
Correct |
636 ms |
89772 KB |
Output is correct |
68 |
Correct |
626 ms |
89888 KB |
Output is correct |
69 |
Correct |
642 ms |
89912 KB |
Output is correct |
70 |
Correct |
647 ms |
90048 KB |
Output is correct |
71 |
Correct |
692 ms |
90032 KB |
Output is correct |
72 |
Execution timed out |
3043 ms |
89796 KB |
Time limit exceeded |
73 |
Halted |
0 ms |
0 KB |
- |