-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1739.cpp
55 lines (51 loc) · 1.06 KB
/
1739.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, q, fen[N][N];
char mat[N][N];
void add(int x, int y, int v) {
for (; x < N; x += x & -x) {
for (int ty = y; ty < N; ty += ty & -ty) {
fen[x][ty] += v;
}
}
}
int get(int x, int y) {
int v = 0;
for (; x > 0; x -= x & -x) {
for (int ty = y; ty > 0; ty -= ty & -ty) {
v += fen[x][ty];
}
}
return v;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> mat[i][j];
if (mat[i][j] == '*') {
add(i, j, 1);
}
}
}
while (q--) {
int t; cin >> t;
if (t == 1) {
int x, y; cin >> x >> y;
if (mat[x][y] == '.') {
add(x, y, 1);
mat[x][y] = '*';
} else {
add(x, y, -1);
mat[x][y] = '.';
}
} else {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << get(x2, y2) - get(x2, y1 - 1) - get(x1 - 1, y2) + get(x1 - 1, y1 - 1) << "\n";
}
}
return 0;
}