Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
// || =================================================================== ||

// ||                                                                     ||

// ||                   Reach Expert by May 2025                          ||

// ||                                                                     ||

// || =================================================================== ||

#include <bits/stdc++.h>

#define int long long

#define endl "\n";

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

#define ONLINE_JUDGE  

using namespace std;

long long mod_exp(long long base, long long exp, long long mod) {

    long long result = 1;

    while (exp > 0) {

        if (exp % 2 == 1) {

            result = (result * base) % mod;     

        }

        base = (base * base) % mod; 

        exp /= 2; 

    }

    return result;

}

int m(set<int> arr){

	int st = 0;

	for(auto i : arr){

		if(i == st){

			// then do nothing

		}else{

			return st;

		}

		st++;

	}

	return st;

}

void solve() {

    int n, x, y;

	cin >> n >> x >> y;

	// vector<set<int>> f(n + 1);

	vector<int> ans(n + 1);

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

		if(i & 1)ans[i] = 0;

		else ans[i] = 1;

	}

	if((x + y) & 1){

		// i think it does not matter in case of even n is even only

		if(n % 2 == 0){

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

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

			}

			cout << endl;

		}else{

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

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

			}

			ans[n] = 2;

			cout << 2;

			cout << endl;

		}

	}else{

		// same number having people are friends

		// so one among them need to have 2 as ans[]

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

			if(i == x){

				cout << 2 << " ";

				ans[i] = 2;

			}else {

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

			}

		}

		cout << endl;

	}

	//validation

	vector<set<int>> f(n + 1);

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

		int nxt = i + 1;

		int prev = i - 1;

		if(nxt == n + 1) nxt = 1;

		if(prev == 0) prev = n;

		f[i].insert(nxt);

		f[i].insert(prev);

	}

	f[x].insert(y);

	f[y].insert(x);



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

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

	// cout << endl;

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

		set<int> friendsMx;

		// cout << "friends of " << i << " : " ;

		for(auto j : f[i]){

			// cout << j << " , " << ans[j] << " ; ";

			friendsMx.insert(ans[j]);

		}

		// cout << endl;

		// cout << "M value for " << i << " is " << m(friendsMx) << endl;

		// cout << "Ans value for " << i << " is " << ans[i] << endl;

		int m_val = m(friendsMx);

		if(m_val != ans[i]){

			cout << "wrong for " << i << endl;

		}

	}







}





signed main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    #ifndef ONLINE_JUDGE 

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

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

    #endif  

    int t;

    cin >> t;

    while(t--)

        solve();

   

} 



/*

void solve() {

    int n, k;

    cin >> n >> k;

    int r = n, l  =1;

	stack<pair<int,int>> st;

	st.push({l, r});

	int ans =0LL;

	while(st.size()){

		auto p = st.top();

		st.pop();

		int curL = p.first;

		int curR = p.second;

		if(curR - curL + 1 < k){

			// do nothing

		}else{

			int sz = curR - curL + 1;

			if(sz & 1){

				int m = (curL + curR) / 2LL;

				ans += m;

				cout << "{" << curL << " , " << curR << "} : " << m << endl;

				st.push({curL, m - 1LL});

				st.push({m + 1LL , curR});

			}else{

				int m = (curL + curR) / 2LL;

				st.push({curL, m});

				st.push({m + 1LL , curR});

			}

		}

	}

	cout << ans << endl;

}

 */

Submission (verdict: Accepted):
// || =================================================================== ||

// ||                                                                     ||

// ||                   Reach Expert by May 2025                          ||

// ||                                                                     ||

// || =================================================================== ||

#include <bits/stdc++.h>

#define int long long

#define endl "\n";

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

#define ONLINE_JUDGE  

using namespace std;

long long mod_exp(long long base, long long exp, long long mod) {

    long long result = 1;

    while (exp > 0) {

        if (exp % 2 == 1) {

            result = (result * base) % mod;     

        }

        base = (base * base) % mod; 

        exp /= 2; 

    }

    return result;

}

int m(set<int> arr){

	int st = 0;

	for(auto i : arr){

		if(i == st){

			// then do nothing

		}else{

			return st;

		}

		st++;

	}

	return st;

}

void solve() {

    int n, x, y;

	cin >> n >> x >> y;

	// vector<set<int>> f(n + 1);

	vector<int> ans(n + 1);

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

		if(i & 1)ans[i] = 0;

		else ans[i] = 1;

	}

	if((x + y) & 1){

		// i think it does not matter in case of even n is even only

		if(n % 2 == 0){

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

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

			}

			cout << endl;

		}else{

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

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

			}

			ans[n] = 2;

			cout << 2;

			cout << endl;

		}

	}else{

		// same number having people are friends

		// so one among them need to have 2 as ans[]

		if(n % 2 == 0){

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

				if(i == x){

					cout << 2 << " ";

					ans[i] = 2;

				}else {

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

				}

			}

			cout << endl;

		}else{

			ans[x] = 2;

			int idx = x - 1;

			if(idx == 0) idx = n;

			int cnt = 1;

			int val = 0;

			while(cnt < n){

				ans[idx] = val;

				val = !val;

				cnt++;

				idx--;

				if(idx == 0) idx = n;

			}

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

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

			}

			cout << endl;

		}

	}

	//validation

	vector<set<int>> f(n + 1);

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

		int nxt = i + 1;

		int prev = i - 1;

		if(nxt == n + 1) nxt = 1;

		if(prev == 0) prev = n;

		f[i].insert(nxt);

		f[i].insert(prev);

	}

	f[x].insert(y);

	f[y].insert(x);



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

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

	// cout << endl;

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

		set<int> friendsMx;

		// cout << "friends of " << i << " : " ;

		for(auto j : f[i]){

			// cout << j << " , " << ans[j] << " ; ";

			friendsMx.insert(ans[j]);

		}

		// cout << endl;

		// cout << "M value for " << i << " is " << m(friendsMx) << endl;

		// cout << "Ans value for " << i << " is " << ans[i] << endl;

		int m_val = m(friendsMx);

		if(m_val != ans[i]){

			cout << "wrong for " << i << endl;

		}

	}







}





signed main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    #ifndef ONLINE_JUDGE 

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

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

    #endif  

    int t;

    cin >> t;

    while(t--)

        solve();

   

} 



/*

void solve() {

    int n, k;

    cin >> n >> k;

    int r = n, l  =1;

	stack<pair<int,int>> st;

	st.push({l, r});

	int ans =0LL;

	while(st.size()){

		auto p = st.top();

		st.pop();

		int curL = p.first;

		int curR = p.second;

		if(curR - curL + 1 < k){

			// do nothing

		}else{

			int sz = curR - curL + 1;

			if(sz & 1){

				int m = (curL + curR) / 2LL;

				ans += m;

				cout << "{" << curL << " , " << curR << "} : " << m << endl;

				st.push({curL, m - 1LL});

				st.push({m + 1LL , curR});

			}else{

				int m = (curL + curR) / 2LL;

				st.push({curL, m});

				st.push({m + 1LL , curR});

			}

		}

	}

	cout << ans << endl;

}

 */