Problem: 2049C - MEX Cycle
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>

#define ll long long

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

using namespace std;







void solve() {

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

    vector<int> arr(n, -1);

    x--; y--;

    arr[x]=0;

    if (x + 1 < n) arr[x+1]=1;

    else arr[0]=1;

    

    if (x-1>=0) arr[x-1]=1;

    else arr[n-1]=1;



    if(arr[y]==-1){

        arr[y]=1;

        if (y + 1 < n && arr[y + 1] == -1) arr[y + 1] = 0;

        else if (y + 1 == n && arr[0] == -1) arr[0] = 0;

        

        if (y - 1 >= 0 && arr[y - 1] == -1) arr[y - 1] = 0;

        else if (y - 1 < 0 && arr[n - 1] == -1) arr[n - 1] = 0;

    }



    int cnt = (x + 1 == n) ? 0 : x + 1;



    for(int i=0; i<n; i++){





        int prev = (cnt == 0) ? arr[n - 1] : arr[cnt - 1];

        int aft = -1;



        if (cnt + 1 < n && arr[cnt + 1] != -1) aft = arr[cnt + 1];

        else if (cnt + 1 == n && arr[0] != -1) aft = arr[0];



        if (aft == -1) {

            if (cnt + 1 == n) arr[0] = prev, aft = arr[0];

            else arr[cnt + 1] = prev, aft = arr[cnt + 1];

        }



        if(cnt == x || cnt==y){

            cnt=(cnt+1)%n;

            continue;

        }



        if (arr[cnt] == prev || arr[cnt] == aft) arr[cnt] = 2;

        cnt = (cnt + 1) % n; 

    }

    

    

    for(auto &it:arr) cout<<it<<" ";

    cout<<'\n';

}



int main() {

    fastIo();

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++) solve();

}

Solution 2 (runtime: 62 ms):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<queue>

#include<array>

#include<stack>

#include<set>

#include<map>

#include<vector>

#include<ctime>

#include<bitset>

#include<random>

#include<tuple>

#define ull unsigned long long 

#define ll long long

#define max_ll 9223372036854775807

#define max_int 2147483647

#define elif else if

#define rep(i, l, r) for(register ll i = l; i <= r; ++i)

#define nep(i, r, l) for(register ll i = r; i >= l; --i)

#define YES puts("Yes");

#define NO puts("No");

using namespace std;

template<class T>inline void read(T &x)

{

    x=0;char c=getchar();bool f=0;

    while(!isdigit(c))f^=c=='-',c=getchar();

    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();

    if(f)x=-x;

}

template<class T>inline void print(T x)

{

    if(x<0)putchar('-'),x=-x;

    if(x>9)print(x/10);

    putchar('0'+x%10);

}

int t;

int n;

int x,y;

int ans[200005];

void sol(){

	read(n);read(x);read(y);

	ans[x]=0;

	ans[y]=1;

	int len=y-x-1;

	if(len%2==0){

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

			ans[i]=ans[i-1]^1;

		}

	}else{

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

			ans[i]=ans[i-1]^1;

		}

		ans[y-1]=2;

	}

	len=n-len-2;

	int k=1;

	if(len%2==0){

		for(int i=x-1;i>=1;i--){

			ans[i]=k;

			k^=1;

		}

		for(int i=n;i>y;i--){

			ans[i]=k;

			k^=1;

		}

	}else{

		for(int i=x-1;i>=1;i--){

			ans[i]=k;

			k^=1;

		}

		for(int i=n;i>y;i--){

			ans[i]=k;

			k^=1;

		}

		ans[y%n+1]=2;

	}

	for(int i=1;i<=n;++i)

		printf("%d ",ans[i]);

	puts("");

}

int main(){

	read(t);

	while(t--){

		sol();

	}

	return 0;

}