結果
| 問題 | No.1067 #いろいろな色 / Red and Blue and more various colors (Middle) |
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-05-29 21:52:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 910 ms / 2,000 ms |
| コード長 | 3,389 bytes |
| 記録 | |
| コンパイル時間 | 4,347 ms |
| コンパイル使用メモリ | 218,504 KB |
| 最終ジャッジ日時 | 2025-01-10 17:01:05 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';
template<typename T,T MOD = 1000000007>
struct Mint{
static constexpr T mod = MOD;
T v;
Mint():v(0){}
Mint(signed v):v(v){}
Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
Mint pow(long long k){
Mint res(1),tmp(v);
while(k){
if(k&1) res*=tmp;
tmp*=tmp;
k>>=1;
}
return res;
}
static Mint add_identity(){return Mint(0);}
static Mint mul_identity(){return Mint(1);}
Mint inv(){return pow(MOD-2);}
Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
Mint& operator/=(Mint a){return (*this)*=a.inv();}
Mint operator+(Mint a) const{return Mint(v)+=a;}
Mint operator-(Mint a) const{return Mint(v)-=a;}
Mint operator*(Mint a) const{return Mint(v)*=a;}
Mint operator/(Mint a) const{return Mint(v)/=a;}
Mint operator-() const{return v?Mint(MOD-v):Mint(v);}
bool operator==(const Mint a)const{return v==a.v;}
bool operator!=(const Mint a)const{return v!=a.v;}
bool operator <(const Mint a)const{return v <a.v;}
static Mint comb(long long n,int k){
Mint num(1),dom(1);
for(int i=0;i<k;i++){
num*=Mint(n-i);
dom*=Mint(i+1);
}
return num/dom;
}
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
template<typename T, typename ...Ts>
vector<T> fusion(vector<T> bs,Ts... ts){
auto append=[&](auto vs){for(auto v:vs) bs.emplace_back(v);};
initializer_list<int>{(void(append(ts)),0)...};
return bs;
}
template<typename V>
V compress(V vs){
sort(vs.begin(),vs.end());
vs.erase(unique(vs.begin(),vs.end()),vs.end());
return vs;
}
template<typename T>
map<T, int> dict(const vector<T> &vs){
map<T, int> res;
for(int i=0;i<(int)vs.size();i++)
res[vs[i]]=i;
return res;
}
map<char, int> dict(const string &s){
return dict(vector<char>(s.begin(),s.end()));
}
//INSERT ABOVE HERE
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n,q;
cin>>n>>q;
vector<int> as(n);
for(int i=0;i<n;i++) cin>>as[i];
vector<int> ls(q),rs(q),ps(q);
for(int i=0;i<q;i++) cin>>ls[i]>>rs[i]>>ps[i];
vector<int> cs(as);
for(int i=0;i<q;i++)
for(int j=ls[i];j<=rs[i];j++)
cs.emplace_back(j);
cs=compress(cs);
auto dc=dict(cs);
int m=cs.size();
vector<vector<int>> G(m);
for(int i=0;i<q;i++)
for(int j=ls[i];j<=rs[i];j++)
G[dc[j]].emplace_back(i);
vector<int> cnt(m);
for(int a:as) cnt[dc[a]]++;
using M = Mint<int, 998244353>;
using Poly = vector<M>;
M fact(1);
Poly dp(1,1);
int num=0;
vector<int> ans(q,0);
for(int a:as) fact*=M(a);
for(int j=m-1;j>=0;j--){
for(int k=0;k<cnt[j];k++){
Poly nx(dp.size()+1,0);
for(int i=0;i<(int)dp.size();i++){
nx[i+0]+=dp[i]*M(cs[j]-1);
nx[i+1]+=dp[i]*M(1);
}
swap(dp,nx);
fact/=M(cs[j]);
num++;
}
for(int i:G[j])
if(ps[i]<=num)
ans[i]^=(dp[ps[i]]*fact).v;
}
for(int a:ans) cout<<a<<newl;
return 0;
}
beet