LOJの#3109氏は「TJOI2019」トルエンセグメントツリー
列挙の両側の場合は経路長ことを見出し、ルートノードの値である場合(X \)を\、左に行く\(Lの\)を、移動する権利を\(R&LT \)
肯定的な回答をすることになる\((2 ^ {L + 1} + 2 ^ {R&LT + 1} - 。3)X + T \) 、に見出すことができる(\ T <(2 ^ { L + 1} + 2 ^ {rを+ 1} - 3)\) 、次いで算出考慮\を(T \)は、左に行く\(Lの\)を右深さまで歩いて、\(R&LTの\)、移動いくつかの和よう\(T \)
最小値はすぐに見つけることは容易でなければならない\(2 ^ {R} - 1 \)を、次いで控除することができます
我々は、左および右の実際の文字列の長さを選択することを見出した([L、1 - 1 \を ] \) と\([1、R - 1 ] \) 11111111 ......
しかし、この\(Iは\)非常に良いDP 1の形態では、その後に変換される\(^ {I + 1} - 1 \ 2) 限り、それぞれの必要に応じて数、形、\(2 ^ {I + 1} \) 、同様にDPする\(T \)を加え、さらに強制選択DPの数がデジタルであることができます
複雑さがある\(D ^ {5} \ ) の上部は非常に遠くバインドするので、少し遅いが、つながることができます。。。
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int d,c;int64 a,b,s;
int getpos(int64 x) {
int res = 0;
while(x) {
++res;
x >>= 1;
}
return res;
}
int64 GetSum(int64 a,int64 b) {
int ta = getpos(a),tb = getpos(b);
if(ta > tb) {swap(a,b);swap(ta,tb);}
int64 res = 0;
for(int i = 1 ; i <= tb - ta ; ++i) {res += b;b >>= 1;}
while(a != b) {
res += a;res += b;
a >>= 1;b >>= 1;
}
res += a;
return res;
}
map<int64,int64> zz;
int La,Lb;
int64 dp[55][105][2];
int64 Process(int64 s,int num) {
memset(dp,0,sizeof(dp));
dp[0][0][0] = 1;
if(s & 1) return 0;
for(int i = 1 ; i <= 50 ; ++i) {
int to = (s >> i) & 1;
for(int j = 0 ; j <= num ; ++j) {
for(int t = 0 ; t <= 1 ; ++t) {
int up = (i <= La) + (i <= Lb);
for(int h = 0 ; h <= up ; ++h) {
if(((t + h) & 1) == to) {
int64 f = 1;
if(h == 1 && up == 2) f = 2;
dp[i][j + h][(t + h - to) / 2] += f * dp[i - 1][j][t];
}
}
}
}
}
return dp[50][num][0];
}
int64 Calc() {
int64 res = 0;
for(int i = 0 ; i <= d ; ++i) {
for(int j = 0 ; j <= d ; ++j) {
int64 k = (1LL << i + 1) + (1LL << j + 1) - 3;
int64 tmp = s;
if(tmp < k) continue;
if(getpos(tmp / k) + max(i,j) > d) continue;
tmp = tmp % k;
if(tmp < (1LL << j) - 1) continue;
tmp -= (1LL << j) - 1;
if(tmp == 0) {++res;continue;}
La = i - 1,Lb = j - 1;
for(int h = 0 ; h <= max(i - 1,0) + max(j - 1,0) ; ++h) {
res += Process(tmp + h,h);
}
}
}
return res;
}
void Solve() {
read(d);read(a);read(b);read(c);
s = GetSum(a,b);
if(c == 1) {out(s);enter;}
else {out(Calc() - 1);enter;}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
int T;
read(T);
for(int i = 1 ; i <= T ; ++i) {
Solve();
}
return 0;
}
(右培養ツアーは大丈夫だった...ちょうど最近、非常に興味深い感じ23333タイトル面を移動する権利を追いかけるようになりました)