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

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

using namespace std;

const int MOD = 998244353;

#define int long long

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



int mex(vector<int> arr)

{

    int N = arr.size();

    sort(arr.begin(), arr.end());

    int mex = 0;

    for (int idx = 0; idx < N; idx++)

    {

        if (arr[idx] == mex)

        {

            mex += 1;

        }

    }

    return mex;

}

void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    int secondOccur = max(x, y)-1;

    int firstOccur = min(x, y)-1;

    vector<int> ans(n, -1);

    loop(i, n - 1, 1)

    {

        if (i == 0)

        {

            ans[i] = 0;

            continue;

        }

        if (i == secondOccur)

        {

            ans[i] = mex({ans[i - 1], ans[firstOccur]});

            continue;

        }

        if (ans[i - 1] == 0 || ans[i - 1] == 2)

        {

            ans[i] = 1;

        }

        else if (ans[i - 1] == 1)

        {

            ans[i] = 0;

        }

    }

    if (secondOccur == n - 1)

    {

        ans[n - 1] = mex({ans[0], ans[firstOccur], ans[n - 2]});

    }

    else

    {

        ans[n - 1] = mex({ans[0], ans[n - 2]});

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}



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

using namespace std;

const int MOD = 998244353;

#define int long long

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



int mex(vector<int> arr)

{

    int N = arr.size();

    sort(arr.begin(), arr.end());

    int mex = 0;

    for (int idx = 0; idx < N; idx++)

    {

        if (arr[idx] == mex)

        {

            mex += 1;

        }

    }

    return mex;

}

void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    int secondOccur = max(x, y) - 1;

    int firstOccur = min(x, y) - 1;

    vector<int> ans(n, -1);

    loop(i, n - 1, 1)

    {

        if (i == 0)

        {

            ans[i] = 0;

            continue;

        }

        if (i == secondOccur && i - 1 != firstOccur)

        {

            ans[i] = mex({ans[i - 1], ans[firstOccur]});

            continue;

        }

        if (ans[i - 1] == 0)

        {

            ans[i] = 1;

        }

        else if (ans[i - 1] == 2)

        {

            ans[i] = mex({ans[i - 1], ans[i - 2]});

        }

        else if (ans[i - 1] == 1)

        {

            ans[i] = 0;

        }

    }

    if (secondOccur == n - 1)

    {

        ans[n - 1] = mex({ans[0], ans[firstOccur], ans[n - 2]});

    }

    else

    {

        ans[n - 1] = mex({ans[0], ans[n - 2]});

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}