自己太弱了,才觉得慢慢的坑,谨以此纪念我的智商,另外快速幂的时候,不需要大数幂,我太懒了,直接捞了个板子来用。
import java.io.BufferedReader;
import java.io.CharConversionException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Main {
// static int[] ch= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
// static char[] ch= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
public static void main(String[] args) {
// TODO Auto-generated method stub
PrintWriter out=new PrintWriter(System.out);
InputReader in=new InputReader(System.in);
int h=in.nextInt();
int w=in.nextInt();
Node[][] node=new Node[h+1][w+1];
//没有考虑到矛盾
//声明
for(int i=0;i<=h;i++) {
for(int j=0;j<=w;j++) {
node[i][j]=new Node();
}
}
//存行
for(int i=1;i<=h;i++) {
int a=in.nextInt();
int j=0;
for(j=1;j<=a;j++) {
node[i][j].data=1;
}
if(j<=w) {
node[i][j].data=2;
}
}
//存列
for(int i=1;i<=w;i++) {
int a=in.nextInt();
int j=0;
for(j=1;j<=a;j++) {
if(node[j][i].data==2) {
System.out.println(0);
return;
}else
node[j][i].data=1;
}
if(j<=h) {
if(node[j][i].data==1) {
System.out.println(0);
return;
}else
node[j][i].data=2;
}
}
int ans=0;
for(int i=1;i<=h;i++) {
for(int j=1;j<=w;j++) {
if(node[i][j].data==0) {
ans++;
}
}
}
BigInteger b=BigInteger.valueOf(ans);
System.out.println(pow(BigInteger.valueOf(2),b,BigInteger.valueOf(1000000007)));
}
private static BigInteger pow(BigInteger a, BigInteger b,BigInteger mod) {
// TODO Auto-generated method stub
BigInteger ans=BigInteger.ONE;
BigInteger t=a;
while(b.compareTo(BigInteger.ZERO)>0) {
if(b.and(BigInteger.ONE).compareTo(BigInteger.ZERO)!=0) {
ans=ans.multiply(t);
ans=ans.mod(mod);
}
b=b.shiftRight(1);
t=t.multiply(t); //千万不要忘了这一步
t=t.mod(mod);
}
return ans;
}
}
class Node{
int x;
int y;
int data;
}
class InputReader{
private final InputStream stream;
private final byte[] buf=new byte[8192];
private int curChar,snumChars;
public InputReader(InputStream st) {
this.stream=st;
}
public int read() {
if(snumChars==-1)
throw new InputMismatchException();
if(curChar>=snumChars) {
curChar=0;
try {
snumChars=stream.read(buf);
}catch (IOException e) {
// TODO: handle exception
throw new InputMismatchException();
}
if(snumChars<=0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c=read();
while(isSpaceChar(c)) {
c=read();
}
int sgn=1;
if(c=='-') {
sgn=-1;
c=read();
}
int res=0;
do {
res*=10;
res+=c-'0';
c=read();
}while(!isSpaceChar(c));
return res*sgn;
}
public long nextLong() {
int c=read();
while(isSpaceChar(c)) {
c=read();
}
int sgn=1;
if(c=='-') {
sgn=-1;
c=read();
}
int res=0;
do {
res*=10;
res+=c-'0';
c=read();
}while(!isSpaceChar(c));
return res*sgn;
}
public int[] nextIntArray(int n) {
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=nextInt();
}
return a;
}
public String readString() {
int c=read();
while(isSpaceChar(c)) {
c=read();
}
StringBuilder res=new StringBuilder();
do {
res.appendCodePoint(c);
c=read();
}while(!isSpaceChar(c));
return res.toString();
}
// public String nextLine() {
// int c=read();
// while(isSpaceChar(c)) {
// c=read();
// }
// StringBuilder res=new StringBuilder();
// do {
// res.appendCodePoint(c);
// c=read();
// }while(!isEndOfLine(c));
// return res.toString();
// }
private boolean isEndOfLine(int c) {
// TODO Auto-generated method stub
return c=='\n'||c=='\r'||c==-1;
}
private boolean isSpaceChar(int c) {
// TODO Auto-generated method stub
return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
}
}