結果
問題 |
No.2568 列辞書順列列
|
ユーザー |
![]() |
提出日時 | 2023-12-06 01:25:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 513 ms / 3,000 ms |
コード長 | 663 bytes |
コンパイル時間 | 5,183 ms |
コンパイル使用メモリ | 253,748 KB |
最終ジャッジ日時 | 2025-02-18 08:10:25 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int N,M,Q; using P = pair<mint,int>; P op(P a,P b){ swap(a,b); a.first += b.first * mint(M).pow(a.second); a.second += b.second; return a; } P e(){ return make_pair(0,0); } int main(){ cin>>N>>M>>Q; segtree<P,op,e> seg(N); rep(i,N){ int a; cin>>a; a--; seg.set(i,make_pair(mint(a),1)); } rep(i,Q){ int l,r; cin>>l>>r; cout<<(seg.prod(l-1,r).first+1).val()<<endl; } return 0; }