0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 12:58:48 +00:00

P6569 [NOI Online #3 提高组] 魔法值

https://www.luogu.com.cn/record/102618970
This commit is contained in:
Baoshuo Ren 2023-02-20 21:16:51 +08:00
parent 60e8368d36
commit 8eaf5442ec
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 94 additions and 0 deletions

88
Luogu/P6569/P6569.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
struct Matrix : public std::vector<std::vector<long long>> {
int n, m;
Matrix(const int &_n = 0, const int &_m = 0)
: std::vector<std::vector<long long>>(_n, std::vector<long long>(_m)),
n(_n),
m(_m) {}
Matrix(const Matrix &_matrix)
: std::vector<std::vector<long long>>(_matrix), n(_matrix.n), m(_matrix.m) {}
Matrix operator=(const Matrix &_matrix) {
std::vector<std::vector<long long>>::operator=(_matrix);
n = _matrix.n;
m = _matrix.m;
return *this;
}
Matrix operator^(Matrix rhs) {
Matrix res(n, rhs.m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < rhs.m; ++j) {
res[i][j] = 0;
for (int k = 0; k < m; ++k) {
res[i][j] ^= (*this)[i][k] * rhs[k][j];
}
}
}
return res;
}
};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
std::vector<long long> a;
cin >> n >> m >> q;
std::copy_n(std::istream_iterator<long long>(cin), n, std::back_inserter(a));
std::vector<Matrix> g;
g.emplace_back(n, n);
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
u--, v--;
g[0][u][v] = g[0][v][u] = 1;
}
for (int i = 1; i <= 32; i++) {
g.emplace_back(g.back() ^ g.back());
}
while (q--) {
long long x;
cin >> x;
Matrix f(1, n);
f[0] = a;
for (long long w = 1, i = 0; w <= x; w <<= 1, i++) {
if (x & w) f = f ^ g[i];
}
cout << f[0][0] << endl;
}
return 0;
}

BIN
Luogu/P6569/data/P6569_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P6569/data/P6569_2.out (Stored with Git LFS) Normal file

Binary file not shown.