Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
/*-----AUTHOR--------

-------FREEBIE-------

https://codeforces.com/profile/freebie

*/



# include <bits/stdc++.h>

using namespace std;



# define ll long long

# define pb push_back

# define mp make_pair

# define f first

# define s second

# define mod 1000000007

# define py cout << "YES" << endl

# define pn cout << "NO" << endl

# define INF 1e18

# define vi vector<int>

# define vc vector<char>

# define vll vector<ll>

# define pii pair<int, int>

# define pll pair<ll, ll>

# define vvi vector<vi>

# define vvc vector<vc>

# define vpii vector<pii>

# define vpll vector<pll>

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

# define endl "\n"

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

# define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



int gcd(int a, int b){

    if(b == 0){

        return a;

    }

    return gcd(b, a%b);

}



int lcm(int a, int b){

    return (a*b)/gcd(a, b);

}



bool isPrime(int n){

    if(n == 1){

        return false;

    }

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

        if(n%i == 0){

            return false;

        }

    }

    return true;

}



void sieve(int n){

    bool prime[n+1];

    memset(prime, true, sizeof(prime));

    for(int p = 2; p*p <= n; p++){

        if(prime[p] == true){

            for(int i = p*p; i <= n; i += p){

                prime[i] = false;

            }

        }

    }

}   



ll binpow(ll a, ll b){

    if(b == 0) return 1;

    if(b%2){

        return (a * binpow(a, b-1)) % mod;

    }

    return binpow((a*a) % mod, b/2);

}



void solve(){

    int n, x, y;

    cin >> n >> x >> y;

    // vi v(n+1);

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

        // simply alternate between 0 and 1 if n is even

        if(n%2 == 0){

            for(ll i=0 ; i<n ; i++){

                cout << i%2 << " ";



            }

        }

        else{

            // if n is odd, then we need to print 0, 1, 0, 1, 0, 1, 0, 1, 0

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

                cout << i%2 << " ";

            }

            cout << 2;

        }

        return;

    }

    if(y == x+1){

        if(n%2 == 0){

            for(ll i=0 ; i<n ; i++){

                cout << i%2 << " ";



            }

        }

        else{

            // if n is odd, then we need to print 0, 1, 0, 1, 0, 1, 0, 1, 0

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

                cout << i%2 << " ";

            }

            cout << 2;

        }

        return;

    }



    vi v(n);

    v[x-1] = 0;

    v[y-1] = 1;

    for(ll i=x ; i+1<y ; i++){

        v[i] = 1 - v[i-1];

    }

    // 0 1 0 1 assign krne ke baad, we need  to check if we have same numbers occuring

    if(v[y-1] == v[y-2]){

        v[y-2] = 2;

    }

    ll prev = v[y-1];

    ll cnt  = 2;

    for(ll i=y%n ; i!=x-1 ; i= (i+1)%n){

        cnt++;

    }

    if(cnt%2){

        v[y%n] = 2;

        for( ll i = (y+1)%n ; i!=x-1 ; i = (i+1)%n){

            v[i] = 1 - prev;

            prev = v[i];

        }   

    }

    else{

        for(ll i = (y+1)%n ; i!=x-1 ; i = (i+1)%n){

            v[i] = 1 - prev;;

            prev = v[i];

        }

    }

    for(auto i : v){

        cout << i << " ";

    }

    return;







}



int main()

{

    fast;

    int TCS;

    cin >> TCS;

    // TCS = 1;

    for (int TC = 1; TC <= TCS; ++TC)

    {

      solve();

    }

}

Submission (verdict: Wrong answer on test 1):
/*-----AUTHOR--------

-------FREEBIE-------

https://codeforces.com/profile/freebie

*/



# include <bits/stdc++.h>

using namespace std;



# define ll long long

# define pb push_back

# define mp make_pair

# define f first

# define s second

# define mod 1000000007

# define py cout << "YES" << endl

# define pn cout << "NO" << endl

# define INF 1e18

# define vi vector<int>

# define vc vector<char>

# define vll vector<ll>

# define pii pair<int, int>

# define pll pair<ll, ll>

# define vvi vector<vi>

# define vvc vector<vc>

# define vpii vector<pii>

# define vpll vector<pll>

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

# define endl "\n"

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

# define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



int gcd(int a, int b){

    if(b == 0){

        return a;

    }

    return gcd(b, a%b);

}



int lcm(int a, int b){

    return (a*b)/gcd(a, b);

}



bool isPrime(int n){

    if(n == 1){

        return false;

    }

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

        if(n%i == 0){

            return false;

        }

    }

    return true;

}



void sieve(int n){

    bool prime[n+1];

    memset(prime, true, sizeof(prime));

    for(int p = 2; p*p <= n; p++){

        if(prime[p] == true){

            for(int i = p*p; i <= n; i += p){

                prime[i] = false;

            }

        }

    }

}   



ll binpow(ll a, ll b){

    if(b == 0) return 1;

    if(b%2){

        return (a * binpow(a, b-1)) % mod;

    }

    return binpow((a*a) % mod, b/2);

}



void solve(){

    int n, x, y;

    cin >> n >> x >> y;

    // vi v(n+1);

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

        // simply alternate between 0 and 1 if n is even

        if(n%2 == 0){

            for(ll i=0 ; i<n ; i++){

                cout << i%2 << " ";



            }

        }

        else{

            // if n is odd, then we need to print 0, 1, 0, 1, 0, 1, 0, 1, 0

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

                cout << i%2 << " ";

            }

            cout << 2;

        }

        return;

    }

    else if(y == x+1){

        if(n%2 == 0){

            for(ll i=0 ; i<n ; i++){

                cout << i%2 << " ";



            }

        }

        else{

            // if n is odd, then we need to print 0, 1, 0, 1, 0, 1, 0, 1, 0

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

                cout << i%2 << " ";

            }

            cout << 2;

        }

        return;

    }



    else{

        vi v(n);

        v[x-1] = 0;

        v[y-1] = 1;

        for(ll i=x ; i+1<y ; i++){

            v[i] = 1 - v[i-1];

        }

        // 0 1 0 1 assign krne ke baad, we need  to check if we have same numbers occuring

        if(v[y-1] == v[y-2]){

            v[y-2] = 2;

        }

        ll prev = v[y-1];

        ll cnt  = 2;

        for(ll i=y%n ; i!=x-1 ; i= (i+1)%n){

            cnt++;

        }

        if(cnt%2){

            v[y%n] = 2;

            for( ll i = (y+1)%n ; i!=x-1 ; i = (i+1)%n){

                v[i] = 1 - prev;

                prev = v[i];

            }   

        }

        else{

            for(ll i = y%n ; i!=x-1 ; i = (i+1)%n){

                v[i] = 1 - prev;;

                prev = v[i];

            }

        }

        for(ll i=0 ; i<n ; i++){

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

        }

    }







}



int main()

{

    fast;

    int TCS;

    cin >> TCS;

    // TCS = 1;

    for (int TC = 1; TC <= TCS; ++TC)

    {

      solve();

    }

}