B. Lasers

time limit per test

2 seconds

memory limit per test

256 megabytes

There is a 2D-coordinate plane that ranges from (0,0) to (x,y). You are located at (0,0) and want to head to (x,y).

However, there are n horizontal lasers, with the i-th laser continuously spanning (0,ai) to (x,ai). Additionally, there are also m vertical lasers, with the i-th laser continuously spanning (bi,0) to (bi,y).

You may move in any direction to reach (x,y), but your movement must be a continuous curve that lies inside the plane. Every time you cross a vertical or a horizontal laser, it counts as one crossing. Particularly, if you pass through an intersection point between two lasers, it counts as two crossings.

For example, if x=y=2, n=m=1, a=1, b=1, the movement can be as follows:

What is the minimum number of crossings necessary to reach (x,y)?

Input

The first line contains t (1≤t≤104) --- the number of test cases.

The first line of each test case contains four integers n, m, x, and y (1≤n,m≤2⋅105,2≤x,y≤109).

The following line contains n integers a1,a2,...,an (0<ai<y) --- the y-coordinates of the horizontal lasers. It is guaranteed that ai>ai−1 for all i>1.

The following line contains m integers b1,b2,...,bm (0<bi<x) --- the x-coordinates of the vertical lasers. It is guaranteed that bi>bi−1 for all i>1.

It is guaranteed that the sum of n and m over all test cases does not exceed 2⋅105.

Output

For each test case, output the minimum number of crossings necessary to reach (x,y).

Example

Input

Copy

复制代码

2

1 1 2 2

1

1

2 1 100000 100000

42 58

32

Output

Copy

复制代码
2
3

解题说明:此题是一道数学题,找规律能发现直接输出m+n即可。

cpp 复制代码
#include <stdio.h>

int main() 
{
	int t, n, m, x, y, a, ans;
	scanf("%d", &t);
	while (t--) 
	{
		scanf("%d %d %d %d", &n, &m, &x, &y);
		ans = n + m;
		while (n--)
		{
			scanf("%d", &a);
		}
		while (m--)
		{
			scanf("%d", &a);
		}
		printf("%d\n", ans);
	}
	return 0;
}
相关推荐
8Qi81 小时前
回文子串(Palindromic Substrings)—— 题解
算法·leetcode·职场和发展·动态规划
小宋加油啊6 小时前
机械臂抓取物体 PVN3D算法调研学习
学习·算法·3d
lqqjuly6 小时前
前沿算法深度解析(一)
算法
小欣加油6 小时前
leetcode1926 迷宫中离入口最近的出口
数据结构·c++·算法·leetcode·职场和发展
happymaker06269 小时前
LeetCodeHot100——42.接雨水
算法
阿正的梦工坊9 小时前
【Rust】07-错误处理:Option、Result 与 ? 运算符
开发语言·算法·rust
八解毒剂11 小时前
数据结构-平衡二叉树——对二叉搜索树的优化
数据结构·c++·算法
运行时记录11 小时前
别再手动写提示词了 — SkillOpt 让技能文档自己进化
算法
啦啦啦啦啦zzzz11 小时前
算法总结(二分查找、双指针)
c++·算法