只会暴力,答案没看懂,呜呜呜。乘的时候还乱七八糟的。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#define ls (u<<1)
#define rs (u<<1|1)
#define mid (l+r>>1)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1000, mod = 1e9 + 7;bitset<N> a[31][N], b;
void inverse(bitset<N> &a);
void prin(bitset<N> a[]);int n, m;void mull(bitset<N> a[], bitset<N> b[])
{bitset<N> c[N];for(int i = 0;i < m;i ++)for(int j = 0;j < m;j ++)c[i][j] = b[m-1-j][i];
// prin(b);prin(c);cout<<" --- ";for(int i = 0;i < m;i ++)for(int j = 0;j < m;j ++)a[i][j] = (b[i]&c[j]).count()&1;
}
void mull(bitset<N> &a, bitset<N> b[])
{bitset<N> c;for(int i = 0;i < m;i ++) c[m-1-i] = (b[i]&a).count()&1;a = c;
}int main()
{scanf("%d", &m);string c;for(int i = 0;i < m;i ++) inverse(a[0][i]); inverse(b);for(int i = 1;i < 31;i ++) mull(a[i], a[i-1]);scanf("%d", &n);while(n --){int k, f = 0;bitset<N> ans = b;scanf("%d", &k);while(k){if(k&1)mull(ans, a[f]);f++; k >>= 1;}for(int i = m-1;i >= 0;i --)cout<<ans[i];cout<<endl;}return 0;
}void inverse(bitset<N> &a){string c;cin>>c;for(int i = 0;i < c.size();i ++)a[i] = c[c.size()-1-i]-'0';}
void prin(bitset<N> a[]){puts("");for(int i = 0;i < m;i ++)cout<<a[i]<<endl;puts("");}