結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー IKyoproIKyopro
提出日時 2020-05-29 23:11:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 3,293 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 207,836 KB
実行使用メモリ 285,184 KB
最終ジャッジ日時 2024-04-24 01:05:40
合計ジャッジ時間 6,040 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 265 ms
179,840 KB
testcase_12 AC 166 ms
108,800 KB
testcase_13 AC 387 ms
251,392 KB
testcase_14 AC 202 ms
139,392 KB
testcase_15 AC 82 ms
55,296 KB
testcase_16 AC 67 ms
43,264 KB
testcase_17 AC 14 ms
10,624 KB
testcase_18 AC 214 ms
145,408 KB
testcase_19 AC 225 ms
154,112 KB
testcase_20 AC 92 ms
59,520 KB
testcase_21 AC 423 ms
285,056 KB
testcase_22 AC 434 ms
285,056 KB
testcase_23 AC 419 ms
285,184 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator==(const mint& r)const{
        return x==r.x;
    }
};


class combination{
public:
    vector<mint> fact,inv,finv;
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    vec<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(),A.end());
    vec<mint> L(N+1,1),R(N+1,1);
    vec<mint> L1(N+1,1),R1(N+1,1);
    for(int i=0;i<N;i++){
        L[i+1] = L[i]*A[i];
        L1[i+1] = L1[i]*(A[i]-1);
    }
    vvec<mint> dp(N+1,vec<mint>(N+1,0));
    dp[N][0] = 1;
    for(int i=N-1;i>=0;i--) for(int j=0;j<=N;j++){
        dp[i][j] += dp[i+1][j]*(A[i]-1);
        if(j!=N) dp[i][j+1] += dp[i+1][j];
    }

    auto solve = [&](int l,int r,int p){
        ll res = 0;
        for(int i=l;i<=r;i++){
            int id = lower_bound(A.begin(),A.end(),i)-A.begin();
//            if(N-id<p) continue;
            mint ans = L[id]*dp[id][p];
//            cerr << i << " " << id << " " << ans << "\n";
            res ^= ans.x;
        }
        return res%mod;
    };

    while(Q--){
        int l,r,p;
        cin >> l >> r >> p;
        cout << solve(l,r,p) << "\n";
    }
}
0