luogu#P12079. [OOI 2025] Card Flip

[OOI 2025] Card Flip

题目描述

Petya and Vasya bought a new card game called ''Flip''. The game contains nn double-sided cards and mm single-sided cards:

  • Double-sided card.\textbf{Double-sided card.} The front side of the card has the number aia_i, and the back side has the number bib_i.
  • Single-sided card.\textbf{Single-sided card.} The front side of the card has a single number cic_i.

All numbers written on the cards on all sides are distinct. Initially, all cards are placed on the table with the front side up. On his turn, a player can perform exactly one of two actions:

  • Remove from the table the card with the smallest number among the remaining cards.
  • If the card with the smallest number is double-sided and facing up, it can be flipped.

The player who removes the last card from the table wins. Determine the winner of the game if Petya goes first.

输入格式

The first line contains two integers nn and mm (1n,m5000001 \le n, m \le 500\,000) --- the number of double-sided and single-sided cards, respectively.

The second line contains nn integers a1a_1, a2a_2, \ldots, ana_n (1ai2n+m1 \le a_i \le 2 \cdot n + m) --- the numbers written on the front side of the double-sided cards.

The third line contains nn integers b1b_1, b2b_2, \ldots, bnb_n (1bi2n+m1 \le b_i \le 2 \cdot n + m) --- the numbers written on the back side of the double-sided cards.

The fourth line contains mm integers c1c_1, c2c_2, \ldots, cmc_m (1ci2n+m1 \le c_i \le 2 \cdot n + m) --- the numbers written on the single-sided cards.

It is guaranteed that each number from 11 to 2n+m2\cdot n + m appears exactly once in one of the arrays aa, bb, or cc.

输出格式

Print First if Petya wins in this game, and Second if Vasya wins.

2 1
5 3
1 2
4
First
1 2
2
3
4 1
Second

提示

Note

In the first example, initially, the cards 3, 4, and 5 are on the table. To win, Petya discards card 3 on his turn, after which Vasya must discard card 4, as it is single-sided. Finally, Petya discards card 5, meaning there will be no cards left for Vasya, and Petya wins.

In the second example, initially, the cards 1, 2, and 4 are on the table. Petya must discard the first card, as it is single-sided. Then, to win, Vasya flips card 2, so there will be cards 3 and 4 on the table. Petya must discard the flipped card number 3, after which Vasya will discard card 4. Since the cards will run out, Vasya will win.

Scoring

The tests for this problem consist of nine groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. Offline-evaluation\textbf{Offline-evaluation} means that the results of testing your solution on this group will only be available after the end of the competition.

Group Points Additional constraints: nn Additional constraints: mm Required Groups Comment
0 -- Examples.
1 12 n20n \le 20 m10m \le 10 0
2 13 -- 0, 1
3 9 -- -- ai>bia_i > b_i
4 10 maxi=1n(ai)<mini=1n(bi)\max_{i = 1}^n(a_i) < \min_{i = 1}^n(b_i)
5 6 The segments [min(ai,bi);max(ai,bi)][ \min(a_i, b_i); \max(a_i, b_i)] do not intersect.
6 11 n200n \le 200 m200m \le 200 The segments [min(ai,bi);max(ai,bi)][ \min(a_i, b_i); \max(a_i, b_i)] are nested or do not intersect.
7 14 -- 5, 6
8 13 n5000n \le 5000 m5000m \le 5000 0, 1, 6
9 12 -- 0 -- 8 Offline-evaluation.