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

Solution 1 (runtime: 62 ms):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <map>

#include <cmath>



using namespace std;

typedef long long LL;

typedef pair<int,int> PII;

const int mod = 998244353;



int T;

int n,x,y;



int main()

{

    scanf("%d",&T);

    

    while(T--)

    {

        scanf("%d%d%d",&n,&x,&y);

        

        if(n%2==1)

        {

            int cnt = 0;

            int dx[2] = {0,1};

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

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

            {

                if(i!=y)

                {

                    printf("%d ",dx[(cnt++)%2]);

                }

                else printf("2 ");

            }printf("\n");

        }

        else

        {

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

            

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

            {

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

                {

                    if((x-i)%2==1) printf("0 ");

                    else printf("1 ");

                }

                int cnt = 0;

                int dx[2] = {0,1};

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

                {

                    if(i==x) printf("1 ");

                    else if(i==y) printf("2 ");

                    else

                    {

                        printf("%d ",dx[(cnt++)%2]);

                    }

                }

                cnt = 0;

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

                {

                    printf("%d ",dx[(cnt++)%2]);

                }

                printf("\n");

            }

            else

            {

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

                {

                    if(abs(x-i)%2==1) printf("1 ");

                    else printf("0 ");

                }

                printf("\n");

            }

        }

    }



    return 0;

}

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

using namespace std;

 

#define int long long 

 

void solve(){

    int n, x, y;

    cin >> n >> x >> y;



    if (n == 3){

        cout << 0 << " " << 1 << " " << 2;

        return;

    }

    if (n == 4){

        if (abs(x - y) == 2){

            for (int i = 1; i <= 4; i++){

                if (i == x) cout << 0;

                else if (i == y) cout << 2;

                else cout << 1;

                cout << " ";

            }

        }

        else {

            cout << 0 << " " << 1 << " " << 0 << " " << 1;

        }

        return;

    }



    vector<int> a(n+1, -1);



    queue<int> q;

    q.push(x);



    while (!q.empty()){

        int cur = q.front();

        q.pop();



        int prv = (cur == 1 ? n : cur-1);

        int nxt = (cur == n ? 1 : cur+1);



        int third = -1;

        if (cur == x) third = y;

        if (cur == y) third = x;



        int ans = 0;

        if (third == -1){

            while (ans == a[prv] || ans == a[nxt]){

                ans++;

            }

        }

        else {

            while (ans == a[prv] || ans == a[nxt] || ans == a[third]){

                ans++;

            }

        }



        a[cur] = ans;

        if (a[prv] == -1) q.push(prv);

        if (a[nxt] == -1) q.push(nxt);

        if (third != -1 && a[third] == -1) q.push(third);

    }



    for (int i = 1; i <= n; i++) cout << a[i] << " ";

}

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t = 1; 

    cin >> t; 

    while (t--){ 

        solve();

        cout << '\n';

    } 

}