QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85315#5661. Multi-LadderspiasticOuOAC ✓2ms3408kbC++141.4kb2023-03-07 15:56:482023-03-07 15:56:52

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 15:56:52]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3408kb
  • [2023-03-07 15:56:48]
  • 提交

answer

#include <iostream>
using namespace std;
const int mo = 1e9 + 7;
int T;
long long n, k, u;
long long Ln, ans;

struct Matrix {
	int numH, numL;
	long long a[5][5] = {0};

	Matrix operator*(Matrix mt) {
		Matrix res;
		res.numL = numL;
		res.numH = mt.numH;
		for (int i = 1; i <= res.numL; ++i) {
			for (int j = 1; j <= res.numH; ++j) {
				for (int k = 1; k <= numH; ++k) {
					res.a[i][j] = (res.a[i][j] + a[i][k] * mt.a[k][j]) % mo;
				}
			}
		}
		return res;
	}

};

Matrix Omt, Emt;

long long qc(long long x, long long y) {
	long long res = 1;
	while (y) {
		if (y & 1)
			res = res * x % mo;
		x = x * x % mo;
		y >>= 1;
	}
	return res;
}

Matrix mtqc(Matrix a, long long x) {
	Matrix res = Emt;
	while (x) {
		if (x & 1)
			res = res * a;
		a = a * a;
		x >>= 1;
	}
	return res;
}

void solve() {
	cin >> n >> k >> u;
	long long d = ((u - 2) * (u - 2) - 1 + u) % mo;		//һ\xb8\xf6\xc6\xe6\xc3\xee\xb5ij\xa3\xca\xfd
	Ln = qc(d, k * (n - 1));

	Omt.numH = Omt.numL = 2;
	Omt.a[1][1] = u - 2, Omt.a[1][2] = u - 1;
	Omt.a[2][1] = 1, Omt.a[2][2] = 0;

	Matrix fmt = mtqc(Omt, k - 2);

	long long c = u * (u - 1) % mo * fmt.a[1][1] % mo;
	ans = c * Ln % mo;
	cout << ans << '\n';
}

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	Emt.numH = Emt.numL = 2;
	Emt.a[1][1] = Emt.a[2][2] = 1;		//2*2\xb5\xa5λ\xbe\xd8\xd5\xf3

	cin >> T;

	while (T--) {
		solve();
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3396kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3408kb

input:

20
2 3 3
1 3 3
10 3 0
10 3 2
1 21 2
1 22 0
2000 15000 2000
12000 30000 200000
1000000000 3 3
2 1000000000 3
2 3 100000000
1000000000 1000000000 10
1000000000 3 100000000
2 1000000000 100000000
1 1000000000 10
1 1000000000 100000000
1 1000 100000000
1000000000 1000000000 0
1000000000 1000000000 1
100...

output:

162
6
0
0
0
0
349400141
243010659
52489881
53690844
176686901
218103365
558243892
991895211
693053429
883715672
80402569
0
0
311752813

result:

ok 20 lines