Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

using namespace std;



int main() {

    int t ;cin>>t; // You can modify t for multiple test cases

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;



        vector<int> a(n, 0); // Initialize with 0



        if (y==n) {

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

                a[i] = (i % 2 == 0) ? 0 : 1;

            }

            if (n % 2) {

                a[0] = 2;

            

            if (a[x - 1] == a[y - 1]) {

                if (a[x - 1] == 0) {

                    a[x - 1] = 2;

                    if (x == 3) {

                        a[x - 2] = 0;

                    }

                } else if (a[x - 1] == 1) {

                    a[y - 1] = 2;

                }

            }

        }

        else{

            if (a[x - 1] == a[y - 1]) {

            a[x-1] = 2;

            }

        }

        } else {

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

                a[i] = (i % 2 == 0) ? 0 : 1;

            }

            if (n % 2) {

                a[n - 1] = 2;

            

            if (a[x - 1] == a[y - 1]) {

                if (a[x - 1] == 0) {

                    a[y - 1] = 2;

                    if (y + 1 < n && a[y + 1] == 2) { // Avoid out-of-bounds access

                        a[y] = 0;

                        a[y+1] = 1;

                    }

                } else if (a[x - 1] == 1) {

                    a[x - 1] = 2;

                }

            }

        }else{

            if (a[x - 1] == a[y - 1]) {

            a[x-1] = 2;

            }

        }

        }



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

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

        }

        cout << endl;

    }



    return 0;

}



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

using namespace std;



int main() {

    int t ;cin>>t; // You can modify t for multiple test cases

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;



        vector<int> a(n, 0); // Initialize with 0



        if (y==n) {

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

                a[i] = (i % 2 == 0) ? 0 : 1;

            }

            if (n % 2) {

                a[0] = 2;

            

            if (a[x - 1] == a[y - 1]) {

                if (a[x - 1] == 0) {

                    a[x - 1] = 2;

                    if (x == 3) {

                        a[x - 2] = 0;

                        a[0] = 1;

                    }

                } else if (a[x - 1] == 1) {

                    a[y - 1] = 2;

                }

            }

        }

        else{

            if (a[x - 1] == a[y - 1]) {

            a[x-1] = 2;

            }

        }

        } else {

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

                a[i] = (i % 2 == 0) ? 0 : 1;

            }

            if (n % 2) {

                a[n - 1] = 2;

            

            if (a[x - 1] == a[y - 1]) {

                if (a[x - 1] == 0) {

                    a[y - 1] = 2;

                    if (y + 1 < n && a[y + 1] == 2) { // Avoid out-of-bounds access

                        a[y] = 0;

                        a[y+1] = 1;

                    }

                } else if (a[x - 1] == 1) {

                    a[x - 1] = 2;

                }

            }

        }else{

            if (a[x - 1] == a[y - 1]) {

            a[x-1] = 2;

            }

        }

        }



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

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

        }

        cout << endl;

    }



    return 0;

}