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

Code 1:
#include <bits/stdc++.h>

using namespace std;

#define int long long



void build(vector<int> &segtree, vector<int> &arr, int v, int l, int r) {

    if (l == r) {

        segtree[v]=arr[l];

    } else {

        int mid = (l + r) / 2;

        build(segtree, arr, 2 * v, l, mid);

        build(segtree, arr, 2 * v + 1, mid + 1, r);

        segtree[v] = gcd(segtree[2 * v], segtree[2 * v + 1]);

    }

}

 



 

int query(vector<int> &segtree, vector<int> &arr, int v, int l, int r, int l1, int r1) {

    if (r1 < l || r < l1) {

        return 0;

    } else if (l >= l1 && r <= r1) {

        return segtree[v];

    } else {

        int mid = (l + r) / 2;

        int a = query(segtree, arr, 2 * v, l, mid, l1, r1);

        int b = query(segtree, arr, 2 * v + 1, mid + 1, r, l1, r1);

        return gcd(a, b);

    }

}



int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while (t--) {

      int n,x,y;

      cin>>n>>x>>y;

      x--; y--;

      vector<int> arr(n);



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

      {

        if(i%2==0)

            arr[i]=0;

        else arr[i]=1;

      }



      if(n%2==1)

      {

        arr[n-1]=2;

      }



      if(arr[x]==arr[y])

      {

        arr[y]=2;

        if(arr[x]==0)

        {

            // cout<<y+1<<endl;

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

            {

                if((y+1-i) % 2==0)

                    arr[i]=0;

                else

                    arr[i]=1;

            }

            if(arr[n-1]==0 )

            {

                if(arr[n-2]==1)

                    arr[n-1]=2;

                else if(arr[n-2]==2)

                    arr[n-1]=1;

            }

        }

      }





       for(auto x:arr)

       {

        cout<<x<<" ";

       }

       cout<<endl;

    }

    return 0;

}



Code 2:
#include <bits/stdc++.h>

using namespace std;

#define int long long



void build(vector<int> &segtree, vector<int> &arr, int v, int l, int r) {

    if (l == r) {

        segtree[v]=arr[l];

    } else {

        int mid = (l + r) / 2;

        build(segtree, arr, 2 * v, l, mid);

        build(segtree, arr, 2 * v + 1, mid + 1, r);

        segtree[v] = gcd(segtree[2 * v], segtree[2 * v + 1]);

    }

}

 



 

int query(vector<int> &segtree, vector<int> &arr, int v, int l, int r, int l1, int r1) {

    if (r1 < l || r < l1) {

        return 0;

    } else if (l >= l1 && r <= r1) {

        return segtree[v];

    } else {

        int mid = (l + r) / 2;

        int a = query(segtree, arr, 2 * v, l, mid, l1, r1);

        int b = query(segtree, arr, 2 * v + 1, mid + 1, r, l1, r1);

        return gcd(a, b);

    }

}



int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while (t--) {

      int n,x,y;

      cin>>n>>x>>y;

      x--; y--;

      vector<int> arr(n);



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

      {

        if(i%2==0)

            arr[i]=0;

        else arr[i]=1;

      }



      if(n%2==1)

      {

        arr[n-1]=2;

      }



      if(arr[x]==arr[y])

      {

        arr[y]=2;

        if(arr[x]==0)

        {

            // cout<<y+1<<endl;

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

            {

                if((y+1-i) % 2==0)

                    arr[i]=0;

                else

                    arr[i]=1;

            }

            if(arr[n-1]==0 )

            {

                if(arr[n-2]==1)

                    arr[n-1]=2;

                else if(arr[n-2]==2)

                    arr[n-1]=1;

            }

        }

        else

        {

            if(arr[n-2]==2 && arr[n-1]==2)

                arr[n-1]=1;





        }

      }





       for(auto x:arr)

       {

        cout<<x<<" ";

       }

       cout<<endl;

    }

    return 0;

}



Answer: 2