結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー kappybarkappybar
提出日時 2020-05-29 23:08:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 1,523 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 174,024 KB
実行使用メモリ 284,928 KB
最終ジャッジ日時 2024-04-24 00:57:12
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 236 ms
179,840 KB
testcase_12 AC 163 ms
108,672 KB
testcase_13 AC 302 ms
251,520 KB
testcase_14 AC 163 ms
139,648 KB
testcase_15 AC 72 ms
55,296 KB
testcase_16 AC 70 ms
43,392 KB
testcase_17 AC 14 ms
11,136 KB
testcase_18 AC 183 ms
145,664 KB
testcase_19 AC 181 ms
154,240 KB
testcase_20 AC 103 ms
59,520 KB
testcase_21 AC 402 ms
284,928 KB
testcase_22 AC 401 ms
284,928 KB
testcase_23 AC 402 ms
284,928 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
using vc = pair<ll,vector<ll>>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 998244353;

int main(){
    int n,q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<ll>());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        rep(j,n+1){
            if(j>0) dp[i][j] = (((a[i-1]-1)*dp[i-1][j])%MOD + dp[i-1][j-1])%MOD;
            else dp[i][j] = ((a[i-1]-1)*dp[i-1][j])%MOD;
        }
    }
    /*
    rep(i,n+1){
        rep(j,n+1) cout << dp[i][j] <<" " ;
        cout << endl;
    }
    */

    vector<ll> cum(n+2,1);
    rep(i,n) cum[i+1] = a[i];
    for(int i=n;i>=0;i--) cum[i] = (cum[i+1]*cum[i])%MOD;

    //rep(i,n+2) cout << cum[i] << " ";

    rep(i,q){
        int l,r,p;
        cin >> l >> r >> p;
        ll res = 0;
        for(int j=l;j<=r;j++){
            int left = 0,right = n+1;
            while(right - left > 1){
                int mid = (right + left)/2;
                if(a[mid-1] >= j) left = mid;
                else right = mid;
            }
            ll ret  = (dp[left][p] * cum[right])%MOD;
            //cout << left <<" " <<ret << " ";
            res ^= ret;
            res %= MOD;
        }
        cout << res << endl;
        //cout << endl;
    }

    return 0;
}
0