답안 #883145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883145 2023-12-04T16:02:58 Z abcvuitunggio 함박 스테이크 (JOI20_hamburg) C++17
100 / 100
471 ms 20084 KB
#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, int dir){
    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]});
    }
}
int f(int mask, int pos, int pos2=-INF){
    int res=(type[mask].empty()?INF:type[mask][0].second);
    if (!type[6].empty()){
        int tmp=upper_bound(type[6].begin(),type[6].end(),make_pair(pos2,INF))-type[6].begin();
        if (tmp<type[6].size())
            res=min(res,type[6][tmp].second);
    }
    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);
        }
        if (mask==2){
            int tmp=upper_bound(type[3].begin(),type[3].end(),make_pair(pos,INF))-type[3].begin();
            if (tmp<type[3].size())
                res=min(res,type[3][tmp].second);
        }
    }
    return res;
}
pair <int, int> calc(int x, int y){
    int l=0,r=INF;
    if (!type[12].empty()){
        int tmp=upper_bound(type[12].begin(),type[12].end(),make_pair(x,INF))-type[12].begin();
        if (tmp<type[12].size())
            r=type[12][tmp].second;
    }
    if (!type[10].empty()){
        int tmp=upper_bound(type[10].begin(),type[10].end(),make_pair(y,INF))-type[10].begin();
        if (tmp<type[10].size())
            l=type[10][tmp].second;
    }
    return {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,1,0);
    strain(2,0,2,1,0);
    strain(4,0,2,1,0);
    strain(8,1,3,1,0);
    strain(3,1,2,1,0);
    strain(5,3,2,-1,1);
    strain(10,0,1,-1,0);
    strain(12,0,3,1,0);
    strain(9,1,3,1,0);
    strain(6,0,2,1,0);
    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 'int f(int, int, int)':
hamburg.cpp:56:16: 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[6].size())
      |             ~~~^~~~~~~~~~~~~~~
hamburg.cpp:67: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]
   67 |             if (tmp<type[3].size())
      |                 ~~~^~~~~~~~~~~~~~~
hamburg.cpp: In function 'std::pair<int, int> calc(int, int)':
hamburg.cpp:77:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         if (tmp<type[12].size())
      |             ~~~^~~~~~~~~~~~~~~~
hamburg.cpp:82:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         if (tmp<type[10].size())
      |             ~~~^~~~~~~~~~~~~~~~
hamburg.cpp: In function 'void check(int, int)':
hamburg.cpp:98: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]
   98 |             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 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2516 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2532 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2532 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 2392 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 3 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 3 ms 2396 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 3 ms 2904 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 3 ms 2648 KB Output is correct
24 Correct 3 ms 2648 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 3 ms 2648 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2648 KB Output is correct
30 Correct 3 ms 2652 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 3 ms 2652 KB Output is correct
34 Correct 3 ms 2652 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 3 ms 2652 KB Output is correct
37 Correct 4 ms 2652 KB Output is correct
38 Correct 4 ms 2652 KB Output is correct
39 Correct 3 ms 2608 KB Output is correct
40 Correct 3 ms 2652 KB Output is correct
41 Correct 3 ms 2652 KB Output is correct
42 Correct 4 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 2600 KB Output is correct
46 Correct 4 ms 2904 KB Output is correct
47 Correct 3 ms 2652 KB Output is correct
48 Correct 4 ms 2652 KB Output is correct
49 Correct 4 ms 2652 KB Output is correct
50 Correct 3 ms 2652 KB Output is correct
51 Correct 4 ms 2652 KB Output is correct
52 Correct 3 ms 2652 KB Output is correct
53 Correct 3 ms 2648 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 2652 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 2516 KB Output is correct
5 Correct 62 ms 5728 KB Output is correct
6 Correct 61 ms 5732 KB Output is correct
7 Correct 62 ms 5800 KB Output is correct
8 Correct 74 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2544 KB Output is correct
5 Correct 64 ms 6372 KB Output is correct
6 Correct 64 ms 6516 KB Output is correct
7 Correct 96 ms 6352 KB Output is correct
8 Correct 84 ms 8328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2516 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2532 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 65 ms 6648 KB Output is correct
14 Correct 67 ms 6540 KB Output is correct
15 Correct 68 ms 6196 KB Output is correct
16 Correct 71 ms 6340 KB Output is correct
17 Correct 67 ms 7172 KB Output is correct
18 Correct 80 ms 6228 KB Output is correct
19 Correct 72 ms 7096 KB Output is correct
20 Correct 75 ms 7936 KB Output is correct
21 Correct 145 ms 10588 KB Output is correct
22 Correct 92 ms 8536 KB Output is correct
23 Correct 85 ms 9404 KB Output is correct
24 Correct 93 ms 10176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2532 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 2392 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 3 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 3 ms 2396 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 3 ms 2904 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 3 ms 2648 KB Output is correct
24 Correct 3 ms 2648 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 3 ms 2648 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2648 KB Output is correct
30 Correct 3 ms 2652 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 3 ms 2652 KB Output is correct
34 Correct 3 ms 2652 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 3 ms 2652 KB Output is correct
37 Correct 4 ms 2652 KB Output is correct
38 Correct 4 ms 2652 KB Output is correct
39 Correct 3 ms 2608 KB Output is correct
40 Correct 3 ms 2652 KB Output is correct
41 Correct 3 ms 2652 KB Output is correct
42 Correct 4 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 2600 KB Output is correct
46 Correct 4 ms 2904 KB Output is correct
47 Correct 3 ms 2652 KB Output is correct
48 Correct 4 ms 2652 KB Output is correct
49 Correct 4 ms 2652 KB Output is correct
50 Correct 3 ms 2652 KB Output is correct
51 Correct 4 ms 2652 KB Output is correct
52 Correct 3 ms 2652 KB Output is correct
53 Correct 3 ms 2648 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 2652 KB Output is correct
59 Correct 82 ms 15220 KB Output is correct
60 Correct 70 ms 14880 KB Output is correct
61 Correct 70 ms 14968 KB Output is correct
62 Correct 82 ms 14584 KB Output is correct
63 Correct 68 ms 14920 KB Output is correct
64 Correct 78 ms 14212 KB Output is correct
65 Correct 87 ms 14896 KB Output is correct
66 Correct 71 ms 14996 KB Output is correct
67 Correct 133 ms 17976 KB Output is correct
68 Correct 98 ms 16748 KB Output is correct
69 Correct 80 ms 15776 KB Output is correct
70 Correct 84 ms 17240 KB Output is correct
71 Correct 385 ms 19760 KB Output is correct
72 Correct 384 ms 19652 KB Output is correct
73 Correct 304 ms 19656 KB Output is correct
74 Correct 258 ms 19848 KB Output is correct
75 Correct 236 ms 19316 KB Output is correct
76 Correct 206 ms 19648 KB Output is correct
77 Correct 248 ms 19824 KB Output is correct
78 Correct 436 ms 19792 KB Output is correct
79 Correct 286 ms 19872 KB Output is correct
80 Correct 224 ms 19492 KB Output is correct
81 Correct 376 ms 19620 KB Output is correct
82 Correct 210 ms 19304 KB Output is correct
83 Correct 147 ms 19140 KB Output is correct
84 Correct 123 ms 17292 KB Output is correct
85 Correct 213 ms 19760 KB Output is correct
86 Correct 150 ms 18164 KB Output is correct
87 Correct 193 ms 19640 KB Output is correct
88 Correct 199 ms 19444 KB Output is correct
89 Correct 276 ms 19376 KB Output is correct
90 Correct 411 ms 19948 KB Output is correct
91 Correct 278 ms 19740 KB Output is correct
92 Correct 414 ms 20072 KB Output is correct
93 Correct 338 ms 19736 KB Output is correct
94 Correct 429 ms 19708 KB Output is correct
95 Correct 371 ms 19840 KB Output is correct
96 Correct 299 ms 19776 KB Output is correct
97 Correct 354 ms 20016 KB Output is correct
98 Correct 336 ms 19420 KB Output is correct
99 Correct 262 ms 19840 KB Output is correct
100 Correct 416 ms 19880 KB Output is correct
101 Correct 385 ms 19848 KB Output is correct
102 Correct 232 ms 17368 KB Output is correct
103 Correct 471 ms 19868 KB Output is correct
104 Correct 251 ms 18416 KB Output is correct
105 Correct 438 ms 20084 KB Output is correct
106 Correct 386 ms 19592 KB Output is correct
107 Correct 321 ms 19840 KB Output is correct
108 Correct 436 ms 20080 KB Output is correct
109 Correct 403 ms 19656 KB Output is correct
110 Correct 368 ms 19796 KB Output is correct
111 Correct 382 ms 20004 KB Output is correct
112 Correct 414 ms 19936 KB Output is correct
113 Correct 224 ms 16972 KB Output is correct
114 Correct 226 ms 16868 KB Output is correct
115 Correct 224 ms 16972 KB Output is correct
116 Correct 221 ms 16908 KB Output is correct
117 Correct 323 ms 19896 KB Output is correct
118 Correct 317 ms 19980 KB Output is correct
119 Correct 302 ms 19972 KB Output is correct
120 Correct 316 ms 20028 KB Output is correct
121 Correct 312 ms 19944 KB Output is correct
122 Correct 302 ms 20000 KB Output is correct
123 Correct 297 ms 19980 KB Output is correct
124 Correct 308 ms 20036 KB Output is correct
125 Correct 298 ms 19920 KB Output is correct
126 Correct 302 ms 20064 KB Output is correct