the
The size of the chessboard is NXM, and each lattice has a weight of 1 or −1.
Above the upper left corner of the chessboard is the entrance, and the bottom and right edges are the exits.
When Dr. Picks a small ball from the top left corner, the ball will run as follows in this chessboard:
If the current size of the grid is 1, the ball will go out from the right edge of the grid, or it will go out from the bottom of the grid. After the ball leaves the lattice, the weight of the lattice becomes the opposite number, i.e. 1 turns −1,−1 into 1.
One step in Dr Picks's experiment was that he would put a K-ball in the upper-left corner of the chessboard, and each ball would be put in after the first ball had left the board. When the ball leaves the chessboard, it falls directly to the ground. To avoid the picks, the basket is hung under some exits and if the ball leaves the board from the exit of the basket, it will be caught by the basket or it will fall to the ground.
Dr. Picks, in order to avoid trouble, the size of the board of any two experiments, the number of balls, the basket position is exactly the same, he only changed the number on the original board. But because the results were eaten by handyman jiry_2, he now remembers only the number of small balls in the interval [Li,ri] that were received in the first experiment.
Now, Dr. Picks tells you the size of the chessboard, the number of balls, the position of the basket, and the Li and Ri for each experiment, and he wants to ask you to figure out how many possible chessboard of each test will satisfy the condition.
n,m<=10 k<=1e+18
Actually is a contour line DP, forcibly called DP set DP ...
This small ball number is very large, but notice that if the number of balls falling in a grid is even, it must be half to the upper half down, and the lattice weight is independent, only when the number of small balls is odd, the last small ball of the direction and lattice weights.
So let's go ahead and leave the little ball of uncertainty in that position. This is the only n*m ball at most.
then consider the contour DP, and note that there are several small balls rolling down from this boundary position.
The number of this state compared to metaphysics, anyway, is able to live.
How to save state.
I refer to the Manchery (http://blog.csdn.net/u014609452/article/details/72823557) with a 80-in-line contour, and then run very fast
#include <cstdio> #include <cstring> #include <algorithm> using namespace std;
const int mod=998244353, h_mod=1000007, maxs=500005;
typedef unsigned long long ull;
typedef long Long LL;
Ull b=80,p_b[15];
struct hashmap{int hshtab[h_mod+5],len,clk,tim[h_mod+5]; int NXT[MAXS],CNT[MAXS],RES[MAXS];
Ull BLN[MAXS];
void Clear () {len=0; clk++;} int gethead (int f_h) {return tim[f_h]!=clk? ( tim[f_h]=clk,hshtab[f_h]=0): Hshtab[f_h];
int &at (ull _bln,int _cnt) {int f_h= (_bln*233+_cnt)%h_mod;
for (int j=gethead (F_H), j;j=nxt[j]) if (bln[j]==_bln&&cnt[j]==_cnt) return res[j]; NXT[++LEN]=HSHTAB[F_H];
Hshtab[f_h]=len; Bln[len]=_bln; cnt[len]=_cnt;
res[len]=0;
return Res[len];
}} F[2];
int n,m,q,sum[15*15];
LL W[15][15],tot;
Char out1[15],out2[15];
int main () {freopen ("uoj141.in", "R", stdin);
Freopen ("Uoj141.out", "w", stdout);
scanf ("%d%d%lld%s%s", &n,&m,&w[1][1],out1+1,out2+1); for (inti=1;i<=n;i++) for (int j=1;j<=m;j++) W[I][J+1]+=W[I][J]/2, W[I+1][J]+=W[I][J]/2, w[i][j]&=1;
for (int i=1;i<=n;i++) tot+= (out1[i]== ' 1 ') *w[i][m+1], w[i][m+1]=0;
for (int i=1;i<=m;i++) tot+= (out2[i]== ' 1 ') *w[n+1][i], w[n+1][i]=0; P_b[0]=1;
for (int i=1;i<=m;i++) p_b[i]=p_b[i-1]*b; int = =; F[P].
Clear (); Ull t=0; for (int i=m;i;i--) t=t*b+w[1][i]; F[P].
at (t,0) = 1;
for (int i=1;i<=n*m;i++,p^=1) {int x= (i-1)/m+1,y= (i-1)%m+1; F[P^1].
Clear (); for (int s=1;s<=f[p].len;s++) {int now=f[p].bln[s]%b; LL n_bln;
int n_cnt; N_bln=f[p].bln[s]/b+p_b[m-1]*w[x+1][y];
N_cnt=f[p].cnt[s];
if (y<m) n_bln+= (now+1)/2;
Else n_cnt+= ((now+1)/2) * (out1[x]== ' 1 ');
if (x<n) n_bln+= (NOW/2) *p_b[m-1];
else n_cnt+= (NOW/2) * (out2[y]== ' 1 '); (F[p^1].
at (n_bln,n_cnt) +=f[p].res[s])%=mod; N_bln=f[p].bln[s]/b+p_b[m-1]*w[x+1][y];
N_cnt=f[p].cnt[s]; if (y<m) n_bln+= (NOW/2);
else n_cnt+= (NOW/2) * (out1[x]== ' 1 ');
if (x<n) n_bln+= ((now+1)/2) *p_b[m-1];
Else n_cnt+= ((now+1)/2) * (out2[y]== ' 1 '); (F[p^1].
at (n_bln,n_cnt) +=f[p].res[s])%=mod;
for (int i=1;i<=f[p].len;i++) (sum[f[p].cnt[i]]+=f[p].res[i])%=mod;
for (int i=1;i<=100;i++) (sum[i]+=sum[i-1])%=mod;
scanf ("%d", &q); while (q--) {LL l,r; scanf ("%lld%lld", &l,&r); L=max (L-tot, (LL) 0);
R=min (R-tot, (LL) 100);
if (l>r) printf ("0\n");
else printf ("%d\n", ((sum[r]-(l-1>=0?sum[l-1]:0))%mod+mod)%mod);
return 0; }