#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int L[200000],D[200000],R[200000],U[200000];
vi xLines,yLines;
int order[200000];
struct rect { int l,d,r,u; };
vector<rect> ans;
int main() {
int i;
int N,K;
scanf("%d %d",&N,&K);
for (i = 0; i < N; i++) {
scanf("%d %d %d %d",&L[i],&D[i],&R[i],&U[i]);
xLines.pb(L[i]),xLines.pb(R[i]+1);
yLines.pb(D[i]),yLines.pb(U[i]+1);
}
sort(xLines.begin(),xLines.end());
xLines.resize(unique(xLines.begin(),xLines.end())-xLines.begin());
sort(yLines.begin(),yLines.end());
yLines.resize(unique(yLines.begin(),yLines.end())-yLines.begin());
for (i = 0; i < N; i++) {
L[i] = lower_bound(xLines.begin(),xLines.end(),L[i])-xLines.begin();
D[i] = lower_bound(yLines.begin(),yLines.end(),D[i])-yLines.begin();
R[i] = lower_bound(xLines.begin(),xLines.end(),R[i]+1)-xLines.begin()-1;
U[i] = lower_bound(yLines.begin(),yLines.end(),U[i]+1)-yLines.begin()-1;
}
int j;
for (i = 0; i < N; i++) order[i] = i;
while (1) {
random_shuffle(order,order+N);
for (i = 0; i < N; i++) {
int u = order[i];
for (j = 0; j < ans.size(); j++) {
if ((L[u] > ans[j].r) || (R[u] < ans[j].l) || (D[u] > ans[j].u) || (U[u] < ans[j].d)) continue;
else {
ans[j].l = max(ans[j].l,L[u]);
ans[j].d = max(ans[j].d,D[u]);
ans[j].r = min(ans[j].r,R[u]);
ans[j].u = min(ans[j].u,U[u]);
break;
}
}
if (j == ans.size()) ans.pb((rect){L[u],D[u],R[u],U[u]});
if (ans.size() > K) break;
}
if (i == N) {
for (j = 0; j < K; j++) {
if (j < ans.size()) printf("%d %d\n",xLines[ans[j].l],yLines[ans[j].d]);
else printf("0 0\n");
}
return 0;
}
else ans.clear();
}
return 0;
}
Compilation message
hamburg.cpp: In function 'int main()':
hamburg.cpp:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (j = 0; j < ans.size(); j++) {
| ~~^~~~~~~~~~~~
hamburg.cpp:99:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | if (j == ans.size()) ans.pb((rect){L[u],D[u],R[u],U[u]});
| ~~^~~~~~~~~~~~~
hamburg.cpp:100:28: warning: comparison of integer expressions of different signedness: 'std::vector<rect>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
100 | if (ans.size() > K) break;
| ~~~~~~~~~~~^~~
hamburg.cpp:104:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | if (j < ans.size()) printf("%d %d\n",xLines[ans[j].l],yLines[ans[j].d]);
| ~~^~~~~~~~~~~~
hamburg.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
66 | scanf("%d %d",&N,&K);
| ~~~~~^~~~~~~~~~~~~~~
hamburg.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | scanf("%d %d %d %d",&L[i],&D[i],&R[i],&U[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
78 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
384 KB |
Output is correct |
10 |
Correct |
19 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
484 KB |
Output is correct |
12 |
Correct |
15 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
600 ms |
476 KB |
Output is correct |
8 |
Correct |
819 ms |
384 KB |
Output is correct |
9 |
Correct |
76 ms |
384 KB |
Output is correct |
10 |
Correct |
564 ms |
508 KB |
Output is correct |
11 |
Correct |
937 ms |
508 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
853 ms |
476 KB |
Output is correct |
14 |
Correct |
353 ms |
384 KB |
Output is correct |
15 |
Correct |
37 ms |
384 KB |
Output is correct |
16 |
Correct |
77 ms |
384 KB |
Output is correct |
17 |
Correct |
463 ms |
384 KB |
Output is correct |
18 |
Correct |
159 ms |
504 KB |
Output is correct |
19 |
Correct |
89 ms |
504 KB |
Output is correct |
20 |
Correct |
2013 ms |
476 KB |
Output is correct |
21 |
Correct |
30 ms |
484 KB |
Output is correct |
22 |
Correct |
175 ms |
384 KB |
Output is correct |
23 |
Correct |
128 ms |
476 KB |
Output is correct |
24 |
Correct |
242 ms |
472 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
27 ms |
480 KB |
Output is correct |
28 |
Correct |
61 ms |
472 KB |
Output is correct |
29 |
Correct |
126 ms |
384 KB |
Output is correct |
30 |
Correct |
11 ms |
384 KB |
Output is correct |
31 |
Execution timed out |
3054 ms |
384 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
416 KB |
Output is correct |
5 |
Correct |
363 ms |
7632 KB |
Output is correct |
6 |
Correct |
379 ms |
7568 KB |
Output is correct |
7 |
Correct |
376 ms |
7504 KB |
Output is correct |
8 |
Correct |
385 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
972 ms |
7644 KB |
Output is correct |
6 |
Correct |
1261 ms |
7584 KB |
Output is correct |
7 |
Execution timed out |
3034 ms |
7628 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
78 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
384 KB |
Output is correct |
10 |
Correct |
19 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
484 KB |
Output is correct |
12 |
Correct |
15 ms |
384 KB |
Output is correct |
13 |
Correct |
2467 ms |
7632 KB |
Output is correct |
14 |
Correct |
1345 ms |
7628 KB |
Output is correct |
15 |
Correct |
1178 ms |
7632 KB |
Output is correct |
16 |
Execution timed out |
3076 ms |
7636 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
600 ms |
476 KB |
Output is correct |
8 |
Correct |
819 ms |
384 KB |
Output is correct |
9 |
Correct |
76 ms |
384 KB |
Output is correct |
10 |
Correct |
564 ms |
508 KB |
Output is correct |
11 |
Correct |
937 ms |
508 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
853 ms |
476 KB |
Output is correct |
14 |
Correct |
353 ms |
384 KB |
Output is correct |
15 |
Correct |
37 ms |
384 KB |
Output is correct |
16 |
Correct |
77 ms |
384 KB |
Output is correct |
17 |
Correct |
463 ms |
384 KB |
Output is correct |
18 |
Correct |
159 ms |
504 KB |
Output is correct |
19 |
Correct |
89 ms |
504 KB |
Output is correct |
20 |
Correct |
2013 ms |
476 KB |
Output is correct |
21 |
Correct |
30 ms |
484 KB |
Output is correct |
22 |
Correct |
175 ms |
384 KB |
Output is correct |
23 |
Correct |
128 ms |
476 KB |
Output is correct |
24 |
Correct |
242 ms |
472 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
27 ms |
480 KB |
Output is correct |
28 |
Correct |
61 ms |
472 KB |
Output is correct |
29 |
Correct |
126 ms |
384 KB |
Output is correct |
30 |
Correct |
11 ms |
384 KB |
Output is correct |
31 |
Execution timed out |
3054 ms |
384 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |