QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553751#5661. Multi-LaddersBongoCatEnjoyer#AC ✓0ms3632kbC++206.3kb2024-09-08 19:22:522024-09-08 19:22:52

Judging History

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

  • [2024-09-08 19:22:52]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3632kb
  • [2024-09-08 19:22:52]
  • 提交

answer

#include <bits/stdc++.h>

#define ll                      long long
#define all(v)                  (v).begin(), (v).end()
#define forn(var, n)            for (ll (var) = 0; (var) < (n); ++(var))
#define forr(var, start, end)   for (ll (var) = (start); (var) < (end); ++(var))
#define fori(var, start, end)   for (ll (var) = (start); (var) > (end); --(var))
#define fora(var, obj)          for (auto (var) : (obj))
#define MOD1                    (ll) (1e9 + 7)
#define MOD9                    (ll) (998244353)
#define prints(x)               cout << (x) << " "
#define println(x)              cout << (x) << "\n"
#define newl()                  cout << "\n"

using namespace std;

template <int P>
struct MInt {
    int val;

    MInt(long long v = 0) {
        val = (v % P + P) % P;
    }

    constexpr MInt& operator=(const MInt& other) {
        val = other.val;
        return *this;
    }

    constexpr MInt operator+(const MInt& other) const { return MInt(*this) += other; }
    constexpr MInt operator-(const MInt& other) const { return MInt(*this) -= other; }
    constexpr MInt operator*(const MInt& other) const { return MInt(*this) *= other; }
    constexpr MInt operator/(const MInt& other) const { return MInt(*this) /= other; }
    constexpr MInt operator-() const { return MInt(-val); }

    constexpr MInt& operator+=(const MInt& other) {
        val += other.val;
        if (val >= P) val -= P;
        return *this;
    }

    constexpr MInt& operator-=(const MInt& other) {
        val -= other.val;
        if (val < 0) val += P;
        return *this;
    }

    constexpr MInt& operator*=(const MInt& other) {
        val = (long long)val * other.val % P;
        return *this;
    }

    constexpr MInt& operator/=(const MInt& other) {
        return *this *= other.inv();
    }

    friend constexpr MInt operator+(long long v, const MInt& m) { return m + v; }
    friend constexpr MInt operator-(long long v, const MInt& m) { return -m + v; }
    friend constexpr MInt operator*(long long v, const MInt& m) { return m * v; }
    friend constexpr MInt operator/(long long v, const MInt& m) { return MInt(v) / m; }

    constexpr bool operator==(const MInt& other) const { return val == other.val; }
    constexpr bool operator!=(const MInt& other) const { return val != other.val; }
    constexpr bool operator<(const MInt& other) const { return val < other.val; }
    constexpr bool operator>(const MInt& other) const { return val > other.val; }
    constexpr bool operator<=(const MInt& other) const { return val <= other.val; }
    constexpr bool operator>=(const MInt& other) const { return val >= other.val; }
    
    constexpr MInt inv() const {
        assert(gcd(val, P) == 1);
        return pow(P - 2);
    }

    constexpr MInt pow(long long p) const {
        if (p < 0) return inv().pow(-p);

        MInt res = 1, a = val;
        while (p > 0) {
            if (p & 1) res *= a;
            a *= a;
            p >>= 1;
        }
        return res;
    }

    friend istream& operator>>(istream& in, MInt& m) {
        long long v;
        in >> v;
        m = MInt(v);
        return in;
    }

    friend ostream& operator<<(ostream& out, const MInt& m) {
        return out << m.val;
    }
};

template <long long P>
struct MLong {
    long long val;

    MLong(long long v = 0) {
        val = (v % P + P) % P;
    }

    constexpr MLong& operator=(const MLong& other) {
        val = other.val;
        return *this;
    }

    constexpr MLong operator+(const MLong& other) const { return MLong(*this) += other; }
    constexpr MLong operator-(const MLong& other) const { return MLong(*this) -= other; }
    constexpr MLong operator*(const MLong& other) const { return MLong(*this) *= other; }
    constexpr MLong operator/(const MLong& other) const { return MLong(*this) /= other; }
    constexpr MLong operator-() const { return MLong(-val); }

    constexpr MLong& operator+=(const MLong& other) {
        val += other.val;
        if (val >= P) val -= P;
        return *this;
    }

    constexpr MLong& operator-=(const MLong& other) {
        val -= other.val;
        if (val < 0) val += P;
        return *this;
    }

    constexpr MLong& operator*=(const MLong& other) {
        val = (long long)val * other.val % P;
        return *this;
    }

    constexpr MLong& operator/=(const MLong& other) {
        return *this *= other.inv();
    }

    friend constexpr MLong operator+(long long v, const MLong& m) { return m + v; }
    friend constexpr MLong operator-(long long v, const MLong& m) { return -m + v; }
    friend constexpr MLong operator*(long long v, const MLong& m) { return m * v; }
    friend constexpr MLong operator/(long long v, const MLong& m) { return MLong(v) / m; }

    constexpr bool operator==(const MLong& other) const { return val == other.val; }
    constexpr bool operator!=(const MLong& other) const { return val != other.val; }
    constexpr bool operator<(const MLong& other) const { return val < other.val; }
    constexpr bool operator>(const MLong& other) const { return val > other.val; }
    constexpr bool operator<=(const MLong& other) const { return val <= other.val; }
    constexpr bool operator>=(const MLong& other) const { return val >= other.val; }

    constexpr MLong inv() const {
        return pow(P - 2);
    }

    constexpr MLong pow(long long p) const {
        if (p < 0) return inv().pow(-p);
        
        MLong res = 1, a = val;
        while (p > 0) {
            if (p & 1) res *= a;
            a *= a;
            p >>= 1;
        }
        return res;
    }

    friend istream& operator>>(istream& in, MLong& m) {
        long long v;
        in >> v;
        m = MLong(v);
        return in;
    }

    friend ostream& operator<<(ostream& out, const MLong& m) {
        return out << m.val;
    }
};

using Z = MInt<MOD1>;

Z cyc(ll sz, ll col) {
    if (sz == 1) return Z(col);

    Z ret = Z(col - 1).pow(sz);
    if (sz % 2) return ret - col + 1;
    else return ret + col - 1;
}

void solve() {
    ll n, k, m; cin >> n >> k >> m;
    println(Z(Z(m - 2) * (m - 1) + 1).pow(n - 1).pow(k) * cyc(k, m));
    return;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t = 1;
    cin >> t;
    while (t--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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