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

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

using namespace std;



int main() {

    long long input;

    cin >> input;

    for(long long i=0 ; i<input ; i++){

        int n,k,m;

        cin >> n >> k >> m;

        int minx=INT_MAX;

        vector<int> que(n,0);

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

            if(j==0){

                if(j+1==k){

                    if(que[j+1]==1 || que[n-j-1]==1 || que[m-1]==1){

                        if(que[j+1]==2 || que[n-j-1]==2 || que[m-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

                else if(j+1==m){

                    if(que[j+1]==1 || que[n-j-1]==1 || que[k-1]==1){

                        if(que[j+1]==2 || que[n-j-1]==2 || que[k-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

                else{

                    if(que[j+1]==1 || que[n-j-1]==1){

                        if(que[j+1]==2 || que[n-j-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

            }

            else if(j==n-1){

                if(j+1==k){

                    if(que[0]==1 || que[n-2]==1 || que[m-1]==1){

                        if(que[0]==2 || que[n-2]==2 || que[m-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

                else if(j+1==m){

                    if(que[0]==1 || que[n-2]==1 || que[k-1]==1){

                        if(que[0]==2 || que[n-2]==2 || que[k-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

                else{

                    if(que[0]==1 || que[n-2]==1){

                        if(que[0]==2 || que[n-2]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

            }

            else{

                if(j+1==k){

                    if(que[j+1]==1 || que[j-1]==1 || que[m-1]==1){

                        if(que[j+1]==2 || que[j-1]==2 || que[m-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

                else if(j+1==m){

                    if(que[j+1]==1 || que[j-1]==1 || que[k-1]==1){

                        if(que[j+1]==2 || que[j-1]==2 || que[k-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

                else{

                    if(que[j+1]==1 || que[j-1]==1){

                        if(que[j+1]==2 || que[j-1]==2){

                            que[j]=3;

                            minx=min(minx,que[j]);

                        }

                        else{

                            que[j]=2;

                            minx=min(minx,que[j]);

                        }

                    }

                    else{

                        que[j]=1;

                        minx=min(minx,que[j]);

                    }

                }

            }

        }

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

            cout << que[j]-minx << " ";

        }

        cout << endl;

    }

}

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

using namespace std;

#define int long long int



const int MOD = 1e9 + 7;

int add(int x, int y)

{

  return ((x + y) % MOD + MOD) % MOD;

}

int mul(int x, int y)

{

  return x * y % MOD;

}

int binpow(int x, int y)

{

  int z = 1;

  while (y)

  {

    if (y % 2 == 1)

      z = mul(z, x);

    x = mul(x, x);

    y /= 2;

  }

  return z;

}



int bp(int x, int y, int k)

{

  int z = 1LL;

  while (y)

  {

    if (y % 2 == 1)

      z = (z * x) % k;

    x = (x * x) % k;

    y = y / 2;

  }

  return z;

}



int inv(int x)

{

  return binpow(x, MOD - 2);

}

int divide(int x, int y)

{

  return mul(x, inv(y));

}



const int N = 2 * (1e5);

int spf[N + 1];



void smallestPrimefactor()

{

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

    spf[i] = i;

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

  {

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

    {

      spf[j] = min(spf[j], i);

    }

  }

}





void solve()

{

  int n;cin>>n;

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

  map<int,int> mp;



  mp[1]=0;

  mp[n]=1;



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

  {

    if(i!=x && i!=y)

    {

      int left = i-1;

      if(i==1)

      left=n;

      int right = i+1;

      if(i==n)

      right=1;



      int oc=0,zc=0;

      if(mp.find(left)!= mp.end())

      {

        if(mp[left]==1)

        oc=1;

        else if(mp[left]==0)

        zc=1;

      }

      if(mp.find(right)!=mp.end())

      {

        if(mp[right]==1)

        oc=1;

        else if(mp[right]==0)

        zc=1;

      }



      if(zc==0)

      mp[i]=0;

      else if(oc==0)

      mp[i]=1;

      else

      mp[i]=2;

    }

  }



  if(mp.find(x)==mp.end())

  {

    int oc=0;

    int zc=0;

    int left = x-1;

    if(x==1)

    left=n;

    int right = x+1;

    if(x==n)

    right=1;



    if(mp.find(left)!=mp.end())

    {

      if(mp[left]==1)

      oc=1;

      else if(mp[left]==0)

      zc=1;

    }

    if(mp.find(right)!=mp.end())

    {

      if(mp[right]==1)

      oc=1;

      else if(mp[right]==0)

      zc=1;

    }

    if(mp.find(y)!=mp.end())

    {

      if(mp[y]==1)

      oc=1;

      else if(mp[y]==0)

      zc=1;

    }



    if(zc==0)

    mp[x]=0;

    else if(oc==0)

    mp[x]=1;

    else

    mp[x]=2;

  }



  if(mp.find(y)==mp.end())

  {

    int oc=0;

    int zc=0;

    int tc=0;

    int left = y-1;

    if(y==1)

    left=n;

    int right = (y+1);

    if(y==n)

    right=1;



    if(mp.find(left)!=mp.end())

    {

      if(mp[left]==1)

      oc=1;

      else if(mp[left]==0)

      zc=1;

      else if(mp[left]==2)

      tc=1;

    }

    if(mp.find(right)!=mp.end())

    {

      if(mp[right]==1)

      oc=1;

      else if(mp[right]==0)

      zc=1;

      else if(mp[right]==2)

      tc=1;

    }

    if(mp.find(x)!=mp.end())

    {

      if(mp[x]==1)

      oc=1;

      else if(mp[x]==0)

      zc=1;

      else if(mp[x]==2)

      tc=1;

    }



    if(zc==0)

    mp[y]=0;

    else if(oc==0)

    mp[y]=1;

    else if(tc==0)

    mp[y]=2;

    else 

    mp[y]=3;

  }



  for(auto it : mp)

  cout<<it.second<<" ";

  

  cout<<"\n";





  

}







signed main()

{

  ios::sync_with_stdio(0);

  cin.tie(0);

  int t;cin>>t;

  while(t--)

  solve();

}