qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

Codeforces Round #594 (Div. 2) A. Integer Points 水题

A. Integer Points

DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew 𝑛 distinct lines, given by equations 𝑦=𝑥+𝑝𝑖 for some distinct 𝑝1,𝑝2,…,𝑝𝑛.

Then JLS drew on the same paper sheet 𝑚 distinct lines given by equations 𝑦=−𝑥+𝑞𝑖 for some distinct 𝑞1,𝑞2,…,𝑞𝑚.

DLS and JLS are interested in counting how many line pairs have integer intersection points, i.e. points with both coordinates that are integers. Unfortunately, the lesson will end up soon, so DLS and JLS are asking for your help.

Input

The first line contains one integer 𝑡 (1≤𝑡≤1000), the number of test cases in the input. Then follow the test case descriptions.

The first line of a test case contains an integer 𝑛 (1≤𝑛≤105), the number of lines drawn by DLS.

The second line of a test case contains 𝑛 distinct integers 𝑝𝑖 (0≤𝑝𝑖≤109) describing the lines drawn by DLS. The integer 𝑝𝑖 describes a line given by the equation 𝑦=𝑥+𝑝𝑖.

The third line of a test case contains an integer 𝑚 (1≤𝑚≤105), the number of lines drawn by JLS.

The fourth line of a test case contains 𝑚 distinct integers 𝑞𝑖 (0≤𝑞𝑖≤109) describing the lines drawn by JLS. The integer 𝑞𝑖 describes a line given by the equation 𝑦=−𝑥+𝑞𝑖.

The sum of the values of 𝑛 over all test cases in the input does not exceed 105. Similarly, the sum of the values of 𝑚 over all test cases in the input does not exceed 105.

In hacks it is allowed to use only one test case in the input, so 𝑡=1 should be satisfied.

Output

For each test case in the input print a single integer — the number of line pairs with integer intersection points.

Example

input
3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1
output
3
1
0

Note

The picture shows the lines from the first test case of the example. Black circles denote intersection points with integer coordinates.

题意

一个二维平面,有两种线,一种是y=x+p[i],一种是y=-x+q[i],问你这两种直线相交后,有多少个整数交点。

题解

我们解出来相交点为 x = (p[i]+q[i])/2,那么只要同奇偶,就是整数交点

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int p[maxn],q[maxn],n,m;
void solve(){
	vector<int>cnt1(2,0),cnt2(2,0);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		cnt1[p[i]%2]++;
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d",&q[i]);
		cnt2[q[i]%2]++;
	}
	cout<<1ll*cnt1[0]*cnt2[0]+1ll*cnt1[1]*cnt2[1]<<endl;

}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		solve();
	}
}
posted @ 2019-11-12 15:35  qscqesze  阅读(90)  评论(0编辑  收藏