QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84104#5661. Multi-LaddersHOLIC#AC ✓2ms3628kbC++201.9kb2023-03-05 15:06:392023-03-05 15:06:42

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-05 15:06:42]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3628kb
  • [2023-03-05 15:06:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct mat{
    int a[2][2];
};
inline int ksm(int x, int y){
    int ans = 1;
    while(y){
        if(y & 1) ans = (1LL * ans * x) % mod;
        x = (1LL * x * x) % mod; y >>= 1;
    }
    return ans;
}
inline mat operator *(mat x, mat y){
    mat res;
    res.a[0][0] = res.a[0][1] = res.a[1][0] = res.a[1][1] = 0;
    for(int k = 0; k <= 1; ++k){
        for(int i = 0; i <= 1; ++i){
            for(int j = 0; j <= 1; ++j){
                int now = (1LL * x.a[i][k] * y.a[k][j]) % mod;
                res.a[i][j] = (res.a[i][j] + now) % mod;
            }
        }
    }
    return res;
}
inline mat ksm2(mat x, int y){
    mat ans;
    ans.a[0][0] = ans.a[1][1] = 1;
    ans.a[0][1] = ans.a[1][0] = 0;
    while(y){
        if(y & 1) ans = ans * x;
        x = x * x; y >>= 1;
    }
    return ans;
}
int main(){
    int T;
    scanf("%d", &T);
    while(T --){
        int n, k, r;
        scanf("%d%d%d", &n, &k, &r);
        if(r == 1 || r == 0){
            puts("0");
            continue;
        }
        int bs = (1LL * (r - 2) * (r - 2)) % mod;
        bs = (bs + (r - 1)) % mod;
        int al = (1LL * k * (n - 1)) % (mod - 1);
        bs = ksm(bs, al);
        if(k == 3){
            int now = (1LL * r * (r - 1)) % mod;
            now = (1LL * now * (r - 2)) % mod;
            now = (1LL * now * bs) % mod;
            printf("%d\n", now);
        }else{
            mat x;
            x.a[0][0] = 0, x.a[0][1] = r - 1, x.a[1][0] = 1, x.a[1][1] = r - 2;
            x = ksm2(x, k - 2);
            int a = (1LL * r * (r - 1)) % mod, b = (1LL * r * (r - 1)) % mod;
            b = (1LL * b * (r - 2)) % mod;
            int ans = (1LL * a * x.a[0][0]) % mod;
            ans = (ans + ((1LL * b * x.a[1][0]) % mod)) % mod;
            ans = (1LL * ans * bs) % mod;
            printf("%d\n", ans);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3628kb

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