1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include<bits/stdc++.h> using namespace std; #define int long long inline int read(){int 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<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back
#define N 70 int n, m, i, j, k; int f[N][2][2][2][2], T[N], Lx[N], Ly[N], Rx[N], Ry[N];
void mke(int *a, int x) { if(!x) return ; int k=-1; while(x) a[++k]=x%2, x/=2; }
int dp(int k, int sx, int sy, int tx, int ty) { if(k<0) return 1; if(f[k][sx][sy][tx][ty]!=-1) return f[k][sx][sy][tx][ty]; int flg=0, Sx, Sy, Tx, Ty, ans=0; for(int x=0; x<=1; ++x) for(int y=0; y<=1; ++y) { if(sx && x<Lx[k]) continue; if(sy && x>Ly[k]) continue; if(tx && y<Rx[k]) continue; if(ty && y>Ry[k]) continue; if((x|y)!=T[k]) continue; int p1=sx&(x==Lx[k]), p2=sy&(x==Ly[k]), q1=tx&(y==Rx[k]), q2=ty&(y==Ry[k]); if((x&y)==1) ans+=dp(k-1, p1, p2, q1, q2); else flg=max(dp(k-1, p1, p2, q1, q2), flg); } ans+=flg; return f[k][sx][sy][tx][ty]=ans; }
signed main() {
memset(f, -1, sizeof(f)); n=read(); mke(T, n); n=read(); mke(Lx, n); n=read(); mke(Ly, n); n=read(); mke(Rx, n); n=read(); mke(Ry, n); printf("%lld", dp(61, 1, 1, 1, 1)); return 0; }
|