蒟蒻求助前三个点RE
查看原帖
蒟蒻求助前三个点RE
161748
ssilrrr楼主2022/12/3 11:11
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int T,n,m,k;
struct node{
    int x,y,z;
};
vector<node> ans;
const int K=5e2+10;
int stk[K][5],sz[K];
int id[K],sps,spc;//stack color
int another[K];
void push(int x,int y){
    ans.push_back({1,x,0});
    stk[x][sz[x]++]=y;
    if(sz[x]>1&&stk[x][sz[x]-1]==stk[x][sz[x]-2]){
        sz[x]-=2;
        stk[x][sz[x]]=stk[x][sz[x]+1]=0;
    }
    //rep(i,0,sz[x]-1)cout<<stk[x][i]<<" ";cout<<endl;
}
void pop(int x,int y){
    ans.push_back({2,x,y});
    sz[x]--;sz[y]--;
    rep(i,0,sz[x]-1){
        stk[x][i]=stk[x][i+1];
    }rep(i,0,sz[y]-1){
        stk[y][i]=stk[y][i+1];
    }
    stk[x][sz[x]]=stk[y][sz[y]]=0;
}
const int N=1e7+5;
int a[N];
void slove(){
	memset(another,0,sizeof another);
	memset(id,0,sizeof id);
	memset(stk,0,sizeof stk);
	memset(sz,0,sizeof sz);
    scanf("%d%d%d",&n,&m,&k);
    rep(i,1,m){
        scanf("%d",a+i);
    }
    rep(i,1,n-1){
        id[i*2]=i;
        id[i*2-1]=i;
        another[i*2]=i*2-1;
        another[i*2-1]=i*2;
    }id[n*2-1]=n;
    sps=n;
    spc=n*2-1;
    rep(i,1,m){
        if(a[i]==spc){
            rep(j,i+1,m){
                if(a[j]==spc){
                    push(sps,a[i]);
                    rep(k,i+1,j-1){
                        push(id[a[k]],a[k]);
                    }
                    push(sps,a[j]);
                    i=j;break;
                }else if(a[j]==stk[id[a[j]]][0]){
                    int w=another[a[j]];
                    int an=0;
                    rep(k,i+1,j-1){
                        an+=(a[k]==w);
                    }
                    an+=stk[id[a[j]]][1]==w;
                    if(an%2==0){
                        push(sps,a[i]);
                        rep(k,i+1,j-1){
                            if(a[k]==w){
                                push(id[a[j]],a[k]);
                            }else{
                                push(id[a[k]],a[k]);
                            }
                        }
                        push(id[a[j]],a[j]);
                        sps=id[a[j]];
                        id[w]=id[spc];
                        another[spc]=w;
                        another[w]=spc;
                        another[a[j]]=0;
                        spc=a[j];
                    }else{
                        push(id[a[j]],a[i]);
                        rep(k,i+1,j-1){
                            if(a[k]==w){
                                push(id[a[j]],a[k]);
                            }else{
                                push(id[a[k]],a[k]);
                            }
                        }
                        push(sps,a[j]);
                        pop(id[a[j]],sps);
                        id[a[i]]=id[a[j]];
                        id[a[j]]=sps;
                        another[spc]=w;
                        another[w]=spc;
                        another[a[j]]=0;
                        spc=a[j];
                    }i=j;break;
                }else if(sz[id[a[j]]]==0){
                	push(id[a[j]],a[i]);
                    rep(k,i+1,j-1){
                        push(id[a[k]],a[k]);
                    }
                    push(id[a[j]],a[j]);
                    id[another[a[j]]]=id[a[i]];
                    id[a[i]]=id[a[j]];
                    sps=id[another[a[j]]];
                    spc=another[a[j]];
                    another[another[a[j]]]=0;
                    another[a[i]]=a[j];
                    another[a[j]]=a[i];
                    i=j;break;
                }
            }
        }else{
            if(a[i]==stk[id[a[i]]][0]){
                push(sps,a[i]);
                pop(sps,id[a[i]]);
            }else{
                push(id[a[i]],a[i]);
            }
        }
    }
}
signed main(){
    scanf("%d",&T);
    while(T--){slove();
    printf("%d\n",ans.size());
    for(auto i:ans){
        if(i.x==1)printf("%d %d\n",i.x,i.y);
        else printf("%d %d %d\n",i.x,i.y,i.z);
    }ans.clear();
    }
}

85,前三个点RE,蒟蒻不理解

https://www.luogu.com.cn/record/96373195

2022/12/3 11:11
加载中...