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

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

#include <algorithm>

#include <ctime>



using namespace std;

#define ull unsigned long long

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define new cout << endl

#define ll  long long

#define pb push_back

#define vll vector<long long>

#define INF (long long)1e9  

#define MOD 1000000007

#define mp make_pair

#define F first

#define S second

#define f(i, a, b) for(long long i = a; i < b; i++) // Loop from a to b

long long gcd(long long a, long long b) {

    while (b != 0) {

        long long temp = b;

        b = a % b;

        a = temp;

    }

    return a;

}

long long lcm(long long a, long long b) {

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

}

long long factorial(int n) {

    long long result = 1;

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

        result *= i;

    }

    return result;

}



long long combination(int n, int r) {

    if (r > n) return 0;

    if (r == 0 || r == n) return 1; 



    

    if (r > n - r) r = n - r;



    long long result = 1;



    for (int i = 0; i < r; ++i) {

        result *= (n - i);

        result /= (i + 1); 

    }



    return result;

}



bool damn(const pair<int, int>& a, const pair<int, int>& b) {   

    if (floor(log2(a.first)) != floor(log2(b.first))) {

        return floor(log2(a.first)) <floor(log2(b.first));  

    }

    else if(a.second!=b.second){

        return a.second<b.second;

    }

    return a.first > b.first; 

};





       

    

vector<long long> sieve_of_eratosthenes(long long limit) {

    vector<bool> prime(limit + 1, true);

    prime[0] = prime[1] = false;

    

    for (long long num = 2; num * num <= limit; ++num) {

        if (prime[num]) {

            for (long long multiple = num * num; multiple <= limit; multiple += num) {

                prime[multiple] = false;

            }

        }

    }



    vector<long long> primes;

    for (long long i = 2; i <= limit; ++i) {

        if (prime[i]) {

            primes.push_back(i);

        }

    }

    

    return primes;

};

void merge(int arr[], int left, int right) {

    if (left >= right) return;

    int mid = left + (right - left) / 2;

    merge(arr, left, mid);

    merge(arr, mid + 1, right);

    

    int n1 = mid - left + 1;

    int n2 = right - mid;

    

    int L[n1], R[n2];

    for (int i = 0; i < n1; i++) L[i] = arr[left + i];

    for (int i = 0; i < n2; i++) R[i] = arr[mid + 1 + i];

    

    int i = 0, j = 0, k = left;

    while (i < n1 && j < n2) {

        if (L[i] <= R[j]) arr[k++] = L[i++];

        else arr[k++] = R[j++];

    }

    

    while (i < n1) arr[k++] = L[i++];

    while (j < n2) arr[k++] = R[j++];

};



void mergeSort(int arr[], int left, int right) {

    if (left < right) {

        int mid = left + (right - left) / 2;

        mergeSort(arr, left, mid);

        mergeSort(arr, mid + 1, right);

        merge(arr, left, right);

    }

};

struct item{

    ll m,c;

};

int count_trailing_zeros(ll n) {

    int count = 0;



    

    while ((n & 1) == 0 && n != 0) {

        count++;

        n >>= 1;  

    }



    return count;

}





int popcount(ll n) {

    int count = 0;

    

    

    while (n) {

        

        n = n & (n - 1);  

        count++;          

    }

    

    return count;

}







struct segTree {

    ll size;

    vll sums;



    void init(int n) {

        size = 1;

        while (size < n) {

            size *= 2;

        }

        sums.assign(2 * size, 0LL);

    }



    void set(ll i, ll v, ll x, ll lx, ll rx) {

        if (rx - lx == 1) {

            sums[x] = v;

            return;

        }

        ll m = (lx + rx) / 2;

        if (i < m) {

            set(i, v, 2 * x + 1, lx, m);

        } 

        else {

            set(i, v, 2 * x + 2, m, rx);

        }

        sums[x] = gcd(sums[2 * x + 1] , sums[2 * x + 2]);

    }



    void set(ll i, ll v) {

        set(i, v, 0, 0, size);

    }



    ll sum(ll l, ll r, ll x, ll lx, ll rx) {

        if (lx >= r || l >= rx) return 1e9;

        if (lx >= l && rx <= r) return sums[x];

        ll m = (lx + rx) / 2;

        ll s1 = sum(l, r, 2 * x + 1, lx, m);

        ll s2 = sum(l, r, 2 * x + 2, m, rx);

        return gcd(s1 , s2);

    }



    ll sum(ll l, ll r) {

        return sum(l, r, 0, 0, size);

    }

};

bool isPerfectPowerOf3(int n) {

    if (n <= 0) {

        return false;

    }

    while (n % 3 == 0) {

        n /= 3;

    }



    return n == 1;

}





int main() {

 

    #ifndef ONLINE_JUDGE

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

    freopen("output.txt", "w", stdout);

    #endif

    ll test_cases;

    cin>>test_cases;

    auto start = chrono::high_resolution_clock::now();



    f(j,0,test_cases){

        ll m,y,x,r1,maxi=0,k;bool change=true; bool sorted=false;ll sum=0;ll sum1=0;ll mini=1e9;

        long long n,d;

        cin>>n>>d>>k;

        vll vec_1(n);

        if(n%2==0){

            

            f(i,0,n){

                vec_1[i]=i%2;

            }

            if(vec_1[d-1]==vec_1[k-1]){

                if(d-1==0){

                    set<ll> i;

                    i.insert(vec_1[n-1]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

                else if(d-1!=n-1){

                    set<ll> i;

                    i.insert(vec_1[d-2]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

                else{

                    set<ll> i;

                    i.insert(vec_1[d-2]);

                    i.insert(vec_1[0]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

            }

        }

        else{

            f(i,0,n-1){

                vec_1[i]=i%2;

            }

            vec_1[n-1]=2;

            if(vec_1[d-1]==vec_1[k-1]){

                if(d-1==0){

                    set<ll> i;

                    i.insert(vec_1[n-1]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

                else{

                    set<ll> i;

                    i.insert(vec_1[d-2]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

            }

        }

        if(d!=n && k!=n){

            set<ll> t;

            t.insert(vec_1[n-2]);

            t.insert(vec_1[0]);

            f(z,0,4){

                if(t.find(z)==t.end()){

                    vec_1[n-1]=z;

                    break;

                }

            }

        }

        else if(d==n){

            set<ll> t;

            t.insert(vec_1[n-2]);

            t.insert(vec_1[0]);

            t.insert(vec_1[k-1]);

            f(z,0,4){

                if(t.find(z)==t.end()){

                    vec_1[n-1]=z;

                    break;

                }

            }

        }

        else{

            set<ll> t;

            t.insert(vec_1[n-2]);

            t.insert(vec_1[0]);

            t.insert(vec_1[d-1]);

            f(z,0,4){

                if(t.find(z)==t.end()){

                    vec_1[n-1]=z;

                    break;

                }

            }

        }

        f(i,0,n){

            cout<<vec_1[i]<<" ";

        }

        cout<<endl;

    }

        

    

    auto end = chrono::high_resolution_clock::now();

    chrono::duration<double> duration = end - start;

    //cout << "Time taken: " << duration.count() << " seconds" << endl;

 

    return 0;

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

#include <algorithm>

#include <ctime>



using namespace std;

#define ull unsigned long long

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define new cout << endl

#define ll  long long

#define pb push_back

#define vll vector<long long>

#define INF (long long)1e9  

#define MOD 1000000007

#define mp make_pair

#define F first

#define S second

#define f(i, a, b) for(long long i = a; i < b; i++) // Loop from a to b

long long gcd(long long a, long long b) {

    while (b != 0) {

        long long temp = b;

        b = a % b;

        a = temp;

    }

    return a;

}

long long lcm(long long a, long long b) {

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

}

long long factorial(int n) {

    long long result = 1;

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

        result *= i;

    }

    return result;

}



long long combination(int n, int r) {

    if (r > n) return 0;

    if (r == 0 || r == n) return 1; 



    

    if (r > n - r) r = n - r;



    long long result = 1;



    for (int i = 0; i < r; ++i) {

        result *= (n - i);

        result /= (i + 1); 

    }



    return result;

}



bool damn(const pair<int, int>& a, const pair<int, int>& b) {   

    if (floor(log2(a.first)) != floor(log2(b.first))) {

        return floor(log2(a.first)) <floor(log2(b.first));  

    }

    else if(a.second!=b.second){

        return a.second<b.second;

    }

    return a.first > b.first; 

};





       

    

vector<long long> sieve_of_eratosthenes(long long limit) {

    vector<bool> prime(limit + 1, true);

    prime[0] = prime[1] = false;

    

    for (long long num = 2; num * num <= limit; ++num) {

        if (prime[num]) {

            for (long long multiple = num * num; multiple <= limit; multiple += num) {

                prime[multiple] = false;

            }

        }

    }



    vector<long long> primes;

    for (long long i = 2; i <= limit; ++i) {

        if (prime[i]) {

            primes.push_back(i);

        }

    }

    

    return primes;

};

void merge(int arr[], int left, int right) {

    if (left >= right) return;

    int mid = left + (right - left) / 2;

    merge(arr, left, mid);

    merge(arr, mid + 1, right);

    

    int n1 = mid - left + 1;

    int n2 = right - mid;

    

    int L[n1], R[n2];

    for (int i = 0; i < n1; i++) L[i] = arr[left + i];

    for (int i = 0; i < n2; i++) R[i] = arr[mid + 1 + i];

    

    int i = 0, j = 0, k = left;

    while (i < n1 && j < n2) {

        if (L[i] <= R[j]) arr[k++] = L[i++];

        else arr[k++] = R[j++];

    }

    

    while (i < n1) arr[k++] = L[i++];

    while (j < n2) arr[k++] = R[j++];

};



void mergeSort(int arr[], int left, int right) {

    if (left < right) {

        int mid = left + (right - left) / 2;

        mergeSort(arr, left, mid);

        mergeSort(arr, mid + 1, right);

        merge(arr, left, right);

    }

};

struct item{

    ll m,c;

};

int count_trailing_zeros(ll n) {

    int count = 0;



    

    while ((n & 1) == 0 && n != 0) {

        count++;

        n >>= 1;  

    }



    return count;

}





int popcount(ll n) {

    int count = 0;

    

    

    while (n) {

        

        n = n & (n - 1);  

        count++;          

    }

    

    return count;

}







struct segTree {

    ll size;

    vll sums;



    void init(int n) {

        size = 1;

        while (size < n) {

            size *= 2;

        }

        sums.assign(2 * size, 0LL);

    }



    void set(ll i, ll v, ll x, ll lx, ll rx) {

        if (rx - lx == 1) {

            sums[x] = v;

            return;

        }

        ll m = (lx + rx) / 2;

        if (i < m) {

            set(i, v, 2 * x + 1, lx, m);

        } 

        else {

            set(i, v, 2 * x + 2, m, rx);

        }

        sums[x] = gcd(sums[2 * x + 1] , sums[2 * x + 2]);

    }



    void set(ll i, ll v) {

        set(i, v, 0, 0, size);

    }



    ll sum(ll l, ll r, ll x, ll lx, ll rx) {

        if (lx >= r || l >= rx) return 1e9;

        if (lx >= l && rx <= r) return sums[x];

        ll m = (lx + rx) / 2;

        ll s1 = sum(l, r, 2 * x + 1, lx, m);

        ll s2 = sum(l, r, 2 * x + 2, m, rx);

        return gcd(s1 , s2);

    }



    ll sum(ll l, ll r) {

        return sum(l, r, 0, 0, size);

    }

};

bool isPerfectPowerOf3(int n) {

    if (n <= 0) {

        return false;

    }

    while (n % 3 == 0) {

        n /= 3;

    }



    return n == 1;

}





int main() {

 

    #ifndef ONLINE_JUDGE

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

    freopen("output.txt", "w", stdout);

    #endif

    ll test_cases;

    cin>>test_cases;

    auto start = chrono::high_resolution_clock::now();



    f(j,0,test_cases){

        ll m,y,x,r1,maxi=0,k;bool change=true; bool sorted=false;ll sum=0;ll sum1=0;ll mini=1e9;

        long long n,d;

        cin>>n>>d>>k;

        vll vec_1(n);

        if(n%2==0){

            

            f(i,0,n){

                vec_1[i]=i%2;

            }

            if(vec_1[d-1]==vec_1[k-1]){

                if(d-1==0){

                    set<ll> i;

                    i.insert(vec_1[n-1]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

                else if(d-1!=n-1){

                    set<ll> i;

                    i.insert(vec_1[d-2]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

                else{

                    set<ll> i;

                    i.insert(vec_1[d-2]);

                    i.insert(vec_1[0]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

            }

        }

        else{

            f(i,0,n-1){

                vec_1[i]=i%2;

            }

            vec_1[n-1]=2;

            if(vec_1[d-1]==vec_1[k-1]){

                if(d-1==0){

                    set<ll> i;

                    i.insert(vec_1[n-1]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

                else{

                    set<ll> i;

                    i.insert(vec_1[d-2]);

                    i.insert(vec_1[d]);

                    i.insert(vec_1[k-1]);

                    f(z,0,4){

                        if(i.find(z)==i.end()){

                            vec_1[d-1]=z;

                            break;

                        }

                    }

                }

            }

        }

        if(d!=n && k!=n){

            set<ll> t;

            t.insert(vec_1[n-2]);

            t.insert(vec_1[0]);

            f(z,0,4){

                if(t.find(z)==t.end()){

                    vec_1[n-1]=z;

                    break;

                }

            }

        }

        else if(d==n){

            set<ll> t;

            t.insert(vec_1[n-2]);

            t.insert(vec_1[0]);

            t.insert(vec_1[k-1]);

            f(z,0,4){

                if(t.find(z)==t.end()){

                    vec_1[n-1]=z;

                    break;

                }

            }

        }

        else{

            set<ll> t;

            t.insert(vec_1[n-2]);

            t.insert(vec_1[0]);

            t.insert(vec_1[d-1]);

            f(z,0,4){

                if(t.find(z)==t.end()){

                    vec_1[n-1]=z;

                    break;

                }

            }

        }

        if(d-1==0){

            set<ll> i;

            i.insert(vec_1[n-1]);

            i.insert(vec_1[d]);

            i.insert(vec_1[k-1]);

            f(z,0,4){

                if(i.find(z)==i.end()){

                    vec_1[d-1]=z;

                    break;

                }

            }

        }

        else{

            set<ll> i;

            i.insert(vec_1[d-2]);

            i.insert(vec_1[d]);

            i.insert(vec_1[k-1]);

            f(z,0,4){

                if(i.find(z)==i.end()){

                    vec_1[d-1]=z;

                    break;

                }

            }

        }



        f(i,0,n){

            cout<<vec_1[i]<<" ";

        }

        cout<<endl;

    }

        

    

    auto end = chrono::high_resolution_clock::now();

    chrono::duration<double> duration = end - start;

    //cout << "Time taken: " << duration.count() << " seconds" << endl;

 

    return 0;

}