Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define close ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

void solved()
{
    int l, r;
    cin >> l >> r;
    bitset<30> right(r);
    bitset<30> left(l);
    bitset<30> ans;
    set<int>st;
    int maxNum = 0;
    for(int i = 0;i<30;i++)
    {
        if(right[i] == 1)
        {
            maxNum = i;
        }
    }
    for (int i = 0; i <= maxNum; i++) {
        if (right[i] == 1 && left[i] == 1) {
            ans[i] = 0;
        } 
        else if (right[i] == 0 && left[i] == 0) {
            ans[i] = 1;
        }
        else
        {
            st.insert(i);
        }
    }

    int k = ans.to_ulong();

    while(!(k != l && k != r && k >= l && k <= r)) 
    {
        if(st.empty())
        {
            break;
        }
        ans[*(st.begin())] = 1;
        st.erase(st.begin());
        k = ans.to_ulong();
    }
    cout<<l<<" "<<r<<" "<<k<<endl;
}

signed main()
{
    close;
    int T = 1;
    cin >> T;
    while (T--) {
        solved();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define close ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

void solved()
{
    int l, r;
    cin >> l >> r;
    bitset<30> right(r);
    bitset<30> left(l);
    bitset<30> ans;
    set<int>st;
    set<int>t1;
    priority_queue<int>t0;
    int maxNum = 0;
    for(int i = 0;i<30;i++)
    {
        if(right[i] == 1)
        {
            maxNum = i;
        }
    }
    for (int i = 0; i <= maxNum; i++) {
        if (right[i] == 1 && left[i] == 1) {
            ans[i] = 0;
            t1.insert(i);
        } 
        else if (right[i] == 0 && left[i] == 0) {
            ans[i] = 1;
            t0.push(i);
        }
        else
        {
            st.insert(i);
        }
    }
    int k = ans.to_ulong();
    int cnt = k;
    priority_queue<int>pq;
    while(!(k != l && k != r && k >= l && k <= r)) 
    {
        if(st.empty())
        {
            break;
        }
        ans[*(st.begin())] = 1;
        pq.push(*(st.begin()));
        st.erase(st.begin());
        k = ans.to_ulong();
    }
    while(!(k != l && k != r && k >= l && k <= r))
    {
        if(k>r)
        {
            if(pq.empty())
            {
                 if(t0.empty())
                 {
                    break;
                 }
                 else
                 {
                    int v = t0.top();
                    t0.pop();
                    ans[v] = 0;
                    k = ans.to_ulong();
                    continue;
                 }
            }
            else
            {
                int v = pq.top();
                pq.pop();
                ans[v] = 0;
                k = ans.to_ulong();
                continue;
            }
        }
        if(t1.empty())
        {
            break;
        }
        ans[*(t1.begin())] = 1;
        t1.erase(t1.begin());
        k = ans.to_ulong();
    }
    cout<<k<<" "<<l<<" "<<r<<endl;
}

signed main()
{
    close;
    int T = 1;
    cin >> T;
    //cerr<< 2 * (134+132+137) - 2 * (134 & 132) - 2 * (134 & 137) - 2 * (132 & 137)<<endl;;
    //cerr<< 2 * (128 + 137 + 134) - 2 *(128 & 134) - 2 * (128 & 134) - 2 * (137 & 134);
    while (T--) {
        solved();
    }
    return 0;
}