QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#517006#9170. Cycle GameAfterlifeWA 1ms5668kbC++174.3kb2024-08-13 02:44:382024-08-13 02:44:38

Judging History

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

  • [2024-08-13 02:44:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5668kb
  • [2024-08-13 02:44:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=1e6+1e3+7;

int n,m,k,fa[N];

int c[N];

int s[N];

int find(int x)
{
    if(x==fa[x])
        return x;
    int f=find(fa[x]);
    s[x]=s[x]+s[fa[x]];
    fa[x]=f;
    return f;
}

int id(int x,int y)
{
    if(x<1||x>n||y<1||y>m)
        return -1;
    return (x-1)*m+y;
}

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int cals(int a,int b)
{
    int xa=(a-1)/m+1,ya=(a-1)%m+1;
    int xb=(b-1)/m+1,yb=(b-1)%m+1;
    return xa*yb-xb*ya;
}

namespace LCT {
    int c[N][2],fa[N];

    bool rev[N];

    int sz[N];

    int isroot(int x)
    {
        return c[fa[x]][0]!=x&&c[fa[x]][1]!=x;
    }

    int type(int x)
    {
        return c[fa[x]][1]==x;
    }

    void update(int x)
    {
        sz[x]=sz[c[x][0]]+sz[c[x][1]]+1;
    }

    void setrev(int x)
    {
        rev[x]^=1;
        swap(c[x][0],c[x][1]);
    }

    void pushdown(int x)
    {
        if(rev[x])
        {
            setrev(c[x][0]);
            setrev(c[x][1]);
            rev[x]=0;
        }
    }

    void rotate(int x)
    {
        int y=fa[x],d=type(x);
        fa[x]=fa[y];if(!isroot(y))c[fa[y]][type(y)]=x;
        fa[c[x][!d]]=y;c[y][d]=c[x][!d];
        c[x][!d]=y;
        fa[y]=x;
        update(y);
    }

    void splay(int x)
    {
        static stack<int> sta;
        sta.push(x);
        int t=x;
        while(!isroot(t))
            sta.push(t=fa[t]);
        while(!sta.empty())
            pushdown(sta.top()),sta.pop();
        for(int i=fa[x];!isroot(x);rotate(x),i=fa[x])
            if(!isroot(i))
                rotate(type(i)==type(x)?i:x);
        update(x);
    }

    void access(int x)
    {
        for(int t=0;x;t=x,x=fa[x])
        {
            splay(x);
            c[x][1]=t;
            update(x);
        }
    }

    void makeroot(int x)
    {
        access(x);
        splay(x);
        setrev(x);
    }

    void link(int x,int y)
    {
        makeroot(x);
        fa[x]=y;
    }

    int getroot(int x)
    {
        access(x);
        splay(x);
        while(c[x][0])
            x=c[x][0];
        splay(x);
        return x;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    // int a,b;
    // cin>>a;
    // // (2*INT_MAX-(INT_MAX-1)*3+INT_MAX)
    // int f=a*2-(a-1)*3+a;
    // cout<<f<<endl;

    // return 0;
    cin>>n>>m>>k;
    for(int i=1;i<=n*m;i++)
        fa[i]=i,LCT::sz[i]=1;
    vector<int> ans(k);
    for(int C=0;C<k;C++)
    {
        int x,y;
        cin>>x>>y;
        int p=id(x,y);
        int bad=0;
        for(int i=x-2;i<=x;i++)
            for(int j=y-2;j<=y;j++)
            {
                bool ok=1;
                int sum=0;
                for(int k=0;k<3;k++)
                    for(int l=0;l<3;l++)
                    {
                        int pos=id(i+k,j+l);
                        if(pos==-1)
                            ok=0;
                        sum+=c[pos];
                    }
                if(!ok)
                    continue;
                if(sum==8)
                    bad=1;
            }
        if(bad)
            continue;
        for(int da=0;da<4;da++)
            for(int db=da+1;db<4;db++)
            {
                int u=id(x+dx[da],y+dy[da]);
                int v=id(x+dx[db],y+dy[db]);
                if(u==-1||v==-1)
                    continue;
                if(!c[u]||!c[v])
                    continue;
                if(find(u)!=find(v))
                    continue;
                int S=s[u]-s[v];
                S+=cals(v,p);
                S+=cals(p,u);
                S=abs(S);
                S/=2;

                LCT::makeroot(u);
                LCT::access(v);
                LCT::splay(v);
                int V=LCT::sz[v]+1;
                if(V!=2*(S+1))
                    bad=1;
            }
        c[p]=1;
        ans[C]=1;
        for(int d=0;d<4;d++)
        {
            int u=id(x+dx[d],y+dy[d]);
            if(u==-1||!c[u])
                continue;
            int fu=find(u),fp=find(p);
            if(fu==fp)
                continue;
            LCT::link(u,p);
            s[fu]=-s[u]+s[p]+cals(u,p);
            fa[fu]=fp;
        }
    }
    for(auto x:ans)
        cout<<x;
    cout<<"\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5668kb

input:

4 3 7
2 1
2 2
2 3
3 1
3 2
4 1
4 2

output:

1111111

result:

ok "1111111"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5668kb

input:

3 3 8
1 1
1 2
1 3
2 3
3 3
3 2
3 1
2 1

output:

11111111

result:

wrong answer 1st words differ - expected: '11111110', found: '11111111'