1. 程式人生 > >Codeforces 460D Little Victor and Set(看題解)

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

def 難受 name else lld href esp 第一個 bsp

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\n", l); puts("1"); printf("%lld\n", l); }
else if(k == 2) { if(n == 2) { if(l < (l ^ r)) { printf("%lld\n", l); puts("1"); printf("%lld\n", l); } else { printf("%lld\n", l ^ r); puts("2"); printf("%lld %lld\n", l, r); } } else { if(l & 1) { printf("%lld\n", (l + 1) ^ (l + 2)); puts("2"); printf("%lld %lld\n", (l + 1), (l + 2)); } else { printf("%lld\n", l ^ (l + 1)); puts("2"); printf("%lld %lld\n", 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\n", l, 3 * t, (3 * t) ^ l); } else { puts("1"); puts("2"); if(l & 1) printf("%lld %lld\n", l + 1, l + 2); else printf("%lld %lld\n", 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\n", SZ(vc)); for(auto& t : vc) printf("%lld ", t); puts(""); return 0; } } puts("1"); puts("2"); printf("%lld %lld\n", 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(看題解)