提交时间:2024-10-04 16:10:53

运行 ID: 33162

#include<bits/stdc++.h> using namespace std; #define ll long long #define r register const int mod=1e9+7,tim=2e6+10,B=300; int n,m,t; int tg[tim]; int e[80][80]; struct mat{ int h,w;int v[80][80]; mat operator*(const mat &b) const{ mat res;res.h=h;res.w=b.w; for(int i=1;i<=res.h;i++){ for(int j=1;j<=res.w;j++){ ll dc=0; for(int k=1;k<=w;k++){ dc+=(long long)b.v[k][j]*v[i][k]%mod; }res.v[i][j]=dc%mod; } }return res; } }; inline int get(mat a,mat b){ ll res=0;int w=a.w; for(int i=1;i<=w;i++){ res+=(long long)a.v[1][i]*b.v[i][n]%mod; }return res%mod; } inline int qp(int a,int b){ int x=1; while(b){ if(b&1) x=1ll*a*x%mod; b>>=1;a=1ll*a*a%mod; }return x; }inline int g(int x){ return qp(x,mod-2); }int du[80]; mat a[B+20]; inline char readchar(){ char ch=getchar(); while(ch!='0'&&ch!='1') ch=getchar(); return ch; } int main(){ freopen("citywalk.in","r",stdin); freopen("citywalk.out","w",stdout); double C=clock(); cin>>n>>m>>t; for(int i=1;i<=n;i++){ //string s;cin>>s;s=' '+s; for(int j=1;j<=n;j++){ e[i][j]=readchar()-'0'; if(e[i][j]) du[i]++; } }for(int i=1;i<=m;i++){ int ti,vi;scanf("%d%d",&ti,&vi); tg[ti]=vi; }mat st,to,I;st.h=1,st.w=n;to.h=n,to.w=n;I.h=n,I.w=n; for(int i=1;i<=n;i++) st.v[1][i]=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(e[i][j]) to.v[i][j]=g(du[i]); else to.v[i][j]=0; I.v[i][j]=(i==j); //cout<<i<<' '<<j<<' '<<I.v[i][j]<<endl; } }a[0]=I; a[1]=to; cerr<<(clock()-C)/CLOCKS_PER_SEC<<' '; for(int i=2;i<=B+3;i++){ a[i]=a[i-1]*to; }cerr<<(clock()-C)/CLOCKS_PER_SEC<<' '; int ans=0; int lp=1;int cnt=0; while(lp<=t){ int dt=0;//cout<<lp<<' '; int lim=min(B,t-lp); while(dt<=lim&&tg[lp+dt]==0){ ll res=0;int w=st.w; for(r int i=1;i<=st.w;i++){ res+=(long long)st.v[1][i]*a[dt].v[i][n]%mod; }ans^=res%mod; //ans^=get(st,a[dt]); dt++; //cout<<get(st,a[0],n)<<' '; }//cout<<dt<<' '; st=st*a[dt];cnt++;lp=lp+dt; if(tg[lp]){ st.v[1][tg[lp]]++;tg[lp]=0; //ans^=st.v[1][n];lp++;st=st*to;cnt++; continue; } }cerr<<(clock()-C)/CLOCKS_PER_SEC<<' '; //cout<<cnt<<' '; cout<<ans; return 0; }