結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー beetbeet
提出日時 2020-05-29 21:52:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 656 ms / 2,000 ms
コード長 3,389 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 221,304 KB
実行使用メモリ 113,440 KB
最終ジャッジ日時 2024-04-23 21:44:44
合計ジャッジ時間 6,523 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 195 ms
34,672 KB
testcase_12 AC 243 ms
48,480 KB
testcase_13 AC 112 ms
15,280 KB
testcase_14 AC 47 ms
6,656 KB
testcase_15 AC 64 ms
15,660 KB
testcase_16 AC 152 ms
33,208 KB
testcase_17 AC 20 ms
7,808 KB
testcase_18 AC 109 ms
20,180 KB
testcase_19 AC 49 ms
6,656 KB
testcase_20 AC 249 ms
51,284 KB
testcase_21 AC 656 ms
113,312 KB
testcase_22 AC 649 ms
113,188 KB
testcase_23 AC 639 ms
113,440 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0