結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー wkwk
提出日時 2020-05-29 23:07:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,587 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 167,812 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-24 00:55:29
合計ジャッジ時間 5,043 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,400 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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 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 1 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

int main()
{   
    int N, Q; cin >> N >> Q;
    long A[7000];
    REP(i, N) cin >> A[i];
    int l[7000], r[7000], p[7000];
    REP(i, Q) cin >> l[i] >> r[i] >> p[i];
    long mod = 998244353;

    sort(A, A+N);
    
    long dp1[7000], dp2[7000];
    long ans[7000];
    REP(i, N) ans[i] = 0l;
    long mulA[7000];
    mulA[N] = 1l;
    REP(i, N) mulA[N-1-i] = (mulA[N-i] * A[i]) % mod;
    //REP(i, N+1) cout << mulA[i] << " ";
    //cout << endl;
    
    REP(i, N+1) dp1[i] = 0l;
    dp1[0] = A[N-1]-1l;
    dp1[1] = 1l;
    REP(i, Q){
        for(int j=l[i]; j<=r[i]; j++){
            int za = (int)(lower_bound(A, A+N, j) - A);
            if(za == (N-1)){
                //cout << i << " " << j << " " << dp1[p[i]] * mulA[1] << endl;
                ans[i] ^= (dp1[p[i]] * mulA[1]) % mod; ans[i] %= mod;
            }
        }
    }
    for(int i = N-2; i>=0; i--){
        REP(j, N+1) dp2[j] = 0l;
        REP(j, N+1){
            dp2[j] += (dp1[j] * (A[i] - 1l)) % mod;
            dp2[j] %= mod;
        }
        REP(j, N){
            dp2[j+1] += dp1[j]; 
            dp2[j+1] %= mod;
        }
        REP(j, N+1) dp1[j] = dp2[j];

        REP(k, Q){
            for(int j=l[k]; j<=r[k]; j++){
                int za = (int)(lower_bound(A, A+N, j) - A);
                if(za == i){
                    ans[k] ^= (dp1[p[k]] * mulA[N-i]) % mod; ans[k] %= mod;
                }
            }
        }
    }
    REP(i, Q) cout << ans[i] << endl;
    
    
    return 0;
}

0