結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー leaf_1415leaf_1415
提出日時 2020-05-29 22:31:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,914 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 89,244 KB
実行使用メモリ 19,912 KB
最終ジャッジ日時 2024-04-23 23:32:40
合計ジャッジ時間 3,877 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 185 ms
11,584 KB
testcase_12 AC 196 ms
11,580 KB
testcase_13 AC 290 ms
5,432 KB
testcase_14 AC 229 ms
5,376 KB
testcase_15 AC 84 ms
5,408 KB
testcase_16 AC 81 ms
11,568 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 218 ms
7,344 KB
testcase_19 AC 218 ms
5,376 KB
testcase_20 AC 74 ms
11,572 KB
testcase_21 AC 205 ms
19,788 KB
testcase_22 AC 202 ms
19,912 KB
testcase_23 AC 200 ms
19,784 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define eps 1e-9
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

llint n, Q;
llint a[6005];
llint l[6005], r[6005], p[6005];
llint dp[2][6005];
llint b[6005], nb[6005];
vector<P> vec;
llint ans[5005];

void calc(llint a)
{
	for(int i = 0; i <= n; i++) nb[i] = 0;
	for(int i = n; i >= 1; i--){
		nb[i-1] = b[i];
		b[i-1] += mod - (a-1)*b[i]%mod, b[i-1] %= mod;
	}
	for(int i = 0; i <= n; i++) nb[i] *= a, nb[i] %= mod;
	for(int i = 0; i <= n; i++) b[i] = nb[i];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	
	for(int i = 1; i <= Q; i++){
		cin >> l[i] >> r[i] >> p[i];
		for(int j = l[i]; j <= r[i]; j++) vec.push_back(P(j, i));
	}
	sort(vec.begin(), vec.end());
	
	dp[0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= n; j++) dp[(i+1)%2][j] = 0;
		for(int j = 0; j <= n; j++){
			dp[(i+1)%2][j] += dp[i%2][j] * (a[i+1]-1) % mod, dp[(i+1)%2][j] %= mod;
			if(j+1 <= n) dp[(i+1)%2][j+1] += dp[i%2][j], dp[(i+1)%2][j+1] %= mod;
		}
	}
	for(int i = 0; i <= n; i++) b[i] = dp[n%2][i];
	
	llint pos = 1;
	for(int i = 0; i < vec.size(); i++){
		while(pos <= n && a[pos] < vec[i].first){
			calc(a[pos]);
			pos++;
		}
		llint id = vec[i].second;
		ans[id] ^= b[p[id]];
	}
	
	for(int i = 1; i <= Q; i++) cout << ans[i]%mod << endl;
	
	return 0;
}
0