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

#SRD0000009. Đếm cây trong hình chữ nhật có cập nhật (Forest Queries II)

HỌC THEO LỘ TRÌNH

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

3 lộ trình

Đếm cây trong hình chữ nhật có cập nhật (Forest Queries II)

Forest Queries II

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

A forest is an n×nn\times n grid where * denotes a tree and . an empty cell. Process qq operations in order: type 1 y x toggles the state of exactly one cell, and type 2 y1 x1 y2 x2 counts the trees within the inclusive rectangle with the specified opposite corners. All earlier toggles affect the current query.

Input

The first line contains n,qn,q, followed by nn grid rows of exactly nn characters each (. or *). Each of the next qq lines is 1 y x (toggle cell) or 2 y1 x1 y2 x2 (count trees).

Output

For each query requesting a result, output one integer on its own line in input order. Update operations produce no output.

Subtasks

  • Subtask 1 (10 points): 1≤n≤81\le n\le 8; 1≤q≤301\le q\le 30; Every row has exactly nn characters from {., *}; 1≤y,x≤n1\le y,x\le n, 1≤y1≤y2≤n1\le y_1\le y_2\le n, 1≤x1≤x2≤n1\le x_1\le x_2\le n.
  • Subtask 2 (20 points): 1≤n≤1001\le n\le 100; 1≤q≤10001\le q\le 1000; Every row has exactly nn characters from {., *}; 1≤y,x≤n1\le y,x\le n, 1≤y1≤y2≤n1\le y_1\le y_2\le n, 1≤x1≤x2≤n1\le x_1\le x_2\le n.
  • Subtask 3 (30 points): 1≤n≤4001\le n\le 400; 1≤q≤200001\le q\le 20000; Every row has exactly nn characters from {., *}; 1≤y,x≤n1\le y,x\le n, 1≤y1≤y2≤n1\le y_1\le y_2\le n, 1≤x1≤x2≤n1\le x_1\le x_2\le n.
  • Subtask 4 (40 points): 1≤n≤10001\le n\le 1000; 1≤q≤2000001\le q\le 200000; Every row has exactly nn characters from {., *}; 1≤y,x≤n1\le y,x\le n, 1≤y1≤y2≤n1\le y_1\le y_2\le n, 1≤x1≤x2≤n1\le x_1\le x_2\le n.

Examples

Input

4 3
.*..
*.**
**..
****
2 2 2 3 4
1 3 3
2 2 2 3 4

Output

3
4

Explanation

Initially the rectangle from (2,2)(2,2) to (3,4)(3,4) contains 33 trees. Cell (3,3)(3,3) was empty and the update toggles it to a tree. The subsequent query returns 44.