\ ([HNOI / AHOI2018] \ ) treasure hunt
Thinking good question.
Each one brought out composition \ (m \) of length \ (n-\) binary number.
Consider the operation into \ (01 \) sequence, \ ((\ LOR \ TO0, \ Land \ TO1) \) .
After that observed for the first \ (J \) bit of the result is \ (1 \) is the last \ (\ lor1 \) position of the operation must be in \ (\ land0 \) later.
What is the conversion requires \ (x \ gt \) operating string.
Conversely, the \ (J \) is \ (0 \) in a case where the last known Similarly \ (\ land0 \) position of the operation must be in \ (\ lor1 \) later.
What is the transformation requires \ (x \ leq \) operating string.
Generals out of a sequence of binary rows, the operation to find upper and lower bounds, to subtract.
There are some details to note, for example, the highest-bit binary string from the original string of \ (1 \) th is the first \ (n \) months.
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
int f=1,w=0;char x=0;
while(x<'0'||x>'9') {if(x=='-') f=-1; x=getchar();}
while(x!=EOF&&x>='0'&&x<='9') {w=(w<<3)+(w<<1)+(x^48);x=getchar();}
return w*f;
}
const int p=1e9+7;
const int N=5e3+10;
string S[N];
int n,m,M[N],Rnk[N],Q,Sum[N];
struct Number
{
int x[N/5+1],Id;
inline bool operator < (const Number &y) const
{
for(int i=1;i<=n;i++)
if(x[i]!=y.x[i]) return x[i]<y.x[i];
return 0;
}
} t[N];
signed main(){
#ifndef ONLINE_JUDGE
freopen("A.in","r",stdin);//Ans=6
#endif
n=read(),m=read();Q=read();M[0]=1;
for(int i=1;i<=n;i++) M[i]=(M[i-1]*2)%p;
for(int i=1;i<=n;i++) cin>>S[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
t[j].x[n-i+1]=S[i][j-1]-'0';
for(int i=1;i<=m;i++) t[i].Id=i;
sort(t+1,t+m+1);
for(int i=1;i<=m;i++) Rnk[t[i].Id]=i;
for(int i=1;i<=n;i++) t[m+1].x[i]=1;
for(int i=1;i<=m+1;i++)
for(int j=1;j<=n;j++)
if(t[i].x[j]) Sum[i]=(Sum[i]+M[n-j])%p;
Sum[m+1]++;
while(Q--)
{
int B=0,E=m+1;string X;cin>>X;
for(int i=1;i<=m;i++) if((X[i-1]-'0')) E=min(E,Rnk[i]);
for(int i=1;i<=m;i++) if(!(X[i-1]-'0')) B=max(B,Rnk[i]);
if(B>E) {puts("0");continue;}
printf("%lld\n",(Sum[E]-Sum[B]+p)%p);
}
}