I'm such a sb!!!.
F[I][0/1][0/1][0/1] to consider whether the first I bit is the upper bound of card N, whether the upper bound of card m, whether the number of the lower bound of card K
G[I][0/1][0/1][0/1] Indicates whether the upper bounds of card n is the upper bound of the first I position of the I-bit, or if the lower bound of card K is the number pair and
Direct DP
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <iostream > #include <algorithm>using namespace Std;long long F[110][2][2][2],g[110][2][2][2],bin[64];long long n,m,mod , K;int T;int Main () {scanf ("%d", &t), while (t--) {scanf ("%lld%lld%lld%lld", &n,&m,&k,&mod); n--; M--;long long ans=0;bin[0]=1;for (int i=1;i<=63;i++) bin[i]= (Long Long) Bin[i-1]*2ll%mod;memset (f,0,sizeof (f)); memset (G,0,sizeof (g)); f[0][1][1][1]=1;g[0][1][1][1]=0;for (int i=0;i<=63;i++) for (int. a=0;a<2;a++) for (int b=0 ; b<2;b++) for (int c=0;c<2;c++) if (F[i][a][b][c]) {int p= (n& (1ll<<)) 63-i )? 0:1; int q= ((m& (1ll<< (63-i))) ==0)? 0:1; int t= ((k& (1ll<< (63-i))) ==0)? 0:1; for (int x=0;x<2;x++) {if (a && x>p) continue; for (int y=0;y<2;y++) {if (b && y>q) continue; int z=x^y; if (C && z<t) continue; int a= (A && x==p)? 1:0; int b= (B && y==q)? 1:0; int c= (C && z==t)? 1:0; F[i+1][a][b][c]= (F[i+1][a][b][c]+f[i][a][b][c])%mod; G[i+1][a][b][c]= (g[i+1][a][b][c]+g[i][a][b][c]+ ((z==0) 0:bin[63-i]) *f[i][a][b][c]%mod)%mod; }}}k%=mod;for (int a=0;a<2;a++) for (int. b=0;b<2;b++) for (int c=0;c<2;c++) ans= (ans+g[6 4][a][b][c]-k*f[64][a][b][c]%mod+mod)%mod;printf ("%lld\n", ans);} return 0;}
"bzoj4513" [Sdoi2016] Energy-Storage meter DP