#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
#define F first
#define S second
#define MT make_tuple
#define MP make_pair
#define SZ(a) ((int)(a).size())
#define PB push_back
#define LBS 20
#define MOD ((long long)1e9+7) //1e9+9
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)
#define ALL(a) (a).begin(), (a).end()
#define END(s) {cout << s;return;}
using namespace std;
typedef long long ll;
typedef double rat;
typedef long long bi;
typedef pair<ll, ll> ii;
typedef std::vector<ii> vii;
typedef std::map<ll, ll> mii;
typedef bitset<LBS> bis;
typedef std::vector<bis> vbs;
typedef priority_queue<ii, std::vector<ii>, greater<ii> > minpq;
typedef priority_queue<ii, std::vector<ii>, less<ii> > maxpq;
typedef priority_queue<ii> pq;
struct ham{
ll l, d, r, u;
};
template<class T>
void in(T &a){
for(auto &x: a)
cin >> x;
}
template<class T>
void out(T &a, string sep=" "){
for(auto x: a)
cout << x<<sep;
cout << '\n';
}
template<class T>
void err(T &a, string sep=" "){
for(auto x: a)
cerr << x <<sep;
cerr << '\n';
}
std::vector<ham> h;
std::vector<int> ma;
std::vector<ii> ou;
int n, k;
void end(){
for(auto &x: ou)
cout << x.F<<" "<<x.S<<"\n";
exit(0);
}
template<class T>
void pop(T &pq){
while (!pq.empty() && ma[pq.top().S])
pq.pop();
if(pq.empty())
end();
}
void rek(minpq pqxi, maxpq pqxa, minpq pqyi, maxpq pqya, int idx=0){
pop(pqxi);
pop(pqxa);
pop(pqyi);
pop(pqya);
if(idx==k)
return;
ll xmi=pqxi.top().F;
ll xma=pqxa.top().F;
ll ymi=pqyi.top().F;
ll yma=pqya.top().F;
// if(xmi>=xma || ymi>=yma){
// ou[idx]={xmi,ymi};
// for(int i=0; i<n; i++)
// if(h[i].l<=xmi && xmi<=h[i].r && h[i].d<=ymi && ymi<=h[i].u)
// ma[i]++;
// rek(pqxi, pqxa, pqyi, pqya, idx+1);
// for(int i=0; i<n; i++)
// if(h[i].l<=xmi && xmi<=h[i].r && h[i].d<=ymi && ymi<=h[i].u)
// ma[i]--;
//
// }
for(auto &c: {MP(xmi,ymi),MP(xmi,yma),MP(xma,ymi),MP(xma,yma)}){
// std::cerr << c.F<<" "<<c.S << '\n';
ou[idx]=c;
for(int i=0; i<n; i++)
if(h[i].l<=c.F && c.F<=h[i].r && h[i].d<=c.S && c.S<=h[i].u)
ma[i]++;
rek(pqxi, pqxa, pqyi, pqya, idx+1);
for(int i=0; i<n; i++)
if(h[i].l<=c.F && c.F<=h[i].r && h[i].d<=c.S && c.S<=h[i].u)
ma[i]--;
}
if(idx==0 && k==4){
for(int i=0; i<n; i++){
assert(!ma[i]);
if(h[i].l<=xmi && xmi<=h[i].r){
for(auto &c: {MP(xmi,h[i].d),MP(xmi,h[i].u)}){
// std::cerr << c.F<<" "<<c.S << '\n';
ou[idx]=c;
for(int i=0; i<n; i++)
if(h[i].l<=c.F && c.F<=h[i].r && h[i].d<=c.S && c.S<=h[i].u)
ma[i]++;
rek(pqxi, pqxa, pqyi, pqya, idx+1);
for(int i=0; i<n; i++)
if(h[i].l<=c.F && c.F<=h[i].r && h[i].d<=c.S && c.S<=h[i].u)
ma[i]--;
}
}
}
end();
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
minpq pqxi, pqyi;
maxpq pqxa, pqya;
h.resize(n);
ou.resize(k,{1,1});
ma.resize(n,0);
for(int i=0; i<n; i++){
cin >> h[i].l>>h[i].d>>h[i].r>>h[i].u;
pqxi.emplace(h[i].r,i);
pqxa.emplace(h[i].l,i);
pqyi.emplace(h[i].u,i);
pqya.emplace(h[i].d,i);
}
rek(pqxi, pqxa, pqyi, pqya);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
896 KB |
Output is correct |
2 |
Correct |
3 ms |
876 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
3 ms |
912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
2 ms |
1024 KB |
Output is correct |
3 |
Correct |
2 ms |
1024 KB |
Output is correct |
4 |
Correct |
2 ms |
1024 KB |
Output is correct |
5 |
Correct |
2 ms |
1024 KB |
Output is correct |
6 |
Correct |
3 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
1024 KB |
Output is correct |
9 |
Correct |
7 ms |
1104 KB |
Output is correct |
10 |
Correct |
5 ms |
1100 KB |
Output is correct |
11 |
Correct |
3 ms |
1036 KB |
Output is correct |
12 |
Correct |
5 ms |
1036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
4 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
10 ms |
1156 KB |
Output is correct |
10 |
Correct |
5 ms |
1180 KB |
Output is correct |
11 |
Correct |
4 ms |
1200 KB |
Output is correct |
12 |
Correct |
3 ms |
1164 KB |
Output is correct |
13 |
Correct |
24 ms |
1184 KB |
Output is correct |
14 |
Correct |
2763 ms |
1456 KB |
Output is correct |
15 |
Correct |
20 ms |
1224 KB |
Output is correct |
16 |
Correct |
11 ms |
1228 KB |
Output is correct |
17 |
Correct |
2923 ms |
1276 KB |
Output is correct |
18 |
Correct |
13 ms |
1232 KB |
Output is correct |
19 |
Correct |
19 ms |
1224 KB |
Output is correct |
20 |
Correct |
2142 ms |
1316 KB |
Output is correct |
21 |
Correct |
21 ms |
1216 KB |
Output is correct |
22 |
Correct |
18 ms |
1248 KB |
Output is correct |
23 |
Correct |
178 ms |
1220 KB |
Output is correct |
24 |
Correct |
16 ms |
1220 KB |
Output is correct |
25 |
Correct |
7 ms |
1216 KB |
Output is correct |
26 |
Correct |
10 ms |
1212 KB |
Output is correct |
27 |
Correct |
11 ms |
1236 KB |
Output is correct |
28 |
Correct |
9 ms |
1184 KB |
Output is correct |
29 |
Correct |
8 ms |
1260 KB |
Output is correct |
30 |
Correct |
9 ms |
1168 KB |
Output is correct |
31 |
Correct |
1663 ms |
1320 KB |
Output is correct |
32 |
Correct |
125 ms |
1332 KB |
Output is correct |
33 |
Correct |
338 ms |
1304 KB |
Output is correct |
34 |
Correct |
217 ms |
1364 KB |
Output is correct |
35 |
Correct |
977 ms |
1308 KB |
Output is correct |
36 |
Correct |
1424 ms |
1332 KB |
Output is correct |
37 |
Execution timed out |
3076 ms |
1348 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
207 ms |
45088 KB |
Output is correct |
6 |
Correct |
189 ms |
45088 KB |
Output is correct |
7 |
Correct |
196 ms |
45264 KB |
Output is correct |
8 |
Correct |
202 ms |
45124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
896 KB |
Output is correct |
2 |
Correct |
3 ms |
876 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
3 ms |
912 KB |
Output is correct |
5 |
Correct |
218 ms |
54864 KB |
Output is correct |
6 |
Correct |
288 ms |
57628 KB |
Output is correct |
7 |
Correct |
223 ms |
56088 KB |
Output is correct |
8 |
Correct |
356 ms |
57704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
2 ms |
1024 KB |
Output is correct |
3 |
Correct |
2 ms |
1024 KB |
Output is correct |
4 |
Correct |
2 ms |
1024 KB |
Output is correct |
5 |
Correct |
2 ms |
1024 KB |
Output is correct |
6 |
Correct |
3 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
1024 KB |
Output is correct |
9 |
Correct |
7 ms |
1104 KB |
Output is correct |
10 |
Correct |
5 ms |
1100 KB |
Output is correct |
11 |
Correct |
3 ms |
1036 KB |
Output is correct |
12 |
Correct |
5 ms |
1036 KB |
Output is correct |
13 |
Correct |
200 ms |
67752 KB |
Output is correct |
14 |
Correct |
236 ms |
67700 KB |
Output is correct |
15 |
Correct |
207 ms |
67356 KB |
Output is correct |
16 |
Correct |
217 ms |
68636 KB |
Output is correct |
17 |
Correct |
216 ms |
67992 KB |
Output is correct |
18 |
Correct |
240 ms |
69148 KB |
Output is correct |
19 |
Correct |
245 ms |
66076 KB |
Output is correct |
20 |
Correct |
325 ms |
69388 KB |
Output is correct |
21 |
Correct |
1236 ms |
70172 KB |
Output is correct |
22 |
Correct |
759 ms |
70296 KB |
Output is correct |
23 |
Correct |
530 ms |
70172 KB |
Output is correct |
24 |
Correct |
674 ms |
70176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
4 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
10 ms |
1156 KB |
Output is correct |
10 |
Correct |
5 ms |
1180 KB |
Output is correct |
11 |
Correct |
4 ms |
1200 KB |
Output is correct |
12 |
Correct |
3 ms |
1164 KB |
Output is correct |
13 |
Correct |
24 ms |
1184 KB |
Output is correct |
14 |
Correct |
2763 ms |
1456 KB |
Output is correct |
15 |
Correct |
20 ms |
1224 KB |
Output is correct |
16 |
Correct |
11 ms |
1228 KB |
Output is correct |
17 |
Correct |
2923 ms |
1276 KB |
Output is correct |
18 |
Correct |
13 ms |
1232 KB |
Output is correct |
19 |
Correct |
19 ms |
1224 KB |
Output is correct |
20 |
Correct |
2142 ms |
1316 KB |
Output is correct |
21 |
Correct |
21 ms |
1216 KB |
Output is correct |
22 |
Correct |
18 ms |
1248 KB |
Output is correct |
23 |
Correct |
178 ms |
1220 KB |
Output is correct |
24 |
Correct |
16 ms |
1220 KB |
Output is correct |
25 |
Correct |
7 ms |
1216 KB |
Output is correct |
26 |
Correct |
10 ms |
1212 KB |
Output is correct |
27 |
Correct |
11 ms |
1236 KB |
Output is correct |
28 |
Correct |
9 ms |
1184 KB |
Output is correct |
29 |
Correct |
8 ms |
1260 KB |
Output is correct |
30 |
Correct |
9 ms |
1168 KB |
Output is correct |
31 |
Correct |
1663 ms |
1320 KB |
Output is correct |
32 |
Correct |
125 ms |
1332 KB |
Output is correct |
33 |
Correct |
338 ms |
1304 KB |
Output is correct |
34 |
Correct |
217 ms |
1364 KB |
Output is correct |
35 |
Correct |
977 ms |
1308 KB |
Output is correct |
36 |
Correct |
1424 ms |
1332 KB |
Output is correct |
37 |
Execution timed out |
3076 ms |
1348 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |