結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー milanis48663220milanis48663220
提出日時 2020-05-29 22:54:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,321 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 285,184 KB
最終ジャッジ日時 2024-04-24 00:31:03
合計ジャッジ時間 3,928 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 192 ms
198,656 KB
testcase_12 AC 125 ms
123,520 KB
testcase_13 AC 251 ms
267,648 KB
testcase_14 AC 143 ms
155,904 KB
testcase_15 AC 63 ms
65,664 KB
testcase_16 AC 54 ms
52,352 KB
testcase_17 AC 13 ms
14,976 KB
testcase_18 AC 157 ms
162,432 KB
testcase_19 AC 157 ms
171,648 KB
testcase_20 AC 78 ms
70,016 KB
testcase_21 AC 292 ms
284,928 KB
testcase_22 AC 291 ms
285,184 KB
testcase_23 AC 290 ms
285,056 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;
int N, Q;
ll A[10000], B[10000]; 

ll dp[6005][6005];
ll pr[6005];

void init(){
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= N; j++){
            dp[i][j] = 0;
        }
        for(int j = 0; j <= i-1; j++){
            // 1
            dp[i][j+1] += dp[(i-1)][j];
            dp[i][j+1] %= MOD;
            // 1 以外
            dp[i][j] += dp[(i-1)][j]*(A[i-1]-1);
            dp[i][j] %= MOD;
        }
    }
    pr[N] = 1;
    for(int i = N-1; i >= 0; i--){
        pr[i] = pr[i+1]*A[i];
        pr[i] %= MOD;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> Q;
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A, A+N, greater<int>());
    init();
    
    for(int i = 0; i < Q; i++){
        int l, r, p;
        cin >> l >> r >> p;
        ll ans = 0;
        int cur = 0;
        for(int j = r; j >= l; j--){
            while(A[cur] >= j){
                cur++;
            }
            ll tmp = (dp[cur][p]*pr[cur])%MOD;
            ans ^= tmp;
        }
        cout << ans%MOD << endl; 
    }
}
0