結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー kotatsugame
提出日時 2020-05-29 22:10:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 86,128 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-06 05:04:14
合計ジャッジ時間 3,040 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
const long mod=998244353;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int N,Q;
long dp[6060];
int ans[5050];
int L[5050],R[5050],P[5050];
main()
{
	cin>>N>>Q;
	map<int,int>mp;
	long T=1;
	for(int i=0;i<N;i++)
	{
		int A;cin>>A;mp[A]++;
		T=T*A%mod;
	}
	for(int i=0;i<Q;i++)
	{
		cin>>L[i]>>R[i]>>P[i];
	}
	vector<pair<int,int> >X(mp.begin(),mp.end());
	dp[0]=T;
	for(int i=X.size();i--;)
	{
		long A=X[i].first;
		long invA=power(A,mod-2);
		for(int j=0;j<X[i].second;j++)
		{
			for(int k=N;k>=0;k--)
			{
				(dp[k+1]+=dp[k]*invA)%=mod;
				dp[k]=dp[k]*(A-1)%mod*invA%mod;
			}
		}
		for(int j=0;j<Q;j++)
		{
			int r=min(R[j],(int)A);
			int l=max(L[j],i==0?1:X[i-1].first+1);
			if(l<=r)
			{
				if((r-l+1)%2==1)ans[j]^=dp[P[j]];
				R[j]=l-1;
			}
		}
	}
	for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
}
0