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

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define sz(x) (ll)x.size()

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

#define ld long double

 

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}



bool s(pair <string,ll> a, pair <string,ll> b)

{

    return a.second>b.second;

}

 

void fun()

{

    lc(n);

    lc(x);

    lc(y);

    vll a(n,0);

    x--, y--;

    if ( n%2==0 )

    {

        for (ll i=0; i<n; i+=2) a[i] = 1;

        if ( a[x]==0 && a[y]==0 ) a[x] = 2;

        else if ( a[x]==1 && a[y]==1 ) a[x] = 2;

        fout(i,n,a);

        cout << endl;

        return;

    }

    else

    {

        for (ll i=0; i<n-2; i+=2) a[i] = 1;

        a[n-1] = 2;

        if ( a[x]==0 && a[y]==0 )

        {

            a[y] = 2;

            if ( a[y+1]==2 ) a[y+2] = 0;

        }

        else if ( a[x]==1 && a[y]==1 ) a[y] = 2;

        fout(i,n,a);

        cout << endl;

        return;

    }

    return;

}

 

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}

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

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define sz(x) (ll)x.size()

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

#define ld long double

 

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}



bool s(pair <string,ll> a, pair <string,ll> b)

{

    return a.second>b.second;

}

 

void fun()

{

    lc(n);

    lc(x);

    lc(y);

    x--, y--;

    if ( n%2==0 )

    {

        f(i,0,n)

        {

            if ( i==x && (x%2)==(y%2) ) cout << "2 ";

            else cout << (i+1)%2 << ' ';

        }

        cout << endl;

        return;

    }

    else

    {

        f(i,0,n)

        {

            if ( i==y && (x%2)==(y%2) )

            {

                cout << "2 ";

                if ( y==(n-2) )

                {

                    cout << "0 ";

                    break;

                }

            }

            else cout << (i+1)%2 << ' ';

        }

        cout << endl;

        return;

    }

    return;

}

 

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}