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

Solution 1 (runtime: 93 ms):
#pragma comment(linker, "/STACK:40000000")

#define _CRT_SECURE_NO_WARNINGS

#include<set>

#include<map>

#include<unordered_map>

#include<iostream>

#include<queue>

#include<sstream>

#include<cstdlib>

#include<cstdio>

#include<vector>

#include<string>

#include<cstring>

#include<algorithm>

#include<cassert>

#include<ctime>

using namespace std;

typedef vector<int>VI; typedef vector<VI>VVI;

typedef vector<string>VS;

typedef pair<int, int>PII;

#define FOR(i,n) for((i)=0;(i)<(n);(i)++)

#define FORN(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define FOR1(i,n) for((i)=1;(i)<=(n);(i)++)

#define BE(a) ((a).begin()),((a).end())

#define SI(a) ((int)(a).size())

#define CLR(a) memset(a,0,sizeof(a))

#define PB push_back

#define MP make_pair



int n, x, y;

int a[200005];



void Solve()

{

    int i, j;

    FOR(i, n) a[i] = i % 2;

    if (n % 2) a[n - 1] = 2;

    if ((x + 1) % n != y && (y + 1) % n != x && a[x] == a[y])

    {

        if (n % 2) FOR(i, n) a[(x + i) % n] = i % 2;

        a[x] = 2;

    }

    /*FOR(i, n)

    {

        set<int> b;

        for (j = -1; j <= 1; j++) b.insert(a[(n + i + j) % n]);

        if (i == x) b.insert(a[y]);

        else if (i == y) b.insert(a[x]);

        for (j = 0; ; j++) if (!b.count(j)) break;

        if (a[i] != j)

        {

            ;

        }

    }*/

}



void WriteAnswer()

{

    int i;

    FOR(i, n)

    {

        if (i) cout << " ";

        cout << a[i];

    }

    cout << endl;

}



void ReadInput()

{

    cin >> n >> x >> y;

    x--, y--;

}



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0), cout.tie(0);

#if !ONLINE_JUDGE

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

#endif

    int t;

    for (cin >> t; t > 0; t--)

    {

        ReadInput();

        Solve();

        WriteAnswer();

    }

    return 0;

}



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

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

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

typedef long long int ll;

//#define mod 1e9 + 7;

using namespace std;

const int high=1e18;

//using namespace __gnu_pbds;

//template <typename T>

//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



ll solve(ll n, ll m)



{



   if (m == 0)

      return 1;

   ll ans = solve(n, m - 1);

   // ans=ans% ll( 1e9+7);

   ans = ans * n;

   // ans=ans% ll( 1e9+7);

   return ans;

}

bool square(ll x)

{

    if (x >= 0) {



        ll sr = sqrt(x);

        return (sr * sr == x);

    }

    // else return false if n<0

    return false;

}

 vector<int> sieve( 2000001);

 

// ll a=1e5+1;

 int l=1e5;

 // vector<ll> ans;



 

void helper()

{

  ll n,x,y;

  cin>>n>>x>>y;

//   x--;

//   y--;



  vector<set<ll>> st(n+1);



  vector<ll> ans(n+1,0);

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

  {

       int mex=0;

       for( auto ngh: st[i])

       {

        if( ngh!=mex) {

            //mex=ngh;

            break;

        }

        else mex++;

       }



  ans[i]=mex;



  int left=i-1;

  if( left==0) left=n;



  int right=i+1;

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



   st[left].insert( mex);

   st[right].insert( mex);



   if( i==x)

   {

        st[y].insert( mex);

   }



   if( i==y)

   {

    st[x].insert( mex);

   }

 //cout<<mex<<" ";

  }

    

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

  {

    cout<<ans[i]<<" ";

  }

  cout<<endl;

 

       

  }



int main()

{

   ios::sync_with_stdio(false);

   cin.tie(0);

    ll t0;

  int N=2000001;

    for(int i=2;i<N;i++){

        sieve[i]=1;

    }

    for(int i=2;i*i<N;i++){//n(log(log(n)))

        if(sieve[i]){

            for(int j=i*i;j<N;j+=i){

                sieve[j]=0;

            }

        }

    }

    //   int i=2;

    //   ll ans=0;

    //  while( ans<64)

    //  {

    //     if( sieve[i]==1)

    //     {

    //       ans++;

    //       no=i;

    //     }

    //  i++;

  

    //  }

  

  

      //ll t0;

   //  helper();



cin>>t0;

  for( int t=1;t<=t0;t++)

      {

   helper();

}

  

}