Problem: 2049C - MEX Cycle
Language: c++17 

Code 1:
#pragma GCC optimize("Ofast")

 

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#include <chrono>

#define pb push_back

#define INF 0x3f3f3f3f

#define LINF 0x3f3f3f3f3f3f3f3f

#define endl '\n'

#define ll long long

#define f first

#define fin cin

#define fout cout

#define s second

#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)

#define debug(x) cout << "DEBUG " << x << endl

#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl

#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl

#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl

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

#define left esquerda

#define lb lower_bound

#define right direita

using namespace std;

using namespace __gnu_pbds;

 

void setIO(string s) {

ios_base::sync_with_stdio(0); cin.tie(0);

freopen((s+".in").c_str(),"r",stdin);

freopen((s+".out").c_str( ),"w",stdout);

}

typedef pair<int, ll> pii;

typedef vector<vector<char>> mat;

typedef pair<int, string> pis;

const ll mod = 1e9 + 7, MAXN = 2e5 + 5;

typedef vector<int> vi;

typedef pair<int, pair<int, int>> piii;

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();

struct chash {

    int operator()(int x) const { return x ^ RANDOM; }

};



 

void solve() {

    int n, x, y;

    cin >> n >> x >> y;



    x--, y--;



    vector<int> v(n);

    v[n - 1] = 1;

    v[1] = 1;





    if(!x && y != 1 && y != n - 1)

        v[y] = 1;



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

        if(v[i] == v[i + 1])

            v[i + 1]++;

        if(x == i && v[x] == v[y])

            v[y]++;

    }



    for(int &i : v)

        cout << i << " ";

    cout << endl;

}



 

int32_t main() {

    int ct = 1;

    cin >> ct;

    while(ct--)

        solve();

}

Code 2:
#pragma GCC optimize("Ofast")

 

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#include <chrono>

#define pb push_back

#define INF 0x3f3f3f3f

#define LINF 0x3f3f3f3f3f3f3f3f

#define endl '\n'

#define ll long long

#define f first

#define fin cin

#define fout cout

#define s second

#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)

#define debug(x) cout << "DEBUG " << x << endl

#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl

#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl

#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl

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

#define left esquerda

#define lb lower_bound

#define right direita

using namespace std;

using namespace __gnu_pbds;

 

void setIO(string s) {

ios_base::sync_with_stdio(0); cin.tie(0);

freopen((s+".in").c_str(),"r",stdin);

freopen((s+".out").c_str( ),"w",stdout);

}

typedef pair<int, ll> pii;

typedef vector<vector<char>> mat;

typedef pair<int, string> pis;

const ll mod = 1e9 + 7, MAXN = 2e5 + 5;

typedef vector<int> vi;

typedef pair<int, pair<int, int>> piii;

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();

struct chash {

    int operator()(int x) const { return x ^ RANDOM; }

};



 

void solve() {

    int n, x, y;

    cin >> n >> x >> y;



    x--, y--;



    vector<int> v(n);



    priority_queue<pii, vector<pii>, greater<pii>> fila;

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

        fila.push({0, i});

    

    while(!fila.empty()) {

        pii aux = fila.top();

        fila.pop();



        if(v[aux.s] != aux.f)

            continue; 

        

        int viz = (aux.s ? aux.s - 1 : n - 1);

        int viz2 = (aux.s + 1 < n ? aux.s + 1 : 0);

        

        vector<int> vl = {viz, viz2};

        if(aux.s == x)

            vl.pb(y);

        if(aux.s == y)

            vl.pb(x);



        for(int &i : vl) 

            if(aux.f == v[i]) {

                fila.push({aux.f + 1, i});

                v[i] = aux.f + 1;

            }

        

    

    

    }

    

    for(int &i : v)

        cout << i << " ";

    cout << endl;

}



 

int32_t main() {

    int ct = 1;

    cin >> ct;

    while(ct--)

        solve();

}

Answer: 2