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

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

#include<algorithm>

#include <bits/stdc++.h>

#include<vector>

typedef long long int ll;

#define pb push_back

#define vi vector<int>

#define vii vector<pair<int,int>> 

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

#define rall(n) n.rbegin(), n.rend()

//#define mod 1000000007

#define mod 998244353

#define INF (1LL<<62)

#define N 200006

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> 

// #include <ext/pb_ds/tree_policy.hpp> 

// using namespace __gnu_pbds;   

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// int dx[9] = {1,-1,0,0,-1,-1,1,1};

// int dy[9] = {0,0,1,-1,1,-1,-1,1};

// ll power(int pow, ll n, ll m)

// {

//   ll result = 1;

//   while(n)

//   {

//     if(n%pow==1)

//     {

//       result = (result * pow)%mode;

//     }

//     else pow = (pow * pow)

//   }

// }

//long long power(long long a, long long b, long long mode)

// {

//     long long result = 1;

//     while (b) {

//         if (b & 1)

//             result = (result * a) % mode;

//         a = (a * a) % mode;

//         b >>= 1;

//     }

//     return result;

// }

ll arr[200010], seg[400010];

ll fact[100];

void build(int index, int low, int high, int pos)

{

    if(low==high)

    {

        seg[index] = arr[low];

        return;

    }

    int mid = (low+high)/2;

    if(pos==1)pos = 2;

    else pos = 1;

    build(2*index+1,low,mid,pos);

    build(2*index+2,mid+1,high,pos);



    if(pos==2)

    {

        seg[index] = seg[2*index+1] ^ seg[2*index+2];

    }

    else

    {

        seg[index] = seg[2*index+1] | seg[2*index+2];



    }

}

void point_update(int index, int low, int high, int node, int value)

{

    if(low == high)

    {

        seg[index] = 1;

        //cout<<seg[low]<<" "<<low<<endl;

        return;

    }

    int mid = (low + high)>>1;

    if(node <= mid && node >= low)

    {

        point_update(2*index + 1, low, mid, node, value);

    }

    else

    {

        point_update(2*index+2, mid+1, high, node, value);

    }

    seg[index] = seg[2*index+1] + seg[2*index+2];

    //cout<<index<<" ==> "<<seg[index]<<endl;



}

ll power(int x,int n)

{

    ll ans = 1;

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

    {

        ans = ans * x;

    }

    return ans;

}

ll powerMod(ll a, ll b){

    if(b==0) return 1;



    if(b%2==0){

        ll x = powerMod(a, b/2);

        return (x*x)%mod;

    }

    else {

        ll x = powerMod(a, b/2);

        return ((x*x)%mod * a)%mod;

    }



    return 0;

}



ll inverseMod(ll a){

    return powerMod(a, mod-2);

}



ll nCrMod(ll n, ll r){

    if (r == 0)

        return 1;

    if (r > n)

        return 0;

    

    return (fact[n] * inverseMod((fact[r] * fact[n-r]) % mod)) % mod;

}

bool first_less(std::pair<int, int> lhs, int rhs) {

    return lhs.first < rhs;

}

bool comp(pair<int,int>a, pair<int,int>b)

{

    if(a.first==b.first)

    {

        return a.second>b.second;

    }

    return a.first<b.first;

}





void solve()

{



  int t = 1; cin>>t;

  

  //cout<<t<<endl;

  while(t--)

  {

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

    map<pair<int,int>,int>mp;



    int arr[n+10];



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



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

    {

        mp[{i,i+1}] = 1;

    }

    mp[{1,n}] = 1;



    if(mp[{x,y}]==0 && n%2==1)

    {

        //cout<<"yuy";

        arr[y] = 1;

        arr[x] = 2;

        int s = 0;



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

        {

            arr[i] = s;

            if(s==0)s = 1;

            else s = 0;

        }

        s = 0;

        for(int i = y+1; i!=x;i++)

        {

            if(i>n)arr[1] = s;

            else

            arr[i] = s;

            if(s==0)s = 1;

            else s = 0;



            i = i % n;

        }

    }

    else if(mp[{x,y}]==0 && n%2==0)

    {

        int s = 0;

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

        {

            arr[i] = s;

            if(s==0)s = 1;

            else s = 0;

        }

        if(x%2==y%2)

        {

            arr[x] = 2;

        }

    }

    else

    {

        if(n%2==0)

        {

            int s = 0;

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

            {

                arr[i] = s;

                if(s==0) s= 1;

                else s = 0;

            }

        }

        else

        {

            int s = 0;

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

            {

                arr[i] = s;

                if(s==0) s= 1;

                else s = 0;

            }

            arr[n] = 2;

        }

    }



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

    {

        cout<<arr[i]<<" ";

    }

    cout<<endl;

    

  }





  

}

        

 

int main()

{

   #ifndef ONLINE_JUDGE 

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

    freopen("outputra.o", "w", stdout);  

   #endif

   std::ios_base::sync_with_stdio(0);

   cin.tie(0);

   cout.tie(0);

 

   solve();   

   return 0;

    

    

}



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

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=2e5+5;

int a[N],n,x,y;

void work(){

    cin>>n>>x>>y;

    if(n&1){

        a[x]=2;

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

            x++;if(x==n+1)x=1;

            a[x]=(i&1);

        }

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

        cout<<endl;

        return;

    }

    for(int i=1;i<=n;i+=2)a[i]=1,a[i+1]=0;

    if(x+1==y||(y+1==x)||(x==1&&y==n)||(x==n&&y==1)){

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

        cout<<endl;

        return;

    }

    if(a[x]==a[y]){

        a[x]=2;

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

        cout<<endl;

        return;

    }

    a[x]=2;int xx=x;

    int fl=0;

    while(1){

        x++;if(x==n+1)x=1;

        if(x==y)break;

        if(fl==0)a[x]=0;

        if(fl==1)a[x]=2;

        if(fl>=2)a[x]=(fl-1)&1;

        fl++;

    }

    fl=0;x=xx;

    while(1){

        x--;if(x==0)x=n;

        if(x==y)break;

        a[x]=(fl-1)&1;

        fl++;

    }

    a[y]=1;

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

    cout<<endl;

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}