奇怪
查看原帖
奇怪
533854
CodingShark楼主2023/12/5 21:02

本来想先写个朴素的 O(n3qlog⁡n)O(n^3q\log n) 的快速幂的,T 了 8 个点。

结果把 #define int long long 改成 #define int unsigned int 就过了,这绝对是最朴素的快速幂,是数据的问题还是我代码的问题?

#include <bits/stdc++.h>
using namespace std;
#define int unsigned int
struct MAT {
	int a[105][105];
	MAT() { memset(a, 0, sizeof a); }
	int* operator[](int x) { return a[x]; }
	MAT operator*(MAT b) const {
		MAT mas;
		for (int i = 1; i <= 100; i++)
			for (int j = 1; j <= 100; j++)
				for (int k = 1; k <= 100; k++)
					mas[i][j] ^= a[i][k] * b[k][j];
		return mas;
	}
	MAT operator^(int y) const {
		MAT mas, base;
		for (int i = 1; i <= 100; i++) mas[i][i] = 1;
		for (int i = 1; i <= 100; i++)
			for (int j = 1; j <= 100; j++)
				base[i][j] = a[i][j];
		while (y) {
			if (y & 1) mas = mas * base;
			base = base * base, y >>= 1;
		} return mas;
	}
} f, st, t;
int n, m, q;
signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++) cin >> st[1][i];
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		f[u][v] = f[v][u] = 1;
	}
	while (q--) {
		int x;
		cin >> x;
		t = f ^ x;
		cout << (st * t)[1][1] << "\n";
	}
	return 0;
}
2023/12/5 21:02
加载中...