460D - Little Victor and Set - CodeForces Solution


brute force constructive algorithms math *2300

Please click on ads to support us..

C++ Code:

#include <random>
#include <bits/stdc++.h>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define ite(i,arr) for(auto &i:arr)
#define MID(l,r) int mid=(l+r)>>1
#define ALL(arr) arr.begin(),arr.end()
#define AXY(a,x,y) int x=a.first,y=a.second
#define vc vector
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define endl '\n'
#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt
#define __builtin_popcountll __popcnt
#define __builtin_popcountlll __popcnt
typedef long long  ll;
using namespace std;

namespace Geo {
	const double eps = 1e-8;
	const double P = acos(-1);
	struct Point {
		double x, y;
		Point() {
			x = 0, y = 0;
		}
		Point(double x, double y) {
			this->x = x;
			this->y = y;
		}
	};
	Point operator +(Point a, Point b) {
		return Point(a.x + b.x, a.y + b.y);
	}
	Point operator -(Point a, Point b) {
		return Point(a.x - b.x, a.y - b.y);
	}
	Point operator *(double a, Point b) {
		return Point(a * b.x, a * b.y);
	}
	Point operator *(Point b, double a) {
		return Point(a * b.x, a * b.y);
	}
	Point operator /(Point b, double a) {
		return Point(b.x / a, b.y / a);
	}
	double len(Point a) {
		return sqrt(a.x * a.x + a.y * a.y);
	}
	double dis(Point a, Point b) {
		return len(a - b);
	}
	bool operator ==(Point a, Point b) {
		return dis(a, b) <= eps;
	}
	bool operator !=(Point a, Point b) {
		return !(a == b);
	}
	double operator *(Point a, Point b) {
		return a.x * b.x + a.y * b.y;
	}

	double operator ^(Point a, Point b) {
		return a.x * b.y - a.y * b.x;
	}

	double getAngel(double b, double a, double c) {
		return acos((a * a + c * c - b * b) / (2 * a * c));
	}
	double getAngel(Point a, Point b) {
		return acos(a * b / len(a) / len(b));
	}
}

#define int ll
signed mod = 1e9 + 9;
ll ADD(ll a, ll b) {
	ll res = 0;
	res += a;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	res += b;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	return res;
}
ll ADD(ll a, ll b, ll c) {
	ll res = 0;
	res += a;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	res += b;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	res += c;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	return res;
}
ll ADD(ll a, ll b, ll c, ll d) {
	ll res = 0;
	res += a;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	res += b;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	res += c;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	res += d;
	if (res >= mod) res -= mod;
	else if (res < 0) res += mod;
	return res;
}
inline ll lowbit(ll b) { return b & (-b); }
inline ll qmi(ll a, ll b) {
	if (b == -1) return qmi(a, mod - 2);
	a %= mod;
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
ll inv(ll b) {
	return qmi(b, mod - 2);
}
const ll N = 1e6 + 10;
ll invArr[N];
ll fact[(ll)N + 5];
ll inv_fact[(ll)N + 5];


int prime[(int)N + 5];
int valid[(int)N + 5];
int pn = 0;
//int phi[N];
//int mu[N];
int sigma0[N];//因子个数
int e0[N];//最小因子的个数
//int sigma1[N];//约数和
//int e1[N];//g[i] 表示 i 的最小质因子的 p^0+p^1+p^2+..+p^k.
inline void sieve() {
	//phi[1] = 1;
	sigma0[1] = 1;
	e0[1] = 1;
	//e1[1] = 1;
	//sigma1[1]=1;
	//mu[1] = 1;
	rep(i, 2, N) {
		if (!valid[i]) {
			valid[i] = i;
			prime[pn++] = i;
			//phi[i] = i - 1;

			sigma0[i] = 2;
			e0[i] = 1;

			//e1[i]=i+1;
			//sigma1[i]=i+1;

			//mu[i] = -1;
		}
		for (int j = 0; j < pn && i * prime[j] < N; j++) {
			valid[i * prime[j]] = prime[j];
			if (i % prime[j] == 0) {
				//phi[i * prime[j]] = phi[i] * prime[j];

				e0[i * prime[j]] = e0[i] + 1;
				sigma0[i * prime[j]] = sigma0[i] / (e0[i] + 1) * (e0[i] + 2);

				//e1[i*prime[j]]=e1[i]*prime[j]+1;
				//sigma1[i*prime[j]]=sigma1[i]/e1[i]*e1[i*prime[j]];
				//mu[i * prime[j]] = 0;
				break;
			}
			else {
				//phi[i * prime[j]] = phi[i] * phi[prime[j]];

				e0[i * prime[j]] = 1;
				sigma0[i * prime[j]] = sigma0[i] * sigma0[prime[j]];

				//e1[i*prime[j]]=prime[j]+1;
				//sigma1[i*prime[j]]=sigma1[i]*sigma1[prime[j]];
				//mu[i * prime[j]] = mu[i] * mu[prime[j]];
			}
		}
	}
}
void getInvArr() {
	invArr[1] = 1;
	rep(i, 2, N) {
		invArr[i] = invArr[mod % i] * (mod - mod / i) % mod;
	}
}
inline void getFact() {
	fact[0] = fact[1] = 1;
	for (ll i = 2; i <= N; i++) {
		fact[i] = i * fact[i - 1] % mod;
	}
}
inline void getInv() {
	inv_fact[N] = inv(fact[N]);
	for (ll i = N - 1; i >= 0; i--) {
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod;
	}
}
inline ll C(ll n, ll m) {
	if (n < 0 || m < 0 || n < m) {
		return 0;
	}
	if (n == m && n == 0) {
		return 1;
	}
	ll res = fact[n] * inv_fact[m] % mod * inv_fact[n - m] % mod;
	return res;
}
ll read() {
	ll x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch>'9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
void write(int x)
{
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}

//125970
int f[N];

int l, r;

void func(int k) {
	if (k >= 4) {
		if (l % 2 == 0 || l + 4 <= r) {
			l += l % 2;
			cout << "0\n4\n" << l << ' ' << l + 1 << ' ' << l + 2 << ' ' << l + 3 << endl;
		}
		else{
			func(3);
		}
	}
	else if (k == 3) {
		int dig = log2(l);
		int mid = (1ll << dig + 1) + (1ll << dig);
		int num = mid ^ l;
	


		if (num<=r&&mid<=r) {

			cout << (num^mid^l) << endl;
			cout << 3 << endl;
			cout << num << ' ' << mid << ' ' << l << endl;
		}
		else {
			
			func(2);
			
		}

	}
	else if (k == 2) {

		if (l % 2 == 0 || (l + 2) <= r) {
			l += l % 2;
			cout << "1\n2\n" << l << ' ' << l + 1 << endl;
		}
		else if(l>(l^(l+1))){
			cout <<(l^(l+1))<< "\n2\n" << l << ' ' << l + 1 << endl;
		}
		else {
			func(1);
		}

	}
	else {
		cout << l << endl;
		cout << 1 << endl;
		cout << l << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> l >> r;
	int k;
	cin >> k;
	k = min(k, r - l + 1);
	func(k);
}


/*
6
0 0 1
0 1 0
0 0 0
0 0 2
0 0 3
0 2 0



*/


Comments

Submit
0 Comments
More Questions

Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses