Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>

using namespace std;

#define print_b(ans) cout<<(ans?"YES":"NO")<<endl;

#define print_n(x)        cout<<x<<endl;

#define times(x)          int x;cin>>x;while(x--)

#define debug(x) cout<<#x<<": "<<x<<endl;

typedef long long ll;

void judge(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    #ifndef ONLINE_JUDGE

        freopen("input.txt","r",stdin);

        //freopen("output.txt","w",stdout);

    #endif

}

int main(){

    judge();

    times(x){

        int n,x,y;cin>>n>>x>>y;

        if(x<y)swap(x,y);

        vector<int> ans(n);

        ans[x-1]=1;

        ans[y-1]=0;

        int left=(x-y-1);

        int right=n-(x-y+1);

        if(left%2==0){

            bool test=1;

            for(int i=y;i<x-1;i++){

                ans[i]=test;

                test^=1;

            }

        }

        else{

            bool test=1;

            for(int i=y;i<(y+left/2);i++){

                ans[i]=test;

                test^=1;

            }

            ans[y+left/2]=2;

            for(int i=(y+left/2+1);i<x-1;i++){

                ans[i]=test;

                test^=1;

            }

        }

        if(right%2==0){

            bool test=false;

            int i=x;

            i%=n;

            while(i!=y-1){

                ans[i]=test;

                test^=true;

                i++;

                i%=n;

            }

        }

        else{

            bool test=0;

            int i=x;

            i%=n;

            int test1=(x+right/2)%n;

            while(i!=test1){

                ans[i]=test;

                test^=1;

                i++;

                i%=n;

            }

            ans[i]=2;

            i++;

            while(i!=y-1){

                ans[i]=test;

                test^=1;

                i++;

                i%=n;

            }

        }

        for(int i=0;i<n;i++)cout<<ans[i]<<" ";

        cout<<endl;

    }

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

#define print_b(ans) cout<<(ans?"YES":"NO")<<endl;

#define print_n(x)        cout<<x<<endl;

#define times(x)          int x;cin>>x;while(x--)

#define debug(x) cout<<#x<<": "<<x<<endl;

typedef long long ll;

void judge(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    #ifndef ONLINE_JUDGE

        freopen("input.txt","r",stdin);

        //freopen("output.txt","w",stdout);

    #endif

}

int main(){

    judge();

    times(x){

        int n,x,y;cin>>n>>x>>y;

        if(x<y)swap(x,y);

        vector<int> ans(n);

        ans[x-1]=1;

        ans[y-1]=0;

        int left=(x-y-1);

        int right=n-(x-y+1);

        if(left%2==0){

            bool test=1;

            for(int i=y;i<x-1;i++){

                ans[i]=test;

                test^=1;

            }

        }

        else{

            bool test=1;

            for(int i=y;i<(y+left/2);i++){

                ans[i]=test;

                test^=1;

            }

            ans[y+left/2]=2;

            for(int i=(y+left/2+1);i<x-1;i++){

                ans[i]=test;

                test^=1;

            }

        }

        if(right%2==0){

            bool test=false;

            int i=x;

            i%=n;

            while(i!=y-1){

                ans[i]=test;

                test^=true;

                i++;

                i%=n;

            }

        }

        else{

            bool test=0;

            int i=x;

            i%=n;

            int test1=(x+right/2)%n;

            while(i!=test1){

                ans[i]=test;

                test^=1;

                i++;

                i%=n;

            }

            ans[i]=2;

            i++;

            i%=n;

            while(i!=y-1){

                ans[i]=test;

                test^=1;

                i++;

                i%=n;

            }

        }

        for(int i=0;i<n;i++)cout<<ans[i]<<" ";

        cout<<endl;

    }

}