QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657134#5661. Multi-Laddersucup-team5226#AC ✓1ms3652kbC++141.4kb2024-10-19 14:14:482024-10-19 14:14:55

Judging History

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

  • [2024-10-19 14:14:55]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3652kb
  • [2024-10-19 14:14:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using str = string;
#define reps(i, a, n) for (ll i = (a); i < ll(n); i++)
#define rep(i, n) reps(i, 0, n)

constexpr ll MOD = ll(1e9) + 7;
ll pow_mod(ll x, ll n) {
    assert(n >= 0);
    assert(n <= (1LL << 40));
    ll r = 1;
    x %= MOD;
    while (n) {
        if (n & 1) r = (r * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return r;
}

void solve() {
    ll n, k, l;
    cin >> n >> k >> l;
    vector<vector<vector<ll>>> mat(40, vector<vector<ll>>(2, vector<ll>(2)));
    mat[0][0][1] = 1;
    mat[0][1][0] = l - 1;
    mat[0][1][1] = l - 2;
    auto mul = [&](vector<vector<ll>> a, vector<vector<ll>> b) {
        vector<vector<ll>> res(2, vector<ll>(2));
        rep(i, 2) rep(j, 2) rep(k, 2) res[i][j] += a[i][k] * b[k][j], res[i][j] %= MOD;
        return res;
    };
    for (int i = 1; i < 40; i++) {
        mat[i] = mul(mat[i - 1], mat[i - 1]);
    }
    vector<vector<ll>> v(2, vector<ll>(2));
    v[0][0] = v[1][1] = 1;
    for (int i = 0; i < 40; i++)
        if ((k - 1) >> i & 1) v = mul(v, mat[i]);
    ll res = v[1][0] * l % MOD;
    ll val = ((l - 1) * (l - 1) % MOD - (l - 2) + MOD) % MOD;
    val = pow_mod(val, n - 1);
    val = pow_mod(val, k);
    res = res * val % MOD;
    cout << res << endl;
}

int main() {
    ll t = 1;
    cin >> t;
    rep(i, t) solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3652kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3648kb

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