結果

問題 No.1758 Lazy Segment Tree...?
ユーザー chocoruskchocorusk
提出日時 2021-11-20 18:11:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 8,000 ms
コード長 1,972 bytes
コンパイル時間 3,463 ms
コンパイル使用メモリ 188,796 KB
実行使用メモリ 20,112 KB
最終ジャッジ日時 2023-09-02 14:03:35
合計ジャッジ時間 6,313 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,856 KB
testcase_01 AC 8 ms
20,000 KB
testcase_02 AC 8 ms
19,808 KB
testcase_03 AC 8 ms
19,800 KB
testcase_04 AC 8 ms
19,804 KB
testcase_05 AC 8 ms
19,804 KB
testcase_06 AC 8 ms
19,796 KB
testcase_07 AC 8 ms
19,864 KB
testcase_08 AC 8 ms
19,800 KB
testcase_09 AC 8 ms
19,868 KB
testcase_10 AC 8 ms
19,864 KB
testcase_11 AC 8 ms
19,992 KB
testcase_12 AC 8 ms
19,868 KB
testcase_13 AC 9 ms
19,852 KB
testcase_14 AC 8 ms
19,864 KB
testcase_15 AC 8 ms
19,808 KB
testcase_16 AC 8 ms
19,880 KB
testcase_17 AC 9 ms
19,808 KB
testcase_18 AC 9 ms
19,848 KB
testcase_19 AC 8 ms
19,812 KB
testcase_20 AC 8 ms
19,800 KB
testcase_21 AC 40 ms
20,080 KB
testcase_22 AC 36 ms
19,872 KB
testcase_23 AC 44 ms
19,852 KB
testcase_24 AC 41 ms
19,928 KB
testcase_25 AC 33 ms
19,864 KB
testcase_26 AC 44 ms
19,800 KB
testcase_27 AC 35 ms
19,812 KB
testcase_28 AC 46 ms
19,856 KB
testcase_29 AC 42 ms
19,796 KB
testcase_30 AC 52 ms
19,808 KB
testcase_31 AC 38 ms
19,812 KB
testcase_32 AC 43 ms
19,796 KB
testcase_33 AC 43 ms
19,856 KB
testcase_34 AC 41 ms
19,800 KB
testcase_35 AC 31 ms
19,936 KB
testcase_36 AC 54 ms
19,804 KB
testcase_37 AC 54 ms
20,112 KB
testcase_38 AC 54 ms
19,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}

int main()
{
    int n, q;
    cin>>n>>q;
    mint ans=0;
    // for(int i=0; i<n; i++){
    //     for(int j=i+1; j<n; j++){
    //         for(int k=0; k<q; k++){
    //             mint x=mint((ll)n*(n+1)).pow(q-k-1);
    //             mint y=mint((ll)n*(n+1)).pow(k);
    //             mint z=mint((ll)n*(n+1)-2*(ll)(j-i)*(n-j+i+1)).pow(k);
    //             ans+=x*(y-z)*(i+1)*(n-j);
    //         }
    //     }
    // }
    mint n0=mint((ll)n*(n+1)).pow(q-1);
    mint invt=mint((ll)n*(n+1)).inv();
    for(int i=0; i<n; i++){
        ans+=mint((ll)(n-i)*(n-i-1)/2)*mint(i+1)*mint(q)*n0;
    }
    mint z[200020];
    z[0]=n;
    for(int i=1; i<n; i++) z[i]=z[i-1]+mint(i+1)*mint(n-i);
    for(int d=1; d<n; d++){
        mint s=mint((ll)n*(n+1)-2*(ll)d*(n-d+1));
        mint u=s*invt;
        mint x;
        if(u.val()==1){
            x=n0*q;
        }else{
            x=n0*(1-u.pow(q))/(1-u);
        }
        mint v=z[n-d-1]-d*mint((ll)(n-d)*(n-d+1)/2);
        ans-=v*x;
    }
    ans/=2;
    ans/=2;
    cout<<ans.val()<<endl;
    return 0;
}
0