Codeforces 460 D. Little Victor and set

Source: Internet
Author: User


Violence + Construction


IfR? -?L? ≤? 4 we can all subsets of size not greaterK. Else, ifK? =? 1, obviously that answer isL. IfK? =? 2, answer is 1, becauseXOROf numbers 2XAnd 2X? +? 1 equls 1. IfK? ≥? 4 answer is 0 becauseXOROf to PairsXOR1 is 0.

IfK? =? 3, we can choose numbers 2XAnd 2X? +? 1XOR1. So we need to know, if we can getXOREquals 0. Suppose that there are 3 such numbersX,YAndZ(R? ≥?X?>?Y?>?Z? ≥?L)XOREquals 0. Consider the most non-zero bit of numberX. At the same bitYIt's also 1, becauseXOREquls 0, andY?>?Z. Consider the next bit of numbers. IfZHave 0 there, we have to do next: Set the previous bit of numbersXAndYEquals 0, and set current bit equals 1. obviuslyXORStill equals 0,ZHadn't changed and numbersXAndYStood closerZ, So they are still [L,?R]. AndX?>?Y. Consider the next bit of numbers. IfZHas zero here than we will change most bitsXBytesYAt the same way and so on.Z?>? 0, so Somewhen we will get to bit in whichZHas 1. SinceXOREquals 0, the same bitXWocould be 1 becauseX?>?Y, AndYWocould have 0 there. At the next bits we will change bit inXTo 0, and in numbersYAndZTo 1. FinallyZWocould be greater or equal than before, andXWocould be less or greater than before, andX?>?Y?>?ZWocould be correct. So, we have the next: if such numbersX,YAndZExist than also exist numbers:

1100... 000

1011... 111

0111... 111

WithXOREquals 0. There are not much such triples, so we can check them.


D. Little Victor and settime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of IntegersSThat has the following properties:

  • For allXThe following inequality holdsL? ≤?X? ≤?R;
  • 1? ≤? |S|? ≤?K;
  • Lets denoteI-Th element of the SetSAsSI; Value must be as small as possible.

Help Victor find the described set.

Input

The first line contains three space-separated IntegersL,?R,?K(1? ≤?L? ≤?R? ≤? 1012; 1? ≤?K? ≤?Min(106 ,?R? -?L? +? 1 )).

Output

Print the minimum possible valueF(S). Then print the cardinality of set |S|. Then print the elements of the Set in any order.

If there are multiple optimal sets, you can print any of them.

Sample test (s) Input
8 15 3
Output
1210 11
Input
8 30 7
Output
0514 9 28 11 16
Note

Operation represents the operation of bitwise exclusive or. In other words, it is the XOR operation.





#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long int LL;LL L,R,K;LL ans=0x3f3f3f3f3f3f3f3f;int main(){    cin>>L>>R>>K;    if(R-L+1<=4)    {        LL m=R-L+1;        LL sig=0;        for(LL i=1;i<(1LL<<m);i++)        {            LL temp=0;            LL wei=0;            LL si=i;            while(si)            {                wei++;                si=si&(si-1);            }            if(wei>K) continue;            for(LL j=0;j<m;j++)            {                if(i&(1LL<<j))                {                    temp^=L+j;                }            }            if(temp<ans)            {                ans=temp;                sig=i;            }        }        cout<<ans<<endl;        LL wei=0;        LL tsig=sig;        while(tsig)        {            wei++;            tsig=tsig&(tsig-1);        }        cout<<wei<<endl;        for(LL i=0;i<m;i++)        {            if(sig&(1<<i))            {                cout<<L+i<<" ";            }        }        cout<<endl;    }    else    {        if(K==1)        {            cout<<L<<endl;            cout<<1<<endl;            cout<<L<<endl;        }        else if(K==2)        {            if(L%2) L++;            cout<<1<<endl;            cout<<2<<endl;            cout<<L<<" "<<L+1<<endl;        }        else if(K==3)        {            bool flag=false;            LL mx=3,mi=1;            while(mx<=R)            {                if(mi>=L)                {                    flag=true;                    cout<<0<<endl<<3<<endl;                    cout<<mx<<" "<<mx-1<<" "<<mi<<endl;                    break;                }                mx<<=1LL;                mi<<=1LL; mi++;            }            if(flag==false)            {                if(L%2) L++;                cout<<1<<endl;                cout<<2<<endl;                cout<<L<<" "<<L+1<<endl;            }        }        else        {            cout<<0<<endl;            cout<<4<<endl;            if(L%2) L++;            cout<<L<<" "<<L+1<<" "<<L+2<<" "<<L+3<<endl;        }    }    return 0;}


Codeforces 460 D. Little Victor and set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.