显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
short n,m[1501][1501],c[1500][1500],q,a,b;
short x,y;
int ans;
char ch;
short f(short w,short z){
if( w==n || z==n ) return m[w][z];
else if(m[w][z]) return f(w,z+1);
else return f(w+1,z);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
freopen("zunxun.in","r",stdin);
freopen("zunxun.out","w",stdout);
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>ch;
if(ch=='R') m[i][j]=1;
}
cin>>m[i][n];
}
for(int i=0;i<n;i++){
cin>>m[n][i];
}
while(x<n){
while(y<n){
c[x][y]=f(x,y);
ans+=c[x][y];
y++;
}
x++;
y=0;
}
cout<<ans<<endl;
cin>>q;
while(q--){
ans=0;
cin>>a>>b;
a--;
b--;
m[a][b]=!m[a][b];
x=0;
while(x<n){
while(y<n){
c[x][y]=f(x,y);
ans+=c[x][y];
y++;
}
x++;
y=0;
}
cout<<ans<<endl;
}
return 0;
}