81 lines
1.9 KiB
C++
81 lines
1.9 KiB
C++
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
// ----- FILE IO -----
|
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
|
#define NL '\n'
|
|
|
|
// ----- FOR LOOPS -----
|
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
|
|
|
// ----- WEZ -----
|
|
#define takeI(n) int (n); cin >> n
|
|
#define takeII(n,m) int (n),(m); cin >> n >> m
|
|
#define takeIII(n,m,k) int (n),(m),(k); cin >>(n) >> (m) >> (k)
|
|
#define whileZ takeI(T); while(T--)
|
|
//
|
|
// ----- MAX MIN -----
|
|
#define REMAX(a,b) (a)=max((a),(b))
|
|
#define REMIN(a,b) (a)=min((a),(b))
|
|
|
|
// ----- DEBUG -----
|
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
|
#define printV(a) printA(a,0,a.size()-1)
|
|
|
|
// ----- STL DS
|
|
#define ALL(c) (c).begin(),(c).end()
|
|
|
|
int changesNeeded(int groupVal) {
|
|
if (groupVal < 3) {
|
|
return groupVal;
|
|
}
|
|
return 4 - groupVal;
|
|
}
|
|
|
|
int fold(int x, int n) {
|
|
return x >= n ? x - n : n - 1 - x;
|
|
}
|
|
|
|
int main() {
|
|
takeII(n, u);
|
|
int n2 = n / 2;
|
|
|
|
vector<vector<int>> group(n2, vector<int>(n2));
|
|
vector<vector<bool>> canvas(n, vector<bool>(n));
|
|
|
|
F(i, 0, n) {
|
|
F(j, 0, n) {
|
|
char ch;
|
|
cin >> ch;
|
|
canvas[i][j] = (ch == '#');
|
|
int xx = fold(i,n2), yy = fold(j, n2);
|
|
if (canvas[i][j]) group[xx][yy] += 1;
|
|
}
|
|
}
|
|
|
|
int res = 0;
|
|
F(i, 0, n2) F(j, 0, n2) res += changesNeeded(group[i][j]);
|
|
cout << res << NL;
|
|
|
|
F(i, 0, u) {
|
|
takeII(x, y);
|
|
x--; y--;
|
|
int xx = fold(x,n2), yy = fold(y, n2);
|
|
|
|
res -= changesNeeded(group[xx][yy]);
|
|
if (canvas[x][y]) group[xx][yy]--;
|
|
else group[xx][yy]++;
|
|
canvas[x][y] = !canvas[x][y];
|
|
res += changesNeeded(group[xx][yy]);
|
|
cout << res << NL;
|
|
}
|
|
}
|