#FT0000172. Những khu vực có rào chắn (The Untended Antiquity)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những khu vực có rào chắn (The Untended Antiquity)
The Untended Antiquity
Source: Codeforces
Version: Phước Hưng OJ Extended
Problem Statement
An grid of cells can contain barriers surrounding rectangular cell regions. A barrier prevents movement between a cell inside its rectangle and a neighboring cell outside it; crossing no barrier is permitted. Initially no barriers are present. Process operations:
1 r1 c1 r2 c2: place a barrier around the specified rectangle.2 r1 c1 r2 c2: remove the barrier around that exact rectangle; it is guaranteed to exist.3 r1 c1 r2 c2: determine whether one can walk between the two specified cells by orthogonal moves without crossing any active barrier.
Active barriers never meet or intersect, nor touch the outer boundary. Nesting is allowed provided these conditions hold.
Input
The first line gives . Each of the following lines contains t r1 c1 r2 c2. For types 1 and 2, the barrier rectangle lies strictly inside: , . For type 3, both cell coordinates may be anywhere in the grid.
Output
For each type-3 operation, output exactly Yes if a walk exists and No otherwise, one per line.
Subtask
- Subtask 1 (20 points): ; ; ; query cells satisfy , ; if a barrier exists, and barriers have , ; active barriers never intersect or touch; every removal targets an existing barrier.
- Subtask 2 (30 points): ; ; ; query cells satisfy , ; if a barrier exists, and barriers have , ; active barriers never intersect or touch; every removal targets an existing barrier.
- Subtask 3 (50 points): ; ; ; query cells satisfy , ; if a barrier exists, and barriers have , ; active barriers never intersect or touch; every removal targets an existing barrier.
Examples
Example 1
Input
5 6 5
1 2 2 4 5
1 3 3 3 3
3 4 4 1 1
2 2 2 4 5
3 1 1 4 4
Output
No
Yes
Explanation
Two nested barriers are placed. Cell lies inside the larger barrier, but lies outside it, so the first attempted walk must cross that barrier and the answer is No. After the larger barrier is removed, both cells lie outside the smaller barrier around , and a path avoiding it exists, so the answer is Yes.
Example 2
Input
5 5 7
3 2 2 4 4
1 2 2 2 2
3 2 2 3 3
3 1 1 3 3
2 2 2 2 2
3 2 2 3 3
3 5 5 1 1
Output
Yes
No
Yes
Yes
Yes
Explanation
Initially every cell is reachable from every other, giving Yes. Enclosing cell separates it from , giving No. Both and remain outside the barrier, so a path connects them, giving Yes. Once the barrier is removed, all cells are connected and the final two answers are Yes.