結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー hedwig100hedwig100
提出日時 2020-05-30 14:14:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 172,828 KB
実行使用メモリ 285,056 KB
最終ジャッジ日時 2024-04-25 05:59:36
合計ジャッジ時間 5,637 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 242 ms
179,840 KB
testcase_12 AC 159 ms
108,672 KB
testcase_13 AC 332 ms
251,136 KB
testcase_14 AC 182 ms
139,392 KB
testcase_15 AC 75 ms
55,168 KB
testcase_16 AC 65 ms
43,264 KB
testcase_17 AC 15 ms
10,880 KB
testcase_18 AC 194 ms
145,280 KB
testcase_19 AC 201 ms
153,984 KB
testcase_20 AC 98 ms
59,392 KB
testcase_21 AC 405 ms
284,928 KB
testcase_22 AC 403 ms
285,056 KB
testcase_23 AC 403 ms
285,056 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 998244353;
const double eps = 1e-6;

int main() {
    int N,Q; cin >> N >> Q;
    vector<ll> A(N);
    rep(i,N) {
        ll a; cin >> a; A[i] = a - 1;
    }
    sort(A.begin(),A.end());

    vector<ll> cumprd(N + 1,1);
    rep(i,N) cumprd[i + 1] = cumprd[i] * (A[i] + 1) % MOD;

    vector<vector<ll>> dp(N + 1,vector<ll>(N + 1,0));
    dp[0] = vector<ll>(N + 1,1);
    for (int i = 1;i < N + 1;i++) {
        for (int j = N - 1; j >= 0;j--) {
            dp[i][j] = (dp[i - 1][j + 1]*A[j] + dp[i][j + 1])%MOD;
        }
    }

    rep(_,Q) {
        ll L,R,P; cin >> L >> R >> P;
        ll ans = 0;
        for (int i = L;i <= R;i ++) {
            int x = lower_bound(A.begin(),A.end(),i - 1) - A.begin();
            if (x == 0) ans ^= dp[N - P][0];
            else if (N - x - P >= 0) ans ^= (cumprd[x] * dp[N - P - x][x] % MOD);
        }
        ans %= MOD;
        cout << ans << endl;
    }
}
0