8618: Three Body

内存限制:256 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述

"The fish who dried the sea went onto land before they did this. They move from one dark forest to another dark forest."

You are now in a KKK-dimensional universe, which could be seen as an n1×n2×...×nKn_1\times n_2 \times ... \times n_Kn1×n2×...×nK hyperrectangle. To be specific, let's divide the universe into n1×n2×...×nKn_1\times n_2 \times ... \times n_Kn1×n2×...×nK hypercubes sized 1×1×...×11 \times 1 \times ... \times 11×1×...×1 to describe different regions. The position of each region can be denoted by a KKK-dimensional integer coordinate (a1,a2,...,aK)(a_1, a_2, ..., a_K)(a1,a2,...,aK) where 0≤ai<ni0 \le a_i < n_i0ai<ni. Each region owns a Dimensional Value\textit{Dimensional Value}Dimensional Value and the initial value is KKK. However, due to the space war and the abuse of dimensionality weapons, the Dimensional Values\textit{Dimensional Values}Dimensional Values of some regions in the universe has decayed to less than KKK.

Your spaceship is an m1×m2×...×mKm_1\times m_2 \times ... \times m_Km1×m2×...×mK hyperrectangle which can also be viewed as m1×m2×...×mKm_1\times m_2 \times ... \times m_Km1×m2×...×mK parts of hypercubes sized 1×1×...×11\times 1\times ...\times 11×1×...×1. The position of each part can also be denoted by a KKK-dimensional integer coordinate (b1,b2,...,bK)(b_1, b_2, ..., b_K)(b1,b2,...,bK) where 0≤bi<mi0 \le b_i < m_i0bi<mi. Each part of your spaceship also owns a Dimensional Value\textit{Dimensional Value}Dimensional Value which is initially KKK. Thanks to advanced technology, some parts of your spaceship are reformed and their Dimensional Values\textit{Dimensional Values}Dimensional Values become less than KKK, which can make them enter the regions with lower Dimensional Values\textit{Dimensional Values}Dimensional Values.

We define the spaceship to be in a valid position if the following conditions are met:
  • Each part of the spaceship is located exactly in one region.
  • Each part of the spaceship cannot have a Dimensional Value\textit{Dimensional Value}Dimensional Value strictly higher than the Dimensional Value\textit{Dimensional Value}Dimensional Value of the region.
Please calculate the number of different valid positions for your spaceship. Please note that you can't rotate the spaceship.

输入格式

The first line contains an integer KKK (2≤K≤52\le K\le 52K5).
The second line contains KKK integers n1,n2,...,nKn_1,n_2,...,n_Kn1,n2,...,nK (1≤∏i=1Kni≤3×1051\le \prod_{i=1}^{K}n_i\le 3\times 10^51i=1Kni3×105), indicating the size of the universe.
The third line is an integer cuc_ucu (0≤cu≤∏i=1Kni0\le c_u\le \prod_{i=1}^{K}n_i0cui=1Kni), indicating the number of regions whose Dimensional Value\textit{Dimensional Value}Dimensional Value has decayed.
Each of the following cuc_ucu lines contains K+1K+1K+1 integers a1,a2,...,aKa_1,a_2,...,a_Ka1,a2,...,aK and ddd (0≤ai<ni0 \le a_i < n_i0ai<ni, 1≤d<K1 \le d < K1d<K), indicating that the Dimensional Value\textit{Dimensional Value}Dimensional Value of region (a1,a2,...,aK)(a_1,a_2,...,a_K)(a1,a2,...,aK) has decayed to ddd. It is guaranteed that the cuc_ucu regions are pairwise different.
The next line contains KKK integers m1,m2,...,mKm_1,m_2,...,m_Km1,m2,...,mK (1≤mi<ni1 \le m_i <n_i1mi<ni), indicating the size of the spaceship.
The next line contains an integer csc_scs (0≤cs≤∏i=1Kmi0\le c_s\le \prod_{i=1}^{K}m_i0csi=1Kmi), indicating the number of parts of the spaceship are reformed.
Each of the following csc_scs lines contains K+1K+1K+1 integers b1,b2,...,bKb_1,b_2,...,b_Kb1,b2,...,bK and ddd (0≤bi<mi0 \le b_i < m_i0bi<mi, 1≤d<K1 \le d < K1d<K), indicating that the Dimensional Value\textit{Dimensional Value}Dimensional Value of part (b1,b2,...,bK)(b_1,b_2,...,b_K)(b1,b2,...,bK) becomes ddd. It is guaranteed that the csc_scs parts are pairwise different.

输出格式

Output one integer indicating the number of different valid positions for your spaceship.

输入样例 复制

2
4 4
7
0 0 1
1 0 1
1 2 1
2 0 1
2 1 1
2 3 1
3 3 1
2 2
1
1 1 1

输出样例 复制

1

数据范围与提示

				
For the first sample, the universe is two-dimensional. The Dimensional Values\textit{Dimensional Values}Dimensional Values of the universe and spaceship are as follows.

分类标签