結果

問題 No.2568 列辞書順列列
ユーザー iris2617
提出日時 2025-03-17 02:08:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 688 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 194,480 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-17 02:08:25
合計ジャッジ時間 6,613 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
//const int iris = 1e9+7;
const int iris = 998244353;
using namespace std;

void solve()
{
	auto qwq=[&](int a,int b=iris-2)
	{
		int res=1;
		while(b)
		{
			if(b&1)
				res=res*a%iris;
			a=a*a%iris;
			b/=2;
		}
		return res;
	};
	int n,m,q;
	cin>>n>>m>>q;
	vector<int> pr(n+1);
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		pr[i]=(pr[i-1]+(a-1)*qwq(m,n-i))%iris;
	}
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		int ans=(pr[r]-pr[l-1]+iris)%iris;
		cout<<(ans*qwq(qwq(m, n-r))+1)%iris<<'\n';
	}
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int T=1;
	//cin>>T;
	while(T--)
		solve();

	return 0;
}
0