163132025-04-28 11:51:48lacitoXorcpp17Elfogadva 100/10035ms3052 KiB
#include <iostream>

using namespace std;

long long TT, L, R, tart, alap, x, y, z, xx, yy, zz, a, b, megy;
long long hat[61];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    hat[0] = 1;
    for(int i=1; i<=60; i++) hat[i] = hat[i-1]*2;

    cin >> TT;
    for(int ii=0; ii<TT; ii++){
        cin >> L >> R;
        tart = 59; alap = 0; x = 0; y = 0; z = 0;
        while((L&hat[tart])==(R&hat[tart])){
            if(L & hat[tart]){
                L ^= hat[tart]; R ^= hat[tart];
                alap ^= hat[tart];
            }
            tart--;
        }

        if(tart==1){
            if(L==0){
                x = 0; y = 1; z = 2;
            } else {
                x = 1; y = 2; z = 3;
            }
        } else {
            if(L & hat[tart-1]){
                if(R-L==2){
                    x = L; y = L+1; z = R;
                } else {
                    if(R-hat[tart]<=1){
                        x = -1;
                    } else {
                        megy = tart-1;
                        while(!(R & hat[megy])) megy--;
                        x = hat[tart]; y = ((hat[megy+1]-1)^R); z = R;
                        if(x==y) {y++; z--;}
                    }
                    if(L==hat[tart]-1){
                        xx = -1;
                    } else {
                        megy = tart-2;
                        while(L & hat[megy]) megy--;
                        xx = L; yy = ((hat[megy+1]-1)^L); zz = hat[tart];
                    }
                    if(x==-1 || (x^y^z)<(xx^yy^zz)){
                        x = xx; y = yy; z = zz;
                    }
                }
            } else {
                x = L; y = ((hat[tart]-1)^L); z = hat[tart];
            }
        }

        cout << (x^alap) << ' ' << (y^alap) << ' ' << (z^alap) << '\n';
    }

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/01ms316 KiB
2Elfogadva0/04ms548 KiB
3Elfogadva5/51ms316 KiB
4Elfogadva5/51ms316 KiB
5Elfogadva5/51ms316 KiB
6Elfogadva5/51ms316 KiB
7Elfogadva5/52ms508 KiB
8Elfogadva5/53ms564 KiB
9Elfogadva5/53ms564 KiB
10Elfogadva5/54ms652 KiB
11Elfogadva5/58ms872 KiB
12Elfogadva5/58ms904 KiB
13Elfogadva5/514ms1332 KiB
14Elfogadva6/621ms1992 KiB
15Elfogadva6/628ms2276 KiB
16Elfogadva6/635ms2872 KiB
17Elfogadva6/635ms3052 KiB
18Elfogadva7/74ms600 KiB
19Elfogadva7/735ms2916 KiB
20Elfogadva7/735ms2860 KiB