QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468490#8339. Rooted Treereal_sigma_team#TL 178ms3676kbC++201.7kb2024-07-08 21:05:572024-07-08 21:05:57

Judging History

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

  • [2024-07-08 21:05:57]
  • 评测
  • 测评结果:TL
  • 用时:178ms
  • 内存:3676kb
  • [2024-07-08 21:05:57]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi2,fma,popcnt")


#ifdef lisie_bimbi
#define debug(x) cout << #x << " : " << x << endl;
#else
#define endl '\n'
#endif


#define int long long
#define inf 1000000000000000000
#define double long double
typedef long long ll;

int mod = 1000000009;

int add(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}

int sub(int a, int b) {
    return a >= b ? a - b : a + mod - b;
}

int mul(int a, int b) {
    return (int)a * b % mod;
}

int binpow(int a, int b){
    if(b == 0){
        return 1;
    }
    int ans = binpow(a, b / 2);
    ans = mul(ans, ans);
    if(b % 2 == 1){
        ans = mul(ans, a);
    }
    return ans;
}

int del(int a, int b){
    return mul(a, binpow(b, mod - 2));
}

signed main() {
#ifdef lisie_bimbi
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#endif
    int m, k;
    cin >> m >> k;
    int d = 0;
    int cnt = 1;
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans = add(ans, mul(m, add(d, 1)));
        //cout << "aaaaaa\n";
        //cout << ans << " " << cnt << " " << m << " " << sub(add(cnt, m), 1) << endl;
        d = del(add(mul(sub(cnt, 1), d), mul(m, add(d, 1))), sub(add(cnt, m), 1));
        //cout << d << endl;
        cnt = add(cnt, m - 1);
    }
    cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 178ms
memory: 3676kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Time Limit Exceeded

input:

48 6713156

output:


result: