Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;

#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma optimize("unroll-loops")

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define all(x) x.begin(), x.end()

#define rll(x) x.rbegin(), x.rend()

#define COMP(x) x.erase(unique(all(x)), x.end())

#define MOD 1000000007

#define MOD2 998244353

#define sz(x) (ll)x.size()

typedef __int128_t lll;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<ll,ll> pll;

typedef pair<ll, pll> PP;

const ll Lnf = 2e18;

const ll inf = 1e9;

void solve(){

    ll n; cin>>n;

    ll x,y; cin>>x>>y; x--; y--;

    if(x+1==y){

        if(~n&1)for(int i = 0 ; i < n ; i++)cout<<(i&1)<<" \n"[i==n-1];

        else{

            for(int i = 0 ; i < n-1 ; i++)cout<<(i&1)<<" ";

            cout<<2<<"\n";

        }

        return;

    }

    if(~n&1){

        vector<ll> ans(n);

        if((y-x-1)%2==0){

            ans[x]=2;

            for(int i = x+1, j = 0 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]= 3;

            for(int i = (y+1)%n, j = 0 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        else{

            ans[x]=1;

            for(int i = x+1, j = 0 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]=2;

            for(int i = (y+1)%n, j = 0 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        for(auto i : ans)cout<<i<<" "; cout<<"\n";

    }

    else{

        vector<ll> ans(n);

        if((y-x-1)%2==1){

            ans[x]=1;

            for(int i = x+1, j = 0 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]=2;

            for(int i = (y+1)%n, j = 1 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        else{

            ans[x]=2;

            for(int i = x+1, j = 1 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]=1;

            for(int i = (y+1)%n, j = 0 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        for(auto i : ans)cout<<i<<" "; cout<<"\n";

    }

}

int main(){

    fast;

    ll t; cin>>t; while(t--)solve();

}



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

using namespace std;

#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma optimize("unroll-loops")

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define all(x) x.begin(), x.end()

#define rll(x) x.rbegin(), x.rend()

#define COMP(x) x.erase(unique(all(x)), x.end())

#define MOD 1000000007

#define MOD2 998244353

#define sz(x) (ll)x.size()

typedef __int128_t lll;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<ll,ll> pll;

typedef pair<ll, pll> PP;

const ll Lnf = 2e18;

const ll inf = 1e9;

void solve(){

    ll n; cin>>n;

    ll x,y; cin>>x>>y; x--; y--;

    if(x+1==y or (x==0 and y==n-1)){

        if(~n&1)for(int i = 0 ; i < n ; i++)cout<<(i&1)<<" \n"[i==n-1];

        else{

            for(int i = 0 ; i < n-1 ; i++)cout<<(i&1)<<" ";

            cout<<2<<"\n";

        }

        return;

    }

    if(~n&1){

        vector<ll> ans(n);

        if((y-x-1)%2==0){

            ans[x]=2;

            for(int i = x+1, j = 0 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]= 3;

            for(int i = (y+1)%n, j = 0 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        else{

            ans[x]=1;

            for(int i = x+1, j = 0 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]=2;

            for(int i = (y+1)%n, j = 0 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        for(auto i : ans)cout<<i<<" "; cout<<"\n";

    }

    else{

        vector<ll> ans(n);

        if((y-x-1)%2==1){

            ans[x]=1;

            for(int i = x+1, j = 0 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]=2;

            for(int i = (y+1)%n, j = 1 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        else{

            ans[x]=2;

            for(int i = x+1, j = 1 ; i < y ; i++, j++)ans[i] = (j&1);

            ans[y]=1;

            for(int i = (y+1)%n, j = 0 ; i != x ; i=(i+1)%n, j++)ans[i] = (j&1);

        }

        for(auto i : ans)cout<<i<<" "; cout<<"\n";

    }

}

int main(){

    fast;

    ll t; cin>>t; while(t--)solve();

}