Codeforces 460D Little Victor and Set(看题解)

Posted cjlhy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 460D Little Victor and Set(看题解)相关的知识,希望对你有一定的参考价值。

Little Victor and Set

其他都很好求, 只有k == 3的时候很难受。。

我们找到第一个不大于l的 t, 答案为 l, 3 * t, (3 * t) ^ l

感觉好像是对的, 感觉又不会证明, 啊, 我好菜啊。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 5e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);

LL l, r, k;

void print(LL x, int cnt) {
    if(!cnt) return;
    print(x / 2, cnt - 1);
    printf("%d", x & 1);
}

int main() {
    scanf("%lld%lld%lld", &l, &r, &k);
    LL n = r - l + 1;
    if(k == 1) {
        printf("%lld
", l);
        puts("1");
        printf("%lld
", l);
    } else if(k == 2) {
        if(n == 2) {
            if(l < (l ^ r)) {
                printf("%lld
", l);
                puts("1");
                printf("%lld
", l);
            } else {
                printf("%lld
", l ^ r);
                puts("2");
                printf("%lld %lld
", l, r);
            }
        } else {
            if(l & 1) {
                printf("%lld
", (l + 1) ^ (l + 2));
                puts("2");
                printf("%lld %lld
", (l + 1), (l + 2));
            } else {
                printf("%lld
", l ^ (l + 1));
                puts("2");
                printf("%lld %lld
", l, (l + 1));
            }
        }
    } else if(k == 3) {
        LL t = 1;
        while(t * 2 <= l) t *= 2;
        if(t * 3 <= r) {
            puts("0");
            puts("3");
            printf("%lld %lld %lld
", l, 3 * t, (3 * t) ^ l);
        } else {
            puts("1");
            puts("2");
            if(l & 1) printf("%lld %lld
", l + 1, l + 2);
            else printf("%lld %lld
", l, l + 1);
        }
    } else {
        if(l & 1) {
            if(n >= 5) {
                puts("0");
                puts("4");
                for(LL i = l + 1; i < l + 5; i++)
                    printf("%lld ", i);
                puts("");
            } else {
                for(int S = 1; S < (1 << n); S++) {
                    vector<LL> vc;
                    LL val = 0;
                    for(int i = 0; i < n; i++)
                        if(S >> i & 1) val ^= l + i, vc.push_back(l + i);
                    if(!val) {
                        puts("0");
                        printf("%d
", SZ(vc));
                        for(auto& t : vc) printf("%lld ", t);
                        puts("");
                        return 0;
                    }
                }
                puts("1");
                puts("2");
                printf("%lld %lld
", l + 1, l + 2);
            }
        } else {
            puts("0");
            puts("4");
            for(LL i = l; i < l + 4; i++)
                printf("%lld ", i);
            puts("");
        }
    }
    return 0;
}

/*
*/

 

以上是关于Codeforces 460D Little Victor and Set(看题解)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 220B - Little Elephant and Array 离线树状数组

[CodeForces-259C] Little Elephant and Bits

『题解』Codeforces220B Little Elephant and Array

Little Girl and Maximum XOR CodeForces - 276D

Little Girl and Maximum Sum CodeForces - 276C

CodeForces - 258D Little Elephant and Broken Sorting