結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー chocoruskchocorusk
提出日時 2020-05-29 22:15:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 521 ms / 2,000 ms
コード長 1,710 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 132,108 KB
実行使用メモリ 287,948 KB
最終ジャッジ日時 2024-04-23 22:57:50
合計ジャッジ時間 5,506 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 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,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 329 ms
203,956 KB
testcase_12 AC 198 ms
135,616 KB
testcase_13 AC 422 ms
270,072 KB
testcase_14 AC 226 ms
165,984 KB
testcase_15 AC 99 ms
88,848 KB
testcase_16 AC 83 ms
55,696 KB
testcase_17 AC 19 ms
19,516 KB
testcase_18 AC 238 ms
162,560 KB
testcase_19 AC 255 ms
179,960 KB
testcase_20 AC 112 ms
91,732 KB
testcase_21 AC 516 ms
287,948 KB
testcase_22 AC 521 ms
287,704 KB
testcase_23 AC 509 ms
287,628 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
int main()
{
	int n, q; cin>>n>>q;
	ll a[6060];
	for(int i=0; i<n; i++) cin>>a[i];
	ll dp[2][6060]={};
	dp[0][0]=1;
	for(int i=0; i<n; i++){
		fill(dp[(i+1)&1], dp[(i+1)&1]+n+1, 0);
		for(int j=0; j<=i; j++){
			(dp[(i+1)&1][j+1]+=dp[i&1][j])%=MOD;
			(dp[(i+1)&1][j]+=dp[i&1][j]*(a[i]-1))%=MOD;
		}
	}
	sort(a, a+n);
	ll c[6060][6060];
	for(int i=0; i<=n; i++) c[0][i]=dp[n&1][i];
	for(int i=1; i<n; i++){
		if((a[i-1]-1)%MOD==0){
			for(int j=0; j<n; j++) c[i][j]=c[i-1][j+1];
			c[i][n]=0;
			continue;
		}
		ll b=inv((a[i-1]-1)%MOD);
		c[i][0]=c[i-1][0];
		for(int j=1; j<=n; j++){
			c[i][j]=(c[i-1][j]+c[i][j-1]*(MOD-b))%MOD;
		}
		for(int j=0; j<=n; j++){
			(c[i][j]*=b)%=MOD; (c[i][j]*=a[i-1])%=MOD;
		}
	}
	for(int i=0; i<q; i++){
		int l, r, p; cin>>l>>r>>p;
		ll ans=0;
		for(int j=l; j<=r; j++){
			int t=lower_bound(a, a+n, j)-a;
			ans^=c[t][p];
		}
		cout<<ans<<endl;
	}
	return 0;
}
0