QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548825#5661. Multi-Laddersskrghariapa#AC ✓0ms3656kbC++202.3kb2024-09-05 21:16:232024-09-05 21:16:24

Judging History

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

  • [2024-09-05 21:16:24]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3656kb
  • [2024-09-05 21:16:23]
  • 提交

answer

#include <bits/stdc++.h>
#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>

using namespace std;
// t2
#define gc getchar_unlocked
#define pii pair<long long, long long>
using ll = long long;
using cd = complex<double>;

const ll maxN = 1e6 + 10, maxM = 2e5 + 10, MAX = 2e6 + 10;
//const ll maxScore = 4294967295;
const ll mod = 1e9 + 7;
const double pi = acos(-1.0);
const double PI = acos(-1.0);
const double e = exp(1.0);
const ll naught = -100001;
const ll maxT = ceil(sqrt(maxN)) + 1;
const ll root_rec = 15311432;
const ll root_1 = 469870224;
const ll root_pw = (1 << 23);
const int K = 20;
const int g = 3;
const int LOGN = 20;
const int num1 = 16;
const int INF = 1e9;
//const ll is_query = -(1LL<<62)

template <typename T> void fastInt(T& angka) {
    T kali = 1; angka = 0; char input = gc();
    while (!isdigit(input)) { if (input == '-') kali = -1; input = gc(); }
    while (isdigit(input)) angka = (angka << 3) + (angka << 1) + input - 48, input = gc();
    angka *= kali;
}

void fastStr(string& str) {
    str = "";
    char c = '0';
    while ((c = gc()) && (c != -1 && c != '\n' && c != '\t' && c != '\r' && c != ' ')) {
        str += c;
    }
}

ll powMod(ll x, ll y, ll p){
    ll res = 1;
    x %= p;
    if(!x) return 0;
    while (y > 0){
        if (y & 1) res = ((res % p) * (x % p)) % p;
        y = y >> 1;
        x = ((x % p) * (x % p)) % p;
    }
    return res % p;
}

ll inverseMod(ll x, ll p){
    return powMod(x, p - 2, p);
}

void solve(){
    ll n, k, l;
    fastInt(n); fastInt(k); fastInt(l);
    if(l <= 1){
        cout << "0\n";
        return;
    }
    ll u = l * l - 3 * l + 3;
    ll powB = (n - 1) * k;
    ll base = powMod(u, powB, mod);
    ll oth = powMod(l - 1, k, mod);
    ll sgn = 1;
    if(k & 1){
        sgn = -1;
    }
    oth = (oth + mod + sgn * (l - 1)) % mod;
    ll ans = (oth * base) % mod;
    cout << ans << '\n';
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.precision(10);
    //auto beg = high_resolution_clock::now();
    //cout << req(1e7 + 8) << '\n';
    //precalc();
    int t; fastInt(t);
    while(t--) solve();
    //auto en = high_resolution_clock::now();
    //auto dur = duration_cast<microseconds>(en - beg);
    //cout << dur.count() << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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