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

#DSU0000012. Tô đỏ các ô (Red Painting)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tô đỏ các ô (Red Painting)

Red Painting

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You have an h×wh\times w grid whose cells are initially white. Two types of operations are performed:

  • Paint a white cell red.
  • Ask whether one cell can be reached from another by moving only through red cells, one step at a time to a cell sharing a side.

Answer all connectivity queries in order.

Input

The first line contains two integers h,wh,w. The next line contains an integer qq. Each of the following qq lines has one of these forms:

  • 1 r c: paint the cell at row rr, column cc red.
  • 2 ra ca rb cb: ask about a path between (ra,ca)(r_a,c_a) and (rb,cb)(r_b,c_b).

Rows are numbered from 11 to hh and columns from 11 to ww. Each cell is painted at most once.

Output

For each operation of type 2, print Yes if such a path exists and No otherwise, one answer per line.

Subtasks

  • Subtask 1 (20 points): 1≤h≤121\le h\le 12; 1≤w≤121\le w\le 12; 1≤q≤651\le q\le 65; 1≤r,ra,rb≤h1\le r,r_a,r_b\le h; 1≤c,ca,cb≤w1\le c,c_a,c_b\le w; every cell is painted at most once.
  • Subtask 2 (30 points): 1≤h≤1301\le h\le 130; 1≤w≤1301\le w\le 130; 1≤q≤60001\le q\le 6000; 1≤r,ra,rb≤h1\le r,r_a,r_b\le h; 1≤c,ca,cb≤w1\le c,c_a,c_b\le w; every cell is painted at most once.
  • Subtask 3 (50 points): 1≤h≤20001\le h\le 2000; 1≤w≤20001\le w\le 2000; 1≤q≤1000001\le q\le 100000; 1≤r,ra,rb≤h1\le r,r_a,r_b\le h; 1≤c,ca,cb≤w1\le c,c_a,c_b\le w; every cell is painted at most once.

Examples

Input

3 3
6
1 2 2
1 1 2
2 1 2 2 2
1 1 1
2 1 1 2 2
2 1 1 3 3

Output

Yes
Yes
No

Explanation

After painting (2,2) and (1,2), they are connected: Yes. Painting (1,1) also connects it to (2,2): Yes. Cell (3,3) remains white: No.