Meaning of the questions: to give you a matrix of n * m left to right you can only operate with the lower deck there are two q times one is asked to flip a unit (you can not go walking becomes unavailable become available go away) another is to ask from (1, x) come (n, y) how many programs
Ideas: Title 1e5 and n is only 10 m we can consider the tree line segment to maintain a m * m matrix analog matrix multiplication when the time is equivalent to the number of computing solutions (to manually simulate what) modify the operation is equivalent to a single point update then re-structure matrix
#include <bits/stdc++.h> using namespace std; const int N = 5e4+7; const int inf = 0x3f3f3f3f; typedef long long ll; const ll mod = 1e9+7; ll a[N][12]; int n,m,q; struct matrix{ int l,r; ll ma[12][12]; }; matrix t[N<<2]; void pushup(int p){ memset(t[p].ma,0,sizeof(t[p].ma)); for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) for(int k=1;k<=m;k++){ t[p].ma[i][j]=(t[p].ma[i][j]+((t[p<<1].ma[i][k]%mod)*(t[p<<1|1].ma[k][j]%mod))%mod)%mod; } } void work(int p,int l){ memset(t[p].ma,0,sizeof(t[p].ma)); for(int i=1;i<=m;i++){ int pos=i; while(pos>=1&&a[l][pos]==0){ t[p].ma[i][pos]=1; pos--; } pos=i; while(pos<=m&&a[l][pos]==0){ t[p].ma[i][pos]=1; pos++; } } } void build(int p,int l,int r){ t[p].l=l; t[p].r=r; if(l==r){ work(p,l); return ; } int mid=(l+r)>>1; build(p<<1,l,mid); build(p<<1|1,mid+1,r); pushup(p); } void update(int p,int x){ if(t[p].l==t[p].r){ work(p,t[p].l); return ; } int mid=(t[p].l+t[p].r)>>1; if(x<=mid) update(p<<1,x); else update(p<<1|1,x); pushup(p); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m>>q; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ char b; cin>>b; a[i][j]=(b!='0'); } } build(1,1,n); for(int i=1;i<=q;i++){ int z,x,y; cin>>z>>x>>y; if(z==1){ a[x][y]^=1; update(1,x); }else{ cout<<t[1].ma[x][y]<<"\n"; } } return 0; }