#CF1895E. Infinite Card Game

    ID: 119 远端评测题 3000ms 512MiB 尝试: 6 已通过: 1 难度: 10 上传者: 标签>binary searchdata structuresdfs and similardpgamesgraphsgreedysortingstwo pointers

Infinite Card Game

Description

Monocarp and Bicarp are playing a card game. Each card has two parameters: an attack value and a defence value. A card $s$ beats another card $t$ if the attack of $s$ is strictly greater than the defence of $t$.

Monocarp has $n$ cards, the $i$-th of them has an attack value of $\mathit{ax}_i$ and a defence value of $\mathit{ay}_i$. Bicarp has $m$ cards, the $j$-th of them has an attack value of $\mathit{bx}_j$ and a defence value of $\mathit{by}_j$.

On the first move, Monocarp chooses one of his cards and plays it. Bicarp has to respond with his own card that beats that card. After that, Monocarp has to respond with a card that beats Bicarp's card. After that, it's Bicarp's turn, and so forth.

After a card is beaten, it returns to the hand of the player who played it. It implies that each player always has the same set of cards to play as at the start of the game. The game ends when the current player has no cards that beat the card which their opponent just played, and the current player loses.

If the game lasts for $100^{500}$ moves, it's declared a draw.

Both Monocarp and Bicarp play optimally. That is, if a player has a winning strategy regardless of his opponent's moves, he plays for a win. Otherwise, if he has a drawing strategy, he plays for a draw.

You are asked to calculate three values:

  • the number of Monocarp's starting moves that result in a win for Monocarp;
  • the number of Monocarp's starting moves that result in a draw;
  • the number of Monocarp's starting moves that result in a win for Bicarp.

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains an integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of cards Monocarp has.

The second line contains $n$ integers $\mathit{ax}_1, \mathit{ax}_2, \dots, \mathit{ax}_n$ ($1 \le \mathit{ax}_i \le 10^6$) — the attack values of Monocarp's cards.

The third line contains $n$ integers $\mathit{ay}_1, \mathit{ay}_2, \dots, \mathit{ay}_n$ ($1 \le \mathit{ay}_i \le 10^6$) — the defence values of Monocarp's cards.

The fourth line contains a single integer $m$ ($1 \le m \le 3 \cdot 10^5$) — the number of cards Bicarp has.

The fifth line contains $m$ integers $\mathit{bx}_1, \mathit{bx}_2, \dots, \mathit{bx}_m$ ($1 \le \mathit{bx}_j \le 10^6$) — the attack values of Bicarp's cards.

The sixth line contains $m$ integers $\mathit{by}_1, \mathit{by}_2, \dots, \mathit{by}_m$ ($1 \le \mathit{by}_j \le 10^6$) — the defence values of Bicarp's cards.

Additional constraints on the input: the sum of $n$ over all test cases doesn't exceed $3 \cdot 10^5$, the sum of $m$ over all test cases doesn't exceed $3 \cdot 10^5$.

For each test case, print three integers:

  • the number of Monocarp's starting moves that result in a win for Monocarp;
  • the number of Monocarp's starting moves that result in a draw;
  • the number of Monocarp's starting moves that result in a win for Bicarp.

题面翻译

单卡和双卡在玩纸牌游戏。每张牌都有两个参数:攻击值和防御值。ss 能打败 tt 当且仅当 ss 的攻击值严格大于 tt 的防御值。

Monocarp 有 nn 张牌,其中第 ii 张的攻击值为 axi\mathit{ax}_i,防御值为 ayi\mathit{ay}_i 。Bicarp有 mm 张牌,其中第 ii 张的攻击值为 bxi\mathit{bx}_i,防御值为 byi\mathit{by}_i。在第一步棋中,Monocarp 选择他的一张牌并打出。Bicarp 必须用他自己的牌来回应,而这张牌要胜过那张牌。之后,Monocarp 必须用一张击败比卡普的牌来回应。之后,轮到 Bicarp,以此类推。

一张牌被打出后,回到打出该牌的玩家手中。 这意味着每个玩家总是拥有游戏开始时的同一套牌。 游戏结束时,若当前玩家手中的牌不能击败对手刚刚打出的牌,当前玩家输掉游戏。如果对局持续 100500100^{500} 步,则宣布平局。

Monocarp 和 Bicarp 都是最佳下法。也就是说,如果棋手无论对手下了多少步棋,都有获胜的策略,那么他就会获胜。否则,如果他有平局策略,他就下平局。要求您计算三个值:

  • Monocarp 的起手牌中导致 Monocarp 获胜的牌数;
  • Monocarp 的起手牌中导致平局的牌数;
  • Monocarp 的起手牌中导致 Bicarp 获胜的牌数。

多组数据,1t1041 \le t \le 10^41n31051 \le n \le 3 \cdot 10^5,$1 \le \mathit{ax}_i,\mathit{ax}_y,\mathit{bx}_i,\mathit{by}_i \le 10^6$,n,m3105\sum n,\sum m \leq 3 \cdot 10^5

Input

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains an integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of cards Monocarp has.

The second line contains $n$ integers $\mathit{ax}_1, \mathit{ax}_2, \dots, \mathit{ax}_n$ ($1 \le \mathit{ax}_i \le 10^6$) — the attack values of Monocarp's cards.

The third line contains $n$ integers $\mathit{ay}_1, \mathit{ay}_2, \dots, \mathit{ay}_n$ ($1 \le \mathit{ay}_i \le 10^6$) — the defence values of Monocarp's cards.

The fourth line contains a single integer $m$ ($1 \le m \le 3 \cdot 10^5$) — the number of cards Bicarp has.

The fifth line contains $m$ integers $\mathit{bx}_1, \mathit{bx}_2, \dots, \mathit{bx}_m$ ($1 \le \mathit{bx}_j \le 10^6$) — the attack values of Bicarp's cards.

The sixth line contains $m$ integers $\mathit{by}_1, \mathit{by}_2, \dots, \mathit{by}_m$ ($1 \le \mathit{by}_j \le 10^6$) — the defence values of Bicarp's cards.

Additional constraints on the input: the sum of $n$ over all test cases doesn't exceed $3 \cdot 10^5$, the sum of $m$ over all test cases doesn't exceed $3 \cdot 10^5$.

Output

For each test case, print three integers:

  • the number of Monocarp's starting moves that result in a win for Monocarp;
  • the number of Monocarp's starting moves that result in a draw;
  • the number of Monocarp's starting moves that result in a win for Bicarp.
3
3
8 7 4
7 1 10
2
8 4
5 10
9
8 8 5 5 5 4 4 1 4
2 7 5 2 8 9 7 1 9
10
9 8 7 6 5 5 4 3 2 1
7 1 6 7 5 8 8 4 9 6
1
10
5
1
10
5
1 1 1
2 4 3
0 1 0