結果

問題 No.1493 隣接xor
ユーザー startcppstartcpp
提出日時 2021-05-01 01:27:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,356 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 81,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 10:25:19
合計ジャッジ時間 5,694 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//TLE
//累積xorを取ると、部分列は何種類?に帰着される。普通にDP考えるとO(N^2 logN)なのだが、どう高速化しようか。
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

void press(vector<int> &a) {
	int i;
	vector<int> sa;
	rep(i, a.size()) sa.push_back(a[i]);
	sort(sa.begin(), sa.end());
	sa.erase(unique(sa.begin(), sa.end()), sa.end());
	rep(i, a.size()) a[i] = lower_bound(sa.begin(), sa.end(), a[i]) - sa.begin();
}

int count_subarray(vector<int> a, int mod) {
	int i, j;
	
	int n = a.size();
	vector<int> dp(n + 1);
	vector<vector<int>> poses(n + 1);
	press(a);

	rep(i, a.size()) poses[a[i]].push_back(i);
	
	dp[0] = 1;
	rep(i, n) { //i番目以降で選ぶ
		rep(j, n) { //値jを選ぶ
			int iter = lower_bound(poses[j].begin(), poses[j].end(), i) - poses[j].begin();
			if (iter >= poses[j].size()) continue;
			(dp[poses[j][iter] + 1] += dp[i]) %= mod;
		}
		(dp[n] += dp[i]) %= mod;	//末尾にする
	}
	return dp[n];
}

int main() {
	int n, i;
	
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	vector<int> ra(n + 1);
	ra[0] = 0; rep(i, n) ra[i + 1] = ra[i] ^ a[i];
	
	vector<int> rb(n - 1);
	rep(i, n - 1) rb[i] = ra[i + 1];
	
	int mod = 1000000007;
	int ans = count_subarray(rb, mod);
	cout << ans << endl;
	return 0;
}
0