WA on test 2求调
查看原帖
WA on test 2求调
397982
Deuteron楼主2022/10/25 20:25
#include<iostream>
using namespace std;
int t,n;
const int N=2e5+5;
int f[N],g[N],c[N],ans,tot,p,w;
int chk(int l,int r){
    return (r-l+1)%2;
}
int main(){
    cin>>t;
    for(int T=1;T<=t;T++){
        cin>>n;
        tot=0;
        for(int i=1;i<=n;i++){
            cin>>f[i];
            if(f[i]!=0){
                g[++tot]=f[i];
                c[tot]=i;
            }
        }
        if(tot==0){
			cout<<1<<"\n";
            cout<<1<<" "<<n<<"\n";
            continue;
        }
        if(tot&1){
            cout<<"-1\n";
            for(int i=1;i<=tot+1;i++) c[i]=g[i]=0;
            continue;
        }
        c[tot+1]=n+1;
        ans=0;
        for(int i=1;i<=tot;i+=2){
            p=(g[i]!=g[i+1]);
            w=chk(c[i],c[i+1]);
            if(p||w) ans++;
            ans++;
        }
        cout<<ans<<endl;
        for(int i=1;i<=tot;i+=2){
            p=(g[i]==g[i+1]);
            w=chk(c[i],c[i+1]);
            if(c[1]>1) c[1]=1;
            if(p){
            	if(w) cout<<c[i]<<" "<<c[i+1]-2<<"\n"<<c[i+1]-1<<" "<<c[i+2]-1<<"\n";
            	else cout<<c[i]<<" "<<c[i+2]-1<<"\n";
			}
            else cout<<c[i]<<" "<<c[i+1]-1<<"\n"<<c[i+1]<<" "<<c[i+2]-1<<"\n";
        }
        for(int i=1;i<=tot+1;i++) c[i]=g[i]=0;
    }
    return 0;
}
2022/10/25 20:25
加载中...