#include <bits/stdc++.h>
using namespace std;
const int INF=2e9;
int n,k,c[200001][4],mn=INF,mx,mn2=INF,mx2,x,y,mask[200001];
vector <pair <int, int>> res;
vector <int> v,ve[16];
vector <pair <int, int>> type[16];
bool check(vector <int> v, int k){
if (v.empty()){
while (k--)
cout << 1 << ' ' << 1 << '\n';
return true;
}
if (!k)
return false;
int a[2]={INF,0},b[2]={INF,0};
for (int i:v){
a[0]=min(a[0],c[i][2]);
a[1]=max(a[1],c[i][0]);
b[0]=min(b[0],c[i][3]);
b[1]=max(b[1],c[i][1]);
}
for (int i=0;i<2;i++)
for (int j=0;j<2;j++){
vector <int> v2;
for (int k:v)
if (c[k][0]>a[i]||c[k][2]<a[i]||c[k][1]>b[j]||c[k][3]<b[j])
v2.push_back(k);
if (check(v2,k-1)){
cout << a[i] << ' ' << b[j] << '\n';
return true;
}
}
return false;
}
void strain(int idx, int a, int b, int sign=1, int dir=1){
x=a,y=b;
sort(ve[idx].begin(),ve[idx].end(),[](int i, int j){
return make_pair(c[i][x],c[i][y])<make_pair(c[j][x],c[j][y]);
});
int mx=-INF;
for (int i:ve[idx]){
if (dir){
while (!type[idx].empty()&&c[i][y]*sign<type[idx].back().second*sign)
type[idx].pop_back();
type[idx].push_back({c[i][x],c[i][y]});
}
else if (type[idx].empty()||c[i][y]*sign>type[idx].back().second*sign)
type[idx].push_back({c[i][x],c[i][y]});
}
}
void update(int i, int p, int &x){
if (type[i].empty())
return;
int tmp=upper_bound(type[i].begin(),type[i].end(),make_pair(p,INF))-type[i].begin();
if (tmp<type[i].size())
x=min(x,type[i][tmp].second);
}
int f(int mask, int pos, int pos2=-INF){
int res=(type[mask].empty()?INF:type[mask][0].second);
update(6,pos2,res);
if (!type[mask|1].empty()){
if (mask==4){
int tmp=lower_bound(type[5].begin(),type[5].end(),make_pair(pos,0))-type[5].begin()-1;
if (tmp>=0)
res=min(res,type[5][tmp].second);
}
else
update(3,pos,res);
}
return res;
}
pair <int, int> calc(int x, int y){
int l=INF,r=INF;
update(12,x,r);
update(10,y,l);
return {(l==INF?0:l),r};
}
void check(int pos, int i){
if (mask[i]%2==0||(!type[1].empty()&&(pos<type[1].back().first||pos>type[1][0].second)))
return;
int l=0,r=INF;
if (!type[8].empty()){
l=type[8].back().first;
r=type[8][0].second;
}
if (!type[9].empty()){
if (pos<=type[9][0].second){
int tmp=upper_bound(type[9].begin(),type[9].end(),make_pair(pos,INF))-type[9].begin();
if (tmp<type[9].size()){
l=max(l,type[9].back().first);
r=min(r,type[9][tmp].second);
}
}
else if (pos>=type[9].back().first){
int lo=0,hi=type[9].size(),kq=-1;
while (lo<=hi){
int mid=(lo+hi)>>1;
if (type[9][mid].second<pos){
l=max(l,type[9][mid].first);
kq=mid;
lo=mid+1;
}
else
hi=mid-1;
}
if (kq!=-1)
r=min(r,type[9][0].second);
}
else{
l=max(l,type[9].back().first);
r=min(r,type[9][0].second);
}
}
int pos2=f(4,pos);
if (type[4].empty()||(!type[4].empty()&&type[4].back().first<=pos2)){
int pos3=f(2,pos,pos2);
if (type[2].empty()||(!type[2].empty()&&type[2].back().first<=pos3)){
if (type[6].empty()||(!type[6].empty()&&type[6].back().first<=pos3)){
auto [x,y]=calc(pos2,pos3);
if (max(l,x)<=min(r,y)){
cout << mn << ' ' << pos << '\n' << pos2 << ' ' << mn2 << '\n' << pos3 << ' ' << mx2 << '\n' << mx << ' ' << max(l,x);
exit(0);
}
}
}
}
pos2=f(2,pos);
if (type[2].empty()||(!type[2].empty()&&type[2].back().first<=pos2)){
int pos3=f(4,pos,pos2);
if (type[4].empty()||(!type[4].empty()&&type[4].back().first<=pos3)){
if (type[6].empty()||(!type[6].empty()&&type[6].back().first<=pos3)){
auto [x,y]=calc(pos3,pos2);
if (max(l,x)<=min(r,y)){
cout << mn << ' ' << pos << '\n' << pos2 << ' ' << mx2 << '\n' << pos3 << ' ' << mn2 << '\n' << mx << ' ' << max(l,x);
exit(0);
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> k;
for (int i=0;i<n;i++){
for (int j=0;j<4;j++)
cin >> c[i][j];
v.push_back(i);
}
if (check(v,k))
return 0;
for (int i=0;i<n;i++){
mn=min(mn,c[i][2]);
mx=max(mx,c[i][0]);
mn2=min(mn2,c[i][3]);
mx2=max(mx2,c[i][1]);
}
for (int i=0;i<n;i++){
mask[i]=(c[i][0]<=mn)+(c[i][3]>=mx2)*2+(c[i][1]<=mn2)*4+(c[i][2]>=mx)*8;
if (__builtin_popcount(mask[i])<3)
ve[mask[i]].push_back(i);
}
strain(1,1,3);
strain(2,0,2);
strain(4,0,2);
strain(8,1,3);
strain(3,1,2);
strain(5,3,2,-1,0);
strain(10,0,1,-1);
strain(12,0,3);
strain(9,1,3);
strain(6,0,2);
for (int i=0;i<n;i++){
check(c[i][1],i);
check(c[i][3],i);
}
}
Compilation message
hamburg.cpp: In function 'void strain(int, int, int, int, int)':
hamburg.cpp:41:9: warning: unused variable 'mx' [-Wunused-variable]
41 | int mx=-INF;
| ^~
hamburg.cpp: In function 'void update(int, int, int&)':
hamburg.cpp:56:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | if (tmp<type[i].size())
| ~~~^~~~~~~~~~~~~~~
hamburg.cpp: In function 'void check(int, int)':
hamburg.cpp:90:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if (tmp<type[9].size()){
| ~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2520 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2532 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
4 ms |
2396 KB |
Output is correct |
15 |
Correct |
3 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
4 ms |
2396 KB |
Output is correct |
18 |
Correct |
3 ms |
2648 KB |
Output is correct |
19 |
Correct |
3 ms |
2648 KB |
Output is correct |
20 |
Correct |
4 ms |
2596 KB |
Output is correct |
21 |
Correct |
4 ms |
2652 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
5 ms |
2652 KB |
Output is correct |
24 |
Correct |
3 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2528 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
3 ms |
2652 KB |
Output is correct |
31 |
Correct |
4 ms |
2652 KB |
Output is correct |
32 |
Correct |
3 ms |
2648 KB |
Output is correct |
33 |
Correct |
3 ms |
2652 KB |
Output is correct |
34 |
Correct |
4 ms |
2652 KB |
Output is correct |
35 |
Correct |
3 ms |
2592 KB |
Output is correct |
36 |
Correct |
3 ms |
2652 KB |
Output is correct |
37 |
Correct |
4 ms |
2672 KB |
Output is correct |
38 |
Correct |
4 ms |
2652 KB |
Output is correct |
39 |
Correct |
3 ms |
2672 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
41 |
Correct |
3 ms |
2648 KB |
Output is correct |
42 |
Correct |
5 ms |
2652 KB |
Output is correct |
43 |
Correct |
3 ms |
2652 KB |
Output is correct |
44 |
Correct |
3 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2652 KB |
Output is correct |
46 |
Correct |
4 ms |
2648 KB |
Output is correct |
47 |
Correct |
3 ms |
2652 KB |
Output is correct |
48 |
Correct |
4 ms |
2596 KB |
Output is correct |
49 |
Correct |
4 ms |
2664 KB |
Output is correct |
50 |
Correct |
3 ms |
2652 KB |
Output is correct |
51 |
Correct |
4 ms |
2680 KB |
Output is correct |
52 |
Correct |
3 ms |
2652 KB |
Output is correct |
53 |
Correct |
3 ms |
2652 KB |
Output is correct |
54 |
Correct |
4 ms |
2652 KB |
Output is correct |
55 |
Correct |
3 ms |
2652 KB |
Output is correct |
56 |
Correct |
3 ms |
2652 KB |
Output is correct |
57 |
Correct |
3 ms |
2652 KB |
Output is correct |
58 |
Correct |
3 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2548 KB |
Output is correct |
5 |
Correct |
83 ms |
5840 KB |
Output is correct |
6 |
Correct |
64 ms |
5892 KB |
Output is correct |
7 |
Correct |
62 ms |
5748 KB |
Output is correct |
8 |
Correct |
62 ms |
5832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
64 ms |
6348 KB |
Output is correct |
6 |
Correct |
66 ms |
6520 KB |
Output is correct |
7 |
Correct |
66 ms |
6468 KB |
Output is correct |
8 |
Correct |
86 ms |
8484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2520 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2532 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
64 ms |
6604 KB |
Output is correct |
14 |
Correct |
71 ms |
6940 KB |
Output is correct |
15 |
Correct |
63 ms |
6128 KB |
Output is correct |
16 |
Correct |
66 ms |
6312 KB |
Output is correct |
17 |
Correct |
65 ms |
6968 KB |
Output is correct |
18 |
Correct |
65 ms |
6252 KB |
Output is correct |
19 |
Correct |
64 ms |
7116 KB |
Output is correct |
20 |
Correct |
68 ms |
7904 KB |
Output is correct |
21 |
Correct |
134 ms |
10544 KB |
Output is correct |
22 |
Correct |
87 ms |
8592 KB |
Output is correct |
23 |
Correct |
81 ms |
9552 KB |
Output is correct |
24 |
Correct |
90 ms |
10224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
4 ms |
2396 KB |
Output is correct |
15 |
Correct |
3 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
4 ms |
2396 KB |
Output is correct |
18 |
Correct |
3 ms |
2648 KB |
Output is correct |
19 |
Correct |
3 ms |
2648 KB |
Output is correct |
20 |
Correct |
4 ms |
2596 KB |
Output is correct |
21 |
Correct |
4 ms |
2652 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
5 ms |
2652 KB |
Output is correct |
24 |
Correct |
3 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2528 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
3 ms |
2652 KB |
Output is correct |
31 |
Correct |
4 ms |
2652 KB |
Output is correct |
32 |
Correct |
3 ms |
2648 KB |
Output is correct |
33 |
Correct |
3 ms |
2652 KB |
Output is correct |
34 |
Correct |
4 ms |
2652 KB |
Output is correct |
35 |
Correct |
3 ms |
2592 KB |
Output is correct |
36 |
Correct |
3 ms |
2652 KB |
Output is correct |
37 |
Correct |
4 ms |
2672 KB |
Output is correct |
38 |
Correct |
4 ms |
2652 KB |
Output is correct |
39 |
Correct |
3 ms |
2672 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
41 |
Correct |
3 ms |
2648 KB |
Output is correct |
42 |
Correct |
5 ms |
2652 KB |
Output is correct |
43 |
Correct |
3 ms |
2652 KB |
Output is correct |
44 |
Correct |
3 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2652 KB |
Output is correct |
46 |
Correct |
4 ms |
2648 KB |
Output is correct |
47 |
Correct |
3 ms |
2652 KB |
Output is correct |
48 |
Correct |
4 ms |
2596 KB |
Output is correct |
49 |
Correct |
4 ms |
2664 KB |
Output is correct |
50 |
Correct |
3 ms |
2652 KB |
Output is correct |
51 |
Correct |
4 ms |
2680 KB |
Output is correct |
52 |
Correct |
3 ms |
2652 KB |
Output is correct |
53 |
Correct |
3 ms |
2652 KB |
Output is correct |
54 |
Correct |
4 ms |
2652 KB |
Output is correct |
55 |
Correct |
3 ms |
2652 KB |
Output is correct |
56 |
Correct |
3 ms |
2652 KB |
Output is correct |
57 |
Correct |
3 ms |
2652 KB |
Output is correct |
58 |
Correct |
3 ms |
2648 KB |
Output is correct |
59 |
Correct |
67 ms |
11692 KB |
Output is correct |
60 |
Correct |
65 ms |
11212 KB |
Output is correct |
61 |
Correct |
69 ms |
11380 KB |
Output is correct |
62 |
Correct |
80 ms |
10900 KB |
Output is correct |
63 |
Correct |
88 ms |
11216 KB |
Output is correct |
64 |
Correct |
71 ms |
10452 KB |
Output is correct |
65 |
Correct |
103 ms |
11304 KB |
Output is correct |
66 |
Correct |
67 ms |
11212 KB |
Output is correct |
67 |
Correct |
120 ms |
14308 KB |
Output is correct |
68 |
Correct |
84 ms |
12968 KB |
Output is correct |
69 |
Correct |
73 ms |
12256 KB |
Output is correct |
70 |
Correct |
120 ms |
13884 KB |
Output is correct |
71 |
Correct |
458 ms |
16228 KB |
Output is correct |
72 |
Correct |
382 ms |
16032 KB |
Output is correct |
73 |
Correct |
289 ms |
15920 KB |
Output is correct |
74 |
Correct |
223 ms |
16264 KB |
Output is correct |
75 |
Correct |
236 ms |
15592 KB |
Output is correct |
76 |
Correct |
220 ms |
16040 KB |
Output is correct |
77 |
Correct |
248 ms |
16292 KB |
Output is correct |
78 |
Correct |
421 ms |
16180 KB |
Output is correct |
79 |
Correct |
295 ms |
16108 KB |
Output is correct |
80 |
Correct |
219 ms |
15832 KB |
Output is correct |
81 |
Correct |
358 ms |
15984 KB |
Output is correct |
82 |
Correct |
253 ms |
15636 KB |
Output is correct |
83 |
Correct |
135 ms |
15440 KB |
Output is correct |
84 |
Correct |
118 ms |
13400 KB |
Output is correct |
85 |
Correct |
210 ms |
16328 KB |
Output is correct |
86 |
Correct |
155 ms |
14616 KB |
Output is correct |
87 |
Correct |
183 ms |
16040 KB |
Output is correct |
88 |
Correct |
174 ms |
15832 KB |
Output is correct |
89 |
Correct |
271 ms |
15592 KB |
Output is correct |
90 |
Correct |
377 ms |
16112 KB |
Output is correct |
91 |
Correct |
272 ms |
16400 KB |
Output is correct |
92 |
Correct |
416 ms |
16216 KB |
Output is correct |
93 |
Correct |
332 ms |
16060 KB |
Output is correct |
94 |
Correct |
402 ms |
16080 KB |
Output is correct |
95 |
Correct |
343 ms |
16168 KB |
Output is correct |
96 |
Correct |
320 ms |
16236 KB |
Output is correct |
97 |
Correct |
354 ms |
16388 KB |
Output is correct |
98 |
Correct |
325 ms |
15916 KB |
Output is correct |
99 |
Correct |
258 ms |
16252 KB |
Output is correct |
100 |
Correct |
412 ms |
16064 KB |
Output is correct |
101 |
Correct |
353 ms |
16156 KB |
Output is correct |
102 |
Correct |
240 ms |
13688 KB |
Output is correct |
103 |
Correct |
458 ms |
16016 KB |
Output is correct |
104 |
Correct |
246 ms |
14892 KB |
Output is correct |
105 |
Correct |
430 ms |
16352 KB |
Output is correct |
106 |
Correct |
390 ms |
15964 KB |
Output is correct |
107 |
Correct |
315 ms |
16024 KB |
Output is correct |
108 |
Correct |
420 ms |
16132 KB |
Output is correct |
109 |
Correct |
421 ms |
12068 KB |
Output is correct |
110 |
Correct |
344 ms |
12084 KB |
Output is correct |
111 |
Correct |
350 ms |
12080 KB |
Output is correct |
112 |
Correct |
427 ms |
12136 KB |
Output is correct |
113 |
Correct |
225 ms |
9252 KB |
Output is correct |
114 |
Correct |
294 ms |
9224 KB |
Output is correct |
115 |
Correct |
222 ms |
9160 KB |
Output is correct |
116 |
Correct |
222 ms |
9196 KB |
Output is correct |
117 |
Correct |
375 ms |
12188 KB |
Output is correct |
118 |
Correct |
298 ms |
11956 KB |
Output is correct |
119 |
Correct |
299 ms |
12112 KB |
Output is correct |
120 |
Correct |
301 ms |
12064 KB |
Output is correct |
121 |
Correct |
302 ms |
12080 KB |
Output is correct |
122 |
Correct |
299 ms |
12052 KB |
Output is correct |
123 |
Correct |
297 ms |
12044 KB |
Output is correct |
124 |
Correct |
298 ms |
12060 KB |
Output is correct |
125 |
Correct |
319 ms |
12068 KB |
Output is correct |
126 |
Correct |
329 ms |
12112 KB |
Output is correct |