結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー soto800soto800
提出日時 2020-05-30 20:04:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 3,686 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 171,188 KB
実行使用メモリ 295,284 KB
最終ジャッジ日時 2024-04-25 13:43:12
合計ジャッジ時間 6,387 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 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 2 ms
6,944 KB
testcase_11 AC 331 ms
235,112 KB
testcase_12 AC 260 ms
182,756 KB
testcase_13 AC 385 ms
277,744 KB
testcase_14 AC 280 ms
207,080 KB
testcase_15 AC 177 ms
128,736 KB
testcase_16 AC 160 ms
112,984 KB
testcase_17 AC 69 ms
51,920 KB
testcase_18 AC 286 ms
210,920 KB
testcase_19 AC 290 ms
217,192 KB
testcase_20 AC 193 ms
134,364 KB
testcase_21 AC 422 ms
295,284 KB
testcase_22 AC 421 ms
294,520 KB
testcase_23 AC 419 ms
294,388 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;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 998244353;
using mint = Fp<MOD>;

lli dp[6200][6200];
lli mo[6200];

int main(){

    lli n,q;
    cin>>n>>q;
    vector<lli> a(n);
    REP(i,0,n)cin>>a[i];

    SORT(a);

    dp[n][0] = 1;
    for(lli i=n-1;i>=0;i--){
        REP(j,0,6100){
            dp[i][j+1] += dp[i+1][j];
            dp[i][j+1] %= MOD;
            dp[i][j] += (dp[i+1][j])*(a[i]-1);
            dp[i][j] %=MOD;
        }
    }

    mo[0] = 1;
    REP(i,0,n)mo[i+1] = (mo[i]*a[i])%MOD;

    while(q--){
        lli l,r,p;
        cin>>l>>r>>p;

        lli res = 0;
        REP(i,l,r+1){
            lli index = (lli)(lower_bound(a.begin(),a.end(),i) - a.begin());
            lli now =  mo[index]*dp[index][p];
            now %= MOD;
            res ^= now;
        }
        cout<<res<<endl;
    }



    return 0;
}
0