QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#145407#3553. Hamburg SteakZhou_JK0 10ms59220kbC++238.0kb2023-08-22 11:32:452023-08-22 11:32:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-22 11:32:46]
  • 评测
  • 测评结果:0
  • 用时:10ms
  • 内存:59220kb
  • [2023-08-22 11:32:45]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cassert>
#include<set>
#include<stack>
#include<tuple>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
const int N=200005;
const int INF=1000000000;
int n,k;
int l[N],d[N],r[N],u[N];
bool vis[N];
pair<int,int>p[5];
void dfs(int step)
{
    if(step>k)
    {
        for(int i=1;i<=n;i++)
            if(!vis[i]) return;
        for(int i=1;i<=k;i++)
            printf("%d %d\n",p[i].first,p[i].second);
        exit(0);
    }
    int maxl=1,minr=INF,maxd=1,minu=INF;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            maxl=max(maxl,l[i]);
            minr=min(minr,r[i]);
            maxd=max(maxd,d[i]);
            minu=min(minu,u[i]);
        }
    vector<int>pos;
    int x,y;
    x=maxl,y=maxd;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            if(l[i]<=x&&x<=r[i]&&d[i]<=y&&y<=u[i]) pos.emplace_back(i),vis[i]=true;
        }
    p[step]={x,y};
    dfs(step+1);
    for(int i:pos)
        vis[i]=false;
    pos.clear();
    x=maxl,y=minu;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            if(l[i]<=x&&x<=r[i]&&d[i]<=y&&y<=u[i]) pos.emplace_back(i),vis[i]=true;
        }
    p[step]={x,y};
    dfs(step+1);
    for(int i:pos)
        vis[i]=false;
    pos.clear();
    x=minr,y=maxd;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            if(l[i]<=x&&x<=r[i]&&d[i]<=y&&y<=u[i]) pos.emplace_back(i),vis[i]=true;
        }
    p[step]={x,y};
    dfs(step+1);
    for(int i:pos)
        vis[i]=false;
    pos.clear();
    x=minr,y=minu;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            if(l[i]<=x&&x<=r[i]&&d[i]<=y&&y<=u[i]) pos.emplace_back(i),vis[i]=true;
        }
    p[step]={x,y};
    dfs(step+1);
    for(int i:pos)
        vis[i]=false;
    return;
}
int c[N];
int id[N][2],cnt;
int pos[N][2];
vector<tuple<int,int,int,int>>L,R,D,U;
vector<int>G[N*10];
int dfn[N*10],low[N*10],Index;
int bel[N*10],tot;
void tarjan(int u)
{
    static bool vis[N*10];
    static stack<int>s;
    dfn[u]=low[u]=++Index;
    s.emplace(u);
    vis[u]=true;
    for(int v:G[u])
        if(!dfn[v])
        {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(vis[v]) low[u]=min(low[u],dfn[v]);
    if(dfn[u]==low[u])
    {
        tot++;
        while(s.top()!=u)
        {
            bel[s.top()]=tot;
            vis[s.top()]=false;
            s.pop();
        }
        bel[u]=tot;
        vis[u]=false;
        s.pop();
    }
    return;
}
int val[N];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d%d",&l[i],&d[i],&r[i],&u[i]);
    dfs(1);
    if(k==4)
    {
        int maxl=*max_element(l+1,l+n+1),minr=*min_element(r+1,r+n+1),maxd=*max_element(d+1,d+n+1),minu=*min_element(u+1,u+n+1);
        assert(minr<=maxl&&minu<=maxd);
        for(int i=1;i<=n;i++)
        {
            if(l[i]<=minr&&minr<=r[i]) c[i]++;
            if(l[i]<=maxl&&maxl<=r[i]) c[i]++;
            if(d[i]<=minu&&minu<=u[i]) c[i]++;
            if(d[i]<=maxd&&maxd<=u[i]) c[i]++;
            if(c[i]>=3) continue;
            assert(c[i]>0);
            id[i][0]=++cnt,id[i][1]=++cnt;
            if(c[i]==1)
            {
                G[id[i][1]].emplace_back(id[i][0]);
                if(l[i]<=minr&&minr<=r[i]) L.emplace_back(d[i],u[i],id[i][0],id[i][1]),pos[i][0]=1;
                else if(l[i]<=maxl&&maxl<=r[i]) R.emplace_back(d[i],u[i],id[i][0],id[i][1]),pos[i][0]=2;
                else if(d[i]<=minu&&minu<=u[i]) D.emplace_back(l[i],r[i],id[i][0],id[i][1]),pos[i][0]=3;
                else if(d[i]<=maxd&&maxd<=u[i]) U.emplace_back(l[i],r[i],id[i][0],id[i][1]),pos[i][0]=4;
                else assert(false);
            }
            if(c[i]==2)
            {
                for(int j=1;j<=4;j++)
                    for(int k=j+1;k<=4;k++)
                    {
                        bool fj=false;
                        if(j==1) fj=l[i]<=minr&&minr<=r[i];
                        else if(j==2) fj=l[i]<=maxl&&maxl<=r[i];
                        else if(j==3) fj=d[i]<=minu&&minu<=u[i];
                        else if(j==4) fj=d[i]<=maxd&&maxd<=u[i];
                        bool fk=false;
                        if(k==1) fk=l[i]<=minr&&minr<=r[i];
                        else if(k==2) fk=l[i]<=maxl&&maxl<=r[i];
                        else if(k==3) fk=d[i]<=minu&&minu<=u[i];
                        else if(k==4) fk=d[i]<=maxd&&maxd<=u[i];
                        if(fj&&fk)
                        {
                            if(j==1) L.emplace_back(d[i],u[i],id[i][0],id[i][1]),pos[i][0]=1;
                            else if(j==2) R.emplace_back(d[i],u[i],id[i][0],id[i][1]),pos[i][0]=2;
                            else if(j==3) D.emplace_back(l[i],r[i],id[i][0],id[i][1]),pos[i][0]=3;
                            else if(j==4) U.emplace_back(l[i],r[i],id[i][0],id[i][1]),pos[i][0]=4;
                            else assert(false);
                            if(k==1) L.emplace_back(d[i],u[i],id[i][1],id[i][0]),pos[i][1]=1;
                            else if(k==2) R.emplace_back(d[i],u[i],id[i][1],id[i][0]),pos[i][1]=2;
                            else if(k==3) D.emplace_back(l[i],r[i],id[i][1],id[i][0]),pos[i][1]=3;
                            else if(k==4) U.emplace_back(l[i],r[i],id[i][1],id[i][0]),pos[i][1]=4;
                            else assert(false);
                        }
                    }
            }
        }
        for(auto a:{L,R,D,U})
        {
            vector<int>to(a.size()),from(a.size());
            for(int i=0;i<(int)a.size();i++)
                to[i]=++cnt,from[i]=++cnt;
            sort(a.begin(),a.end(),[=](const tuple<int,int,int,int> &x,const tuple<int,int,int,int> &y){return get<1>(x)<get<1>(y);});
            for(int i=0;i<(int)a.size();i++)
            {
                G[to[i]].emplace_back(get<3>(a[i]));
                G[get<2>(a[i])].emplace_back(from[i]);
                if(i>0)
                {
                    G[to[i]].emplace_back(to[i-1]);
                    G[from[i-1]].emplace_back(from[i]);
                }
            }
            vector<int>posr(a.size());
            for(int i=0;i<(int)posr.size();i++)
                posr[i]=get<1>(a[i]);
            for(int i=0;i<(int)a.size();i++)
            {
                auto [li,ri,i1,i0]=a[i];
                if(i>0)
                {
                    int j=lower_bound(posr.begin(),posr.begin()+i,li)-posr.begin()-1;
                    if(j>=0)
                    {
                        G[i1].emplace_back(to[j]);
                        G[from[j]].emplace_back(i0);
                    }
                }
            }
        }
        for(int i=1;i<=cnt;i++)
            if(!dfn[i]) tarjan(i);
        for(int i=1;i<=n;i++)
            if(c[i]==1||c[i]==2) assert(bel[id[i][0]]!=bel[id[i][1]]);
        for(int i=1;i<=n;i++)
            if(c[i]==1||c[i]==2) val[i]=bel[id[i][1]]<bel[id[i][0]];
        int ld=1,lu=INF,rd=1,ru=INF;
        int dl=1,dr=INF,ul=1,ur=INF;
        for(int i=1;i<=n;i++)
            if(c[i]==1)
            {
                if(pos[i][0]==1) ld=max(ld,d[i]),lu=min(lu,u[i]);
                else if(pos[i][0]==2) rd=max(rd,d[i]),ru=min(ru,u[i]);
                else if(pos[i][0]==3) dl=max(dl,l[i]),dr=min(dr,r[i]);
                else if(pos[i][0]==4) ul=max(ul,l[i]),ur=min(ur,r[i]);
            }
            else if(c[i]==2)
            {
                if(pos[i][val[i]]==1) ld=max(ld,d[i]),lu=min(lu,u[i]);
                else if(pos[i][val[i]]==2) rd=max(rd,d[i]),ru=min(ru,u[i]);
                else if(pos[i][val[i]]==3) dl=max(dl,l[i]),dr=min(dr,r[i]);
                else if(pos[i][val[i]]==4) ul=max(ul,l[i]),ur=min(ur,r[i]);
            }
        assert(ld<=lu&&rd<=ru&&dl<=dr&&ul<=ur);
        printf("%d %d\n",minr,ld);
        printf("%d %d\n",maxl,rd);
        printf("%d %d\n",dl,minu);
        printf("%d %d",ul,maxd);
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 57088kb

input:

1936 1
275634612 269663887 525116613 936487725
97408668 7442476 814869170 687312206
436819238 107950642 958111100 591552952
7518596 205530980 782566587 854412425
496572510 309198877 998274921 764947740
205948014 311140816 696959672 600779117
332275583 5172242 984611829 780400859
404519140 226954535 ...

output:

500095467 495713566

result:

wrong answer 1st lines differ - expected: '500995935 495734996', found: '500095467 495713566'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 10ms
memory: 59220kb

input:

1928 2
257715250 61165602 852430884 888048968
291121137 322570367 570606015 908598504
418176729 319924920 611676731 632485660
33180758 215166338 468783003 795212414
441068331 188624227 750676748 613482091
344172819 322492096 940801573 568738370
246507550 338324125 785514636 678843646
100885653 12352...

output:

553348827 550579979
376616176 496147660

result:

wrong answer 1st lines differ - expected: '554391350 553379929', found: '553348827 550579979'

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 4ms
memory: 57100kb

input:

1980 3
580358104 434053443 986861108 684634218
125969708 5379869 593299091 644204766
366688051 54873592 662708561 602035535
211630750 166795940 981075947 676159693
524950613 414516203 951984898 573261034
10925143 210994662 543601795 609644115
82102881 63393894 401995062 922075556
245641393 276511435...

output:

816253792 497455773
437786479 497455773
274745882 496362979

result:

wrong answer 1st lines differ - expected: '275428833 497556652', found: '816253792 497455773'

Subtask #4:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 7ms
memory: 57088kb

input:

1989 4
20688201 462820019 870557654 779905491
299122723 258293216 630017062 521792413
430322558 33567880 691187720 757852374
104994597 262388698 979697437 904439328
237383344 375297588 673858769 638443621
715773360 364818076 896724313 888051478
235043050 422124296 833892854 936850257
434942952 25412...

output:

740481982 495357540
476653932 494820027
417434611 494344760
293219812 487377130

result:

wrong answer 1st lines differ - expected: '302970929 495470567', found: '740481982 495357540'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%