結果

問題 No.1696 Nonnil
ユーザー chocoruskchocorusk
提出日時 2021-10-02 17:45:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,236 ms / 3,500 ms
コード長 4,063 bytes
コンパイル時間 3,958 ms
コンパイル使用メモリ 205,824 KB
実行使用メモリ 91,264 KB
最終ジャッジ日時 2023-09-27 18:14:50
合計ジャッジ時間 30,454 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,192 KB
testcase_01 AC 7 ms
19,000 KB
testcase_02 AC 8 ms
19,032 KB
testcase_03 AC 615 ms
91,264 KB
testcase_04 AC 7 ms
18,992 KB
testcase_05 AC 7 ms
19,128 KB
testcase_06 AC 7 ms
18,992 KB
testcase_07 AC 7 ms
19,036 KB
testcase_08 AC 623 ms
91,100 KB
testcase_09 AC 58 ms
23,440 KB
testcase_10 AC 86 ms
24,528 KB
testcase_11 AC 51 ms
22,860 KB
testcase_12 AC 78 ms
24,356 KB
testcase_13 AC 51 ms
22,948 KB
testcase_14 AC 1,039 ms
86,488 KB
testcase_15 AC 141 ms
31,636 KB
testcase_16 AC 1,181 ms
91,088 KB
testcase_17 AC 932 ms
83,244 KB
testcase_18 AC 393 ms
41,440 KB
testcase_19 AC 7 ms
19,052 KB
testcase_20 AC 8 ms
19,008 KB
testcase_21 AC 724 ms
75,800 KB
testcase_22 AC 690 ms
74,280 KB
testcase_23 AC 612 ms
71,144 KB
testcase_24 AC 578 ms
69,044 KB
testcase_25 AC 905 ms
82,072 KB
testcase_26 AC 915 ms
82,980 KB
testcase_27 AC 1,142 ms
90,424 KB
testcase_28 AC 660 ms
71,896 KB
testcase_29 AC 815 ms
79,044 KB
testcase_30 AC 461 ms
43,696 KB
testcase_31 AC 997 ms
85,360 KB
testcase_32 AC 1,103 ms
88,532 KB
testcase_33 AC 757 ms
76,316 KB
testcase_34 AC 769 ms
77,384 KB
testcase_35 AC 857 ms
80,924 KB
testcase_36 AC 1,148 ms
91,100 KB
testcase_37 AC 1,159 ms
91,160 KB
testcase_38 AC 1,144 ms
91,096 KB
testcase_39 AC 1,131 ms
90,900 KB
testcase_40 AC 1,236 ms
90,796 KB
testcase_41 AC 222 ms
34,360 KB
testcase_42 AC 557 ms
86,276 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];
}
template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	using G=function<Monoid(Monoid, OperatorMonoid, int)>;
	using H=function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
	int sz;
	vector<Monoid> data;
	vector<OperatorMonoid> lazy;
	F f;
	G g;
	H h;
	Monoid e1;
	OperatorMonoid e0;

    LazySegmentTree(){}

	LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
		sz=1;
		while(sz<n) sz<<=1;
		data.resize(2*sz-1, e1);
		lazy.resize(2*sz-1, e0);
	}

    void init(int n, const F f1, const G g1, const H h1, const Monoid &e11, const OperatorMonoid &e01){
        f=f1,g=g1,h=h1,e1=e11,e0=e01;
        sz=1;
		while(sz<n) sz<<=1;
		data.resize(2*sz-1, e1);
		lazy.resize(2*sz-1, e0);
    }

	void build(vector<Monoid> v){
		for(int i=0; i<v.size(); i++) data[i+sz-1]=v[i];
		for(int i=sz-2; i>=0; i--) data[i]=f(data[2*i+1], data[2*i+2]);
	}

	void eval(int k, int l, int r){
		if(lazy[k]!=e0){
			data[k]=g(data[k], lazy[k], r-l);
			if(k<sz-1){
				lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
			}
		}
		lazy[k]=e0;
	}

	void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
		eval(k, l, r);
		if(r<=a || b<=l) return;
		if(a<=l && r<=b){
			lazy[k]=h(lazy[k], x);
			eval(k, l, r);
		}else{
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			data[k]=f(data[2*k+1], data[2*k+2]);
		}
	}
	void update(int a, int b, const OperatorMonoid &x){
		return update(a, b, x, 0, 0, sz);
	}

	Monoid find(int a, int b, int k, int l, int r){
		eval(k, l, r);
		if(b<=l || r<=a) return e1;
		if(a<=l && r<=b) return data[k];
		else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
	}
	Monoid find(int a, int b){
		return find(a, b, 0, 0, sz);
	}
	Monoid operator[](const int &k){
		return find(k, k+1);
	}
};
ll n;
int k, m;
int lmx[1515];

int main()
{
    cin>>n>>k>>m;
    for(int i=0; i<m; i++){
        int l, r; cin>>l>>r;
        lmx[r]=max(lmx[r], l);
    }
    using mb=pair<mint, bool>;
    auto f=[&](mint a, mint b){
        return a+b;
    };
    auto g=[&](mint a, mb x, int len){
        if(x.second) return x.first*len;
        return a;
    };
    auto h=[&](mb x, mb y){
        if(y.second) return y;
        return x;
    };
    vector<LazySegmentTree<mint, mb>> seg(k+1);
    for(int i=0; i<=k; i++) seg[i].init(k+1, f, g, h, 0, make_pair(0, 0));
    seg[0].update(0, 1, make_pair(1, 1));
    for(int i=1; i<=k; i++){
        for(int j=i-1; j>=0; j--){
            mint v=seg[j].data[0];
            seg[j+1].update(i, i+1, make_pair(v, 1));
            seg[j].update(0, lmx[i], make_pair(0, 1));
        }
    }
    mint x[1515];
    fac(k+1);
    for(int i=1; i<=k; i++){
        x[i]=mint(i).pow(n);
        for(int j=1; j<i; j++){
            x[i]-=x[j]*comb(i, j);
        }
    }
    mint ans=0;
    for(int i=1; i<=k; i++){
        mint v=seg[i].find(0, k+1);
        //cout<<v.val()<<" "<<x[i].val()<<endl;
        ans+=v*x[i];
    }
    cout<<ans.val()<<endl;
    return 0;
}
0