Submission #1038931

# Submission time Handle Problem Language Result Execution time Memory
1038931 2024-07-30T09:33:08 Z hotboy2703 Hamburg Steak (JOI20_hamburg) C++17
100 / 100
1721 ms 320092 KB
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll INF = 1e18;
const ll MAXN = 2e5+100;
struct rec{
    ll l,r,d,u;
    rec(ll l1= 0,ll r1 = 0,ll d1 = 0,ll u1 = 0):l(l1),r(r1),d(d1),u(u1){}
};
namespace SCC{

    bool res[MAXN*12];
    vector <ll> g1[MAXN*12];
    vector <ll> g2[MAXN*12];
    bool in[MAXN*12];
    ll val[MAXN*12];
    ll n;
    void add(ll x,ll y){
        n = max({n,x|1,y|1});
        g1[x].push_back(y);    
        g2[y].push_back(x);
    }
    void dfs(ll u,vector <ll> g[],vector <ll> &comp){
        in[u] = 1;
        for (auto v:g[u]){
            if (!in[v])dfs(v,g,comp);
        }
        comp.push_back(u);
    }
    void solve(){
        vector <ll> order;
        for (ll i = 0;i <= n;i ++){
            if (!in[i]){
                dfs(i,g1,order);
            }
        }
        memset(in,0,sizeof in);
        reverse(order.begin(),order.end());
        ll cur = 0;
        for (auto x:order){
            if (!in[x]){
                vector <ll> comp;
                dfs(x,g2,comp);
                for (auto y:comp)val[y] = cur;
                cur++;
            }
        }
        for (ll i = 0;i <= n;i ++){
            res[i] = (val[i] > val[i^1]);
        }
    }
}
vector <rec> A;
ll n,k;
ll PTR;
struct line{
    ll l,r,id;
};
vector <line> b[4];
void solve(){
    ll L=0,R=INF,D=0,U=INF;
    for (auto x:A){
        L = max(x.l,L);
        R = min(x.r,R);
        D = max(x.d,D);
        U = min(x.u,U);
    }
    // U < D,R < L
    A.push_back({L,L,U+1,D-1});
    A.push_back({R,R,U+1,D-1});
    A.push_back({R+1,L-1,D,D});
    A.push_back({R+1,L-1,U,U});
    for (auto [l,r,d,u]:A){
        vector <pair <ll,pll> > all;
        if (l <= L && L <= r)all.push_back(MP(0,MP(d,u)));
        if (l <= R && R <= r)all.push_back(MP(1,MP(d,u)));
        if (d <= D && D <= u)all.push_back(MP(2,MP(l,r)));
        if (d <= U && U <= u)all.push_back(MP(3,MP(l,r)));
        if (sz(all) >= 3)continue;
        for (auto x:all){
            b[x.fi].push_back({x.se.fi,x.se.se,PTR++});
        }
        if (sz(all) == 2){
            ll u = PTR-2,v = PTR-1;
            SCC::add(u<<1|1,v<<1);
            SCC::add(v<<1|1,u<<1);
        }
        if (sz(all) == 1){
            ll u = PTR-1;
            SCC::add(u<<1|1,u<<1);
        }
    }
    for (ll i = 0;i < 4;i ++){
        sort(b[i].begin(),b[i].end(),[](line x,line y){return x.r < y.r;});
        vector <ll> ban(sz(b[i]));
        for (ll j = 0;j < sz(b[i]);j ++){
            ban[j] = PTR++;
            SCC::add(ban[j]<<1,b[i][j].id<<1|1);
            if (j)SCC::add(ban[j]<<1,ban[j-1]<<1);
            auto tmp = lower_bound(b[i].begin(),b[i].end(),b[i][j].l,[](line x,ll y){return x.r < y;}) - b[i].begin()-1;;
            if (tmp>=0)SCC::add(b[i][j].id<<1,ban[tmp]<<1);
        }
        sort(b[i].begin(),b[i].end(),[](line x,line y){return x.l > y.l;});
        for (ll j = 0;j < sz(b[i]);j ++){
            ban[j] = PTR++;
            SCC::add(ban[j]<<1,b[i][j].id<<1|1);
            if (j)SCC::add(ban[j]<<1,ban[j-1]<<1);
            auto tmp = lower_bound(b[i].begin(),b[i].end(),b[i][j].r,[](line x,ll y){return x.l > y;}) - b[i].begin()-1;;
            if (tmp>=0)SCC::add(b[i][j].id<<1,ban[tmp]<<1);
        }
    }
    SCC::solve();
    pll ans[4];
    for (ll i = 0;i < 4;i ++){
        ans[i].fi = 0,ans[i].se = INF;
        for (auto j:b[i]){
            if (SCC::res[j.id<<1]){
                ans[i].fi = max(ans[i].fi,j.l);
                ans[i].se = min(ans[i].se,j.r);
            }
        }
    }
    cout<<L<<' '<<ans[0].fi<<'\n';
    cout<<R<<' '<<ans[1].fi<<'\n';
    cout<<ans[2].fi<<' '<<D<<'\n';
    cout<<ans[3].fi<<' '<<U<<'\n';
}
vector <pll> ans;
bool done = 0;
vector <rec> del(vector <rec> a,pll y){
    vector <rec> res;
    for (auto x:a){
        if (x.l <= y.fi && x.r >= y.fi &&
            x.d <= y.se && x.u >= y.se){}
        else res.emplace_back(x);
    }
    return res;
}
void brute(vector <rec> cur,vector <pll> c){
    if (done)return;
    // for (auto x:cur)cout<<x.l<<' '<<x.r<<' '<<x.d<<' '<<x.u<<' ';
    // cout<<sz(c)<<'\n';
    if (sz(c)==k||cur.empty()){
        while (sz(c) < k){c.push_back(MP(0,0));}
        if (cur.empty()){
            for (ll i = 0;i < k;i ++)cout<<c[i].fi<<' '<<c[i].se<<'\n';
            done = 1;
        }
        return;
    }
    ll L=0,R=INF,D=0,U=INF;
    for (auto x:cur){
        L = max(x.l,L);
        R = min(x.r,R);
        D = max(x.d,D);
        U = min(x.u,U);
    }
    {
        auto tmp = MP(L,D);
        c.push_back(tmp);
        brute(del(cur,tmp),c);
        c.pop_back();
    }
    {
        auto tmp = MP(L,U);
        c.push_back(tmp);
        brute(del(cur,tmp),c);
        c.pop_back();
    }
    {
        auto tmp = MP(R,D);
        c.push_back(tmp);
        brute(del(cur,tmp),c);
        c.pop_back();
    }
    {
        auto tmp = MP(R,U);
        c.push_back(tmp);
        brute(del(cur,tmp),c);
        c.pop_back();
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>k;
    A.resize(n);
    for (auto &x:A)cin>>x.l>>x.d>>x.r>>x.u;
    brute(A,ans);
    if (done)return 0;
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 43 ms 113180 KB Output is correct
2 Correct 42 ms 113232 KB Output is correct
3 Correct 42 ms 113212 KB Output is correct
4 Correct 44 ms 113336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 113236 KB Output is correct
2 Correct 41 ms 113488 KB Output is correct
3 Correct 42 ms 113488 KB Output is correct
4 Correct 43 ms 113568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 113488 KB Output is correct
2 Correct 42 ms 113496 KB Output is correct
3 Correct 43 ms 113500 KB Output is correct
4 Correct 42 ms 113500 KB Output is correct
5 Correct 42 ms 113500 KB Output is correct
6 Correct 41 ms 113488 KB Output is correct
7 Correct 42 ms 113508 KB Output is correct
8 Correct 45 ms 113696 KB Output is correct
9 Correct 42 ms 113492 KB Output is correct
10 Correct 43 ms 113752 KB Output is correct
11 Correct 44 ms 113500 KB Output is correct
12 Correct 44 ms 113488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 113500 KB Output is correct
2 Correct 42 ms 113236 KB Output is correct
3 Correct 42 ms 113460 KB Output is correct
4 Correct 43 ms 113516 KB Output is correct
5 Correct 42 ms 113492 KB Output is correct
6 Correct 41 ms 113492 KB Output is correct
7 Correct 45 ms 113488 KB Output is correct
8 Correct 43 ms 113880 KB Output is correct
9 Correct 41 ms 113488 KB Output is correct
10 Correct 42 ms 113744 KB Output is correct
11 Correct 45 ms 113864 KB Output is correct
12 Correct 41 ms 113492 KB Output is correct
13 Correct 42 ms 113452 KB Output is correct
14 Correct 46 ms 116404 KB Output is correct
15 Correct 42 ms 113568 KB Output is correct
16 Correct 45 ms 113488 KB Output is correct
17 Correct 50 ms 116716 KB Output is correct
18 Correct 43 ms 113716 KB Output is correct
19 Correct 43 ms 113744 KB Output is correct
20 Correct 50 ms 116736 KB Output is correct
21 Correct 42 ms 113492 KB Output is correct
22 Correct 44 ms 113888 KB Output is correct
23 Correct 51 ms 116900 KB Output is correct
24 Correct 48 ms 113904 KB Output is correct
25 Correct 42 ms 113880 KB Output is correct
26 Correct 45 ms 113936 KB Output is correct
27 Correct 45 ms 113832 KB Output is correct
28 Correct 43 ms 113800 KB Output is correct
29 Correct 44 ms 113824 KB Output is correct
30 Correct 44 ms 113880 KB Output is correct
31 Correct 48 ms 116488 KB Output is correct
32 Correct 48 ms 116344 KB Output is correct
33 Correct 47 ms 116360 KB Output is correct
34 Correct 46 ms 116460 KB Output is correct
35 Correct 55 ms 116924 KB Output is correct
36 Correct 46 ms 116420 KB Output is correct
37 Correct 56 ms 116876 KB Output is correct
38 Correct 55 ms 116968 KB Output is correct
39 Correct 49 ms 116724 KB Output is correct
40 Correct 48 ms 116580 KB Output is correct
41 Correct 48 ms 116608 KB Output is correct
42 Correct 51 ms 116836 KB Output is correct
43 Correct 49 ms 116812 KB Output is correct
44 Correct 48 ms 116964 KB Output is correct
45 Correct 42 ms 113916 KB Output is correct
46 Correct 51 ms 116856 KB Output is correct
47 Correct 72 ms 116768 KB Output is correct
48 Correct 54 ms 116964 KB Output is correct
49 Correct 47 ms 116812 KB Output is correct
50 Correct 47 ms 116636 KB Output is correct
51 Correct 53 ms 116876 KB Output is correct
52 Correct 52 ms 116400 KB Output is correct
53 Correct 54 ms 116632 KB Output is correct
54 Correct 61 ms 116956 KB Output is correct
55 Correct 52 ms 116564 KB Output is correct
56 Correct 50 ms 116672 KB Output is correct
57 Correct 52 ms 116608 KB Output is correct
58 Correct 53 ms 116708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 113180 KB Output is correct
2 Correct 42 ms 113232 KB Output is correct
3 Correct 42 ms 113212 KB Output is correct
4 Correct 44 ms 113336 KB Output is correct
5 Correct 103 ms 132000 KB Output is correct
6 Correct 108 ms 131924 KB Output is correct
7 Correct 105 ms 131924 KB Output is correct
8 Correct 98 ms 132016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 113236 KB Output is correct
2 Correct 41 ms 113488 KB Output is correct
3 Correct 42 ms 113488 KB Output is correct
4 Correct 43 ms 113568 KB Output is correct
5 Correct 129 ms 145140 KB Output is correct
6 Correct 120 ms 145088 KB Output is correct
7 Correct 119 ms 139252 KB Output is correct
8 Correct 122 ms 153536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 113488 KB Output is correct
2 Correct 42 ms 113496 KB Output is correct
3 Correct 43 ms 113500 KB Output is correct
4 Correct 42 ms 113500 KB Output is correct
5 Correct 42 ms 113500 KB Output is correct
6 Correct 41 ms 113488 KB Output is correct
7 Correct 42 ms 113508 KB Output is correct
8 Correct 45 ms 113696 KB Output is correct
9 Correct 42 ms 113492 KB Output is correct
10 Correct 43 ms 113752 KB Output is correct
11 Correct 44 ms 113500 KB Output is correct
12 Correct 44 ms 113488 KB Output is correct
13 Correct 120 ms 141884 KB Output is correct
14 Correct 126 ms 142492 KB Output is correct
15 Correct 122 ms 143304 KB Output is correct
16 Correct 102 ms 138132 KB Output is correct
17 Correct 116 ms 142588 KB Output is correct
18 Correct 102 ms 136532 KB Output is correct
19 Correct 119 ms 146092 KB Output is correct
20 Correct 233 ms 165568 KB Output is correct
21 Correct 127 ms 147124 KB Output is correct
22 Correct 157 ms 164616 KB Output is correct
23 Correct 177 ms 163908 KB Output is correct
24 Correct 165 ms 163364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 113500 KB Output is correct
2 Correct 42 ms 113236 KB Output is correct
3 Correct 42 ms 113460 KB Output is correct
4 Correct 43 ms 113516 KB Output is correct
5 Correct 42 ms 113492 KB Output is correct
6 Correct 41 ms 113492 KB Output is correct
7 Correct 45 ms 113488 KB Output is correct
8 Correct 43 ms 113880 KB Output is correct
9 Correct 41 ms 113488 KB Output is correct
10 Correct 42 ms 113744 KB Output is correct
11 Correct 45 ms 113864 KB Output is correct
12 Correct 41 ms 113492 KB Output is correct
13 Correct 42 ms 113452 KB Output is correct
14 Correct 46 ms 116404 KB Output is correct
15 Correct 42 ms 113568 KB Output is correct
16 Correct 45 ms 113488 KB Output is correct
17 Correct 50 ms 116716 KB Output is correct
18 Correct 43 ms 113716 KB Output is correct
19 Correct 43 ms 113744 KB Output is correct
20 Correct 50 ms 116736 KB Output is correct
21 Correct 42 ms 113492 KB Output is correct
22 Correct 44 ms 113888 KB Output is correct
23 Correct 51 ms 116900 KB Output is correct
24 Correct 48 ms 113904 KB Output is correct
25 Correct 42 ms 113880 KB Output is correct
26 Correct 45 ms 113936 KB Output is correct
27 Correct 45 ms 113832 KB Output is correct
28 Correct 43 ms 113800 KB Output is correct
29 Correct 44 ms 113824 KB Output is correct
30 Correct 44 ms 113880 KB Output is correct
31 Correct 48 ms 116488 KB Output is correct
32 Correct 48 ms 116344 KB Output is correct
33 Correct 47 ms 116360 KB Output is correct
34 Correct 46 ms 116460 KB Output is correct
35 Correct 55 ms 116924 KB Output is correct
36 Correct 46 ms 116420 KB Output is correct
37 Correct 56 ms 116876 KB Output is correct
38 Correct 55 ms 116968 KB Output is correct
39 Correct 49 ms 116724 KB Output is correct
40 Correct 48 ms 116580 KB Output is correct
41 Correct 48 ms 116608 KB Output is correct
42 Correct 51 ms 116836 KB Output is correct
43 Correct 49 ms 116812 KB Output is correct
44 Correct 48 ms 116964 KB Output is correct
45 Correct 42 ms 113916 KB Output is correct
46 Correct 51 ms 116856 KB Output is correct
47 Correct 72 ms 116768 KB Output is correct
48 Correct 54 ms 116964 KB Output is correct
49 Correct 47 ms 116812 KB Output is correct
50 Correct 47 ms 116636 KB Output is correct
51 Correct 53 ms 116876 KB Output is correct
52 Correct 52 ms 116400 KB Output is correct
53 Correct 54 ms 116632 KB Output is correct
54 Correct 61 ms 116956 KB Output is correct
55 Correct 52 ms 116564 KB Output is correct
56 Correct 50 ms 116672 KB Output is correct
57 Correct 52 ms 116608 KB Output is correct
58 Correct 53 ms 116708 KB Output is correct
59 Correct 132 ms 155724 KB Output is correct
60 Correct 127 ms 153732 KB Output is correct
61 Correct 123 ms 152304 KB Output is correct
62 Correct 130 ms 151484 KB Output is correct
63 Correct 129 ms 152208 KB Output is correct
64 Correct 125 ms 143372 KB Output is correct
65 Correct 137 ms 156420 KB Output is correct
66 Correct 456 ms 178996 KB Output is correct
67 Correct 193 ms 171036 KB Output is correct
68 Correct 624 ms 189448 KB Output is correct
69 Correct 797 ms 190480 KB Output is correct
70 Correct 546 ms 186032 KB Output is correct
71 Correct 141 ms 159924 KB Output is correct
72 Correct 1207 ms 265148 KB Output is correct
73 Correct 160 ms 165064 KB Output is correct
74 Correct 324 ms 189120 KB Output is correct
75 Correct 771 ms 204184 KB Output is correct
76 Correct 342 ms 185636 KB Output is correct
77 Correct 141 ms 159036 KB Output is correct
78 Correct 1605 ms 256940 KB Output is correct
79 Correct 153 ms 168148 KB Output is correct
80 Correct 248 ms 170180 KB Output is correct
81 Correct 1287 ms 258640 KB Output is correct
82 Correct 282 ms 183144 KB Output is correct
83 Correct 400 ms 179880 KB Output is correct
84 Correct 406 ms 186440 KB Output is correct
85 Correct 606 ms 190468 KB Output is correct
86 Correct 238 ms 169824 KB Output is correct
87 Correct 639 ms 191356 KB Output is correct
88 Correct 378 ms 190340 KB Output is correct
89 Correct 954 ms 237108 KB Output is correct
90 Correct 1409 ms 256660 KB Output is correct
91 Correct 894 ms 226284 KB Output is correct
92 Correct 1509 ms 281796 KB Output is correct
93 Correct 1228 ms 268504 KB Output is correct
94 Correct 1355 ms 250120 KB Output is correct
95 Correct 1377 ms 257272 KB Output is correct
96 Correct 1182 ms 265864 KB Output is correct
97 Correct 1275 ms 266280 KB Output is correct
98 Correct 1208 ms 249708 KB Output is correct
99 Correct 933 ms 240080 KB Output is correct
100 Correct 1484 ms 264328 KB Output is correct
101 Correct 1319 ms 265512 KB Output is correct
102 Correct 676 ms 192980 KB Output is correct
103 Correct 1721 ms 263048 KB Output is correct
104 Correct 866 ms 230712 KB Output is correct
105 Correct 1662 ms 275016 KB Output is correct
106 Correct 1466 ms 260040 KB Output is correct
107 Correct 1220 ms 255760 KB Output is correct
108 Correct 1555 ms 271436 KB Output is correct
109 Correct 1538 ms 265564 KB Output is correct
110 Correct 1413 ms 257800 KB Output is correct
111 Correct 1327 ms 249856 KB Output is correct
112 Correct 1581 ms 271848 KB Output is correct
113 Correct 760 ms 226488 KB Output is correct
114 Correct 733 ms 227896 KB Output is correct
115 Correct 746 ms 226984 KB Output is correct
116 Correct 768 ms 227128 KB Output is correct
117 Correct 1558 ms 320092 KB Output is correct
118 Correct 1598 ms 319276 KB Output is correct
119 Correct 1601 ms 318816 KB Output is correct
120 Correct 1609 ms 318648 KB Output is correct
121 Correct 1638 ms 319380 KB Output is correct
122 Correct 1550 ms 318852 KB Output is correct
123 Correct 1508 ms 319320 KB Output is correct
124 Correct 1581 ms 319568 KB Output is correct
125 Correct 1564 ms 319008 KB Output is correct
126 Correct 1582 ms 318804 KB Output is correct