結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー wkwk
提出日時 2020-05-29 23:18:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,000 ms / 2,000 ms
コード長 1,732 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 168,064 KB
実行使用メモリ 258,304 KB
最終ジャッジ日時 2024-04-24 01:23:05
合計ジャッジ時間 7,381 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 356 ms
118,784 KB
testcase_12 AC 415 ms
134,912 KB
testcase_13 AC 205 ms
54,016 KB
testcase_14 AC 95 ms
13,824 KB
testcase_15 AC 65 ms
29,312 KB
testcase_16 AC 167 ms
61,952 KB
testcase_17 AC 12 ms
7,808 KB
testcase_18 AC 171 ms
58,240 KB
testcase_19 AC 102 ms
13,568 KB
testcase_20 AC 311 ms
111,232 KB
testcase_21 AC 1,000 ms
258,176 KB
testcase_22 AC 914 ms
258,176 KB
testcase_23 AC 916 ms
258,304 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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

    long za[7000][7000];

    REP(k, Q){
        REP(i, N+1) za[k][i] = 0l;
        for(int j=l[k]; j<=r[k]; j++){
            int z = (int)(lower_bound(A, A+N, j) - A);
            za[k][z]++;
        }
    }


    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){
            long temp = (dp1[p[k]] * mulA[N-i]) % mod;
            if(za[k][i]%2!=0){
                ans[k] ^= (dp1[p[k]] * mulA[N-i]) % mod; ans[k] %= mod;
            }
        }
    }
    REP(i, Q) cout << ans[i] << endl;
    
    
    return 0;
}

0