题意:
https://acm.taifua.com/bzoj/p/4644.html
思路:
找不到题,也没法交,bzoj也时好时坏,但是思路有就行了
其实线性基因为一次插入只有一个赋值操作也可以用同样的方式撤销,不一定要每次都复制一遍下传(注意是撤销不是删除哦~
https://www.cnblogs.com/tusikalanse/p/11345944.html(到位了
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<bitset> 5 #include<vector> 6 #define ML 1000 7 using namespace std; 8 inline int read() 9 { 10 int x = 0 , f = 1; char ch = getchar(); 11 while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar();} 12 while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();} 13 return x * f; 14 } 15 16 int n,m,last[505]; 17 struct node{int l,r;vector<bitset<1002> >s;vector<int>p;}T[4005]; 18 bitset<1002> s[4005],now; 19 char st[1005]; 20 21 void build(int x,int l,int r) 22 { 23 if((T[x].l=l)==(T[x].r=r))return; 24 int mid=l+r>>1; 25 build(x<<1,l,mid);build(x<<1|1,mid+1,r); 26 } 27 28 void ins(int x,int l,int r,bitset<1002>&b) 29 { 30 // cout<<"ins"<<x<<" "<<l<<" "<<r<<endl; 31 if(T[x].l==l&&T[x].r==r){T[x].s.push_back(b);return;} 32 int mid=(T[x].l+T[x].r)>>1; 33 if(r<=mid) ins(x<<1,l,r,b); 34 else if(l>mid) ins(x<<1|1,l,r,b); 35 else {ins(x<<1,l,mid,b);ins(x<<1|1,mid+1,r,b);} 36 } 37 38 void dfs(int x) 39 { 40 // cout<<"dfs"<<x<<endl; 41 for(int i=0;i<T[x].s.size();i++) 42 { 43 for(int j=1;j<=ML;j++) 44 { 45 if(T[x].s[i][j]) 46 { 47 if(!s[j][j]) 48 { 49 s[j]=T[x].s[i]; 50 T[x].p.push_back(j); 51 break; 52 } 53 else T[x].s[i]^=s[j]; 54 } 55 } 56 } 57 if(T[x].l!=T[x].r) dfs(x<<1),dfs(x<<1|1); 58 else 59 { 60 now.reset(); 61 for(int i=1;i<=ML;i++) 62 if(s[i][i]&&!now[i]) 63 now^=s[i]; 64 int j=1; 65 for(;j<=ML&&!now[j];j++); 66 67 if(j>ML) printf("0"); 68 else for(;j<=ML;j++) printf("%d",now[j]?1:0); 69 puts(""); 70 } 71 for(int i=0;i<T[x].p.size();i++) 72 s[T[x].p[i]].reset(); 73 } 74 75 int main() 76 { 77 read();n=read();m=read(); 78 build(1,1,m); 79 for(int i=1;i<=m;i++) 80 { 81 int u=read(),v=read(); 82 scanf("%s",st+1);if(u==v) continue; 83 int len=strlen(st+1);now.reset(); 84 for(int j=1;j<=len;j++) 85 now[ML-len+j]=st[j]=='1'?1:0; 86 if(last[u])ins(1,last[u],i-1,s[u]);last[u]=i; 87 if(last[v])ins(1,last[v],i-1,s[v]);last[v]=i; 88 s[u]^=now;s[v]^=now; 89 } 90 for(int i=1;i<=n;i++) 91 if(last[i]<=m&&last[i]) 92 ins(1,last[i],m,s[i]); 93 for(int i=1;i<=n;i++)s[i].reset(); 94 dfs(1); 95 return 0; 96 }