Language: C++


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-all-loops")
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long int LL;

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

int N;
LL Ans;

struct node
{
	LL l, r;
	void give(LL _l, LL _r)
	{
		l = _l, r = _r;
	}
};
int tot;
node v[3];

void dfs(int p, int cnt, LL l, LL r)
{
	if (p == tot)
	{
		if (cnt)
			if (cnt & 1)
			{
				if (l <= r)
					Ans += r - l + 1LL;
			}
			else
			{
				if (l <= r)
					Ans -= r - l + 1LL;
			}
		return ;
	}
	dfs(p + 1, cnt, l, r);
	dfs(p + 1, cnt + 1, max(l, v[p].l), min(r, v[p].r));
}

int main()
{
	gi(L), gi(R);
	if (N == 1 || L == R)
		Ans = (R - L + 1LL) % MOD;
	else
	{
		for (k = 59LL;k >= 0LL;--k)
			if ((L & (1LL << k)) ^ (R & (1LL << k)))
				break;
			else
			{
				if (L & (1LL << k))
					L -= (1LL << k);
				if (R & (1LL << k))
					R -= (1LL << k);
			}
		tot = 0;
		v[tot++].give(L, R);
		for (LL p = 59LL;p >= 0LL;--p)
			if ((1LL << k) + (1LL << p) <= R)
			{
				v[tot++].give(1LL << k, (1LL << k) + (1LL << (p + 1LL)) - 1LL);
				break;
			}
		v[tot++].give(L + (1LL << k), (1LL << (k + 1LL)) - 1LL);
		Ans = 0LL, dfs(0, 0, 0LL, 1LL << 60LL);
	}
	print(Ans), putc('\n');
	return 0;
}
/*
考虑把L和R的二进制位从高到低写下来，去掉最长公共前缀，特判掉L = R的情况，那么L的最高位 = 0、R的最高位 = 1，设最高位是k，有L < 2^k <= R
分如下几段考虑：
(1)[L, R]一定在答案中
(2)找到最大p使得2^k + 2^p <= R，容易发现对于所有0 <= i <= p都有L < 2^k + 2^i <= R，故[2^k, 2^k + 2^(p + 1))在答案中
(3)考虑[L, 2^k)中的数，显然让它们or上> 2^k的数是没有任何意义的。故[L + 2^k, 2^(k + 1))在答案中
把这三段求并即可 
*/

Compiler output:
a.cc: In function 'int main()':
a.cc:68:12: error: 'L' was not declared in this scope
   68 |         gi(L), gi(R);
      |            ^
a.cc:68:19: error: 'R' was not declared in this scope
   68 |         gi(L), gi(R);
      |                   ^
a.cc:70:39: error: 'MOD' was not declared in this scope
   70 |                 Ans = (R - L + 1LL) % MOD;
      |                                       ^~~
a.cc:73:22: error: 'k' was not declared in this scope
   73 |                 for (k = 59LL;k >= 0LL;--k)
      |                      ^
a.cc:86:37: error: 'k' was not declared in this scope
   86 |                         if ((1LL << k) + (1LL << p) <= R)
      |                                     ^
a.cc:91:43: error: 'k' was not declared in this scope
   91 |                 v[tot++].give(L + (1LL << k), (1LL << (k + 1LL)) - 1LL);
      |                                           ^