PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000172. Những khu vực có rào chắn (The Untended Antiquity)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 N×MN\times M 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 QQ 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 N,M,QN,M,Q. Each of the following QQ lines contains t r1 c1 r2 c2. For types 1 and 2, the barrier rectangle lies strictly inside: 2≤r1≤r2≤N−12\le r1\le r2\le N-1, 2≤c1≤c2≤M−12\le c1\le c2\le M-1. 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): 1≤N≤101\le N\le 10; 1≤M≤101\le M\le 10; 1≤Q≤401\le Q\le 40; query cells satisfy 1≤r≤N1\le r\le N, 1≤c≤M1\le c\le M; if a barrier exists, N,M≥3N,M\ge3 and barriers have 2≤r1≤r2≤N−12\le r_1\le r_2\le N-1, 2≤c1≤c2≤M−12\le c_1\le c_2\le M-1; active barriers never intersect or touch; every removal targets an existing barrier.
  • Subtask 2 (30 points): 1≤N≤3001\le N\le 300; 1≤M≤3001\le M\le 300; 1≤Q≤35001\le Q\le 3500; query cells satisfy 1≤r≤N1\le r\le N, 1≤c≤M1\le c\le M; if a barrier exists, N,M≥3N,M\ge3 and barriers have 2≤r1≤r2≤N−12\le r_1\le r_2\le N-1, 2≤c1≤c2≤M−12\le c_1\le c_2\le M-1; active barriers never intersect or touch; every removal targets an existing barrier.
  • Subtask 3 (50 points): 1≤N≤25001\le N\le 2500; 1≤M≤25001\le M\le 2500; 1≤Q≤1000001\le Q\le 100000; query cells satisfy 1≤r≤N1\le r\le N, 1≤c≤M1\le c\le M; if a barrier exists, N,M≥3N,M\ge3 and barriers have 2≤r1≤r2≤N−12\le r_1\le r_2\le N-1, 2≤c1≤c2≤M−12\le c_1\le c_2\le M-1; 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 (4,4)(4,4) lies inside the larger barrier, but (1,1)(1,1) 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 (3,3)(3,3), 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 (2,2)(2,2) separates it from (3,3)(3,3), giving No. Both (1,1)(1,1) and (3,3)(3,3) 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.