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

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

// g++-14 -o main [file].cpp;

//./main < input.txt > output.txt

using namespace std;



#pragma region

#define ll long long

template<typename T>

void print(T v[], int n, int i = 0){

    for(; i < n; ++i){ 

        cout << v[i] << " ";

    }

    cout << endl;

}

template<typename T>

void print(vector<T> v){

    for(int i =0 ; i < v.size(); ++i){ 

        cout << v[i] << " ";

    }

    cout << endl;

}

ll inv_mod_prime(ll a, ll MOD) {

  return a <= 1 ? a : MOD - (MOD/a) * inv_mod_prime(MOD % a, MOD) % MOD;

}

// count number of bits 

// only for int64 and int32

//__builtin_popcount 



// bool is_prime[4'00'001];

// void sieve(int n){ 

//     memset(is_prime, true, sizeof(is_prime));

//     is_prime[0] = is_prime[1] = false;

//     for(int i = 4; i <= n; i += 2){ 

//         is_prime[i] = false;

//     }

//     for(int i = 9; i <= n; i += 6){ 

//         is_prime[i] = false;

//     }

//     for(int i = 15; i <= n; i += 10){ 

//         is_prime[i] = false;

//     }

//     int num = 7; 

//     while(num  <= n){

//         if(is_prime[num]){

//             for(int i = num+num; i <= n; i += num){

//                 is_prime[i] = false;

//             }

//         }

//         num += 2;

//     }

// }

#pragma endregion





int a[2'00'001];

int n, x, y;



int convert_ind(int i){ 

    if(i == 0) return n;

    if(i == n+1) return 1;

    return i;



}



void solve(){

    cin >> n >> x >> y;

    int start = x; 

    int diff = y-x;

    int rev_diff = n-diff; 



    int val = 0;

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

        a[i] = val; 

        val ^= 1;

    }

    if(diff%2 == 0){ 

        a[convert_ind(y-1)] = 2; 

        a[y] = 1;

    }

    int ind = x;

    val = 0;

    while(ind != y){ 

        a[ind] = val;

        val ^= 1;

        ind--;

        ind = convert_ind(ind);

    }

    if(rev_diff%2 == 0){ 

        a[convert_ind(y+1)] = 2;

        a[y] = 1;

    }



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

        cout << a[i] << " ";

    }

    cout << endl;

















    







}



int main(){

    ios::sync_with_stdio(false); 

    cin.tie(nullptr);

    int t; 

    cin >> t; 

    while(t--){

        

        solve();

    }

    return 0;

}

Solution 2 (runtime: 108 ms):


// Online IDE - Code Editor, Compiler, Interpreter



#include<iostream>

#include <bits/stdc++.h>



using namespace std;



int main()

{

    int t,n,x,y;

    cin>>t;

    while(t--){

        cin>>n>>x>>y;

        vector<int> v(n+1);

        v[x]=0;

        v[y]=1;

        int a,b,count=0,n1,n2;

        a=x,b=y-1,n1=x,n2=y;

        while(b>a){

            if(count%2==0)

            v[b]=0;

            else

            v[b]=1;

            b--;

            count++;

        }

        //count=0;

/*        x--;

        while(x>=0){

            if(count%2==0)

            v[x]=0;

            else

            v[x]=1;

            x--;

            count++;

        }*/

        count=0;

        y++;

        while(y%(n+1)!=x){

            if(count%2==0)

            v[y%(n+1)]=0;

            else

            v[y%(n+1)]=1;

            //y++;

            if(y%(n+1)!=0)

            count++;

            y++;

            //cout<<y<<endl;

        }

        //cout<<y<<endl;

        if(n2-n1>1 && (n2-n1)%2==0){

            if(n1==n)

            v[1]=2;

            else

            v[n1+1]=2;

        }

        if(n-(n2-n1)>1 && (n-(n2-n1))%2==0){

            if(n1==1)

                v[n]=2;

                else

                v[n1-1]=2;

            

        }

        int i=1;

        while(i<=n)

        {

            cout<<v[i]<<" ";

            i++;

        }

        

        

    }

    return 0;

}