思路:key[k][k]*key[k][k],其他的都会有2次,相互抵消。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
#define maxn 1080
int key[maxn][maxn];
int main()
{
//freopen("in.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++)
scanf("%d",&key[i][j]);
int ans = 0;
for(int i = 1;i <= n;i++) ans += key[i][i];
ans %= 2;
int m; scanf("%d",&m);
while(m--)
{
int ope; scanf("%d",&ope);
if(ope == 3) printf("%d",ans%2);
else
{
int k; scanf("%d",&k);
ans ^= 1;
key[k][k] = 1 - key[k][k];
}
}
puts("");
}
return 0;
}