結果

問題 No.1493 隣接xor
ユーザー keijakkeijak
提出日時 2021-05-01 05:10:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 210,964 KB
実行使用メモリ 15,520 KB
最終ジャッジ日時 2023-09-26 13:20:10
合計ジャッジ時間 6,099 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 154 ms
15,520 KB
testcase_04 AC 156 ms
15,388 KB
testcase_05 AC 162 ms
15,364 KB
testcase_06 AC 162 ms
15,364 KB
testcase_07 AC 155 ms
15,324 KB
testcase_08 AC 153 ms
15,404 KB
testcase_09 AC 148 ms
15,416 KB
testcase_10 AC 140 ms
15,472 KB
testcase_11 AC 146 ms
15,440 KB
testcase_12 AC 143 ms
15,420 KB
testcase_13 AC 26 ms
6,172 KB
testcase_14 AC 14 ms
6,136 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 61 ms
9,288 KB
testcase_21 AC 72 ms
10,500 KB
testcase_22 AC 45 ms
8,348 KB
testcase_23 AC 60 ms
9,552 KB
testcase_24 AC 135 ms
14,800 KB
testcase_25 AC 49 ms
8,020 KB
testcase_26 AC 74 ms
10,880 KB
testcase_27 AC 28 ms
6,204 KB
testcase_28 AC 119 ms
14,292 KB
testcase_29 AC 78 ms
11,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP_(i, a_, b_, a, b, ...) \
  for (int i = (a), END_##i = (b); i < END_##i; ++i)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(x) std::begin(x), std::end(x)
using u32 = unsigned;

#include <atcoder/modint>
using Mint = atcoder::modint1000000007;
std::ostream &operator<<(std::ostream &os, const Mint &m) {
  return os << m.val();
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
using namespace std;

Mint solve() {
  int n;
  cin >> n;
  vector<u32> a(n), b(n + 1);
  cin >> a;
  REP(i, n) b[i + 1] = b[i] ^ a[i];

  vector dp(n + 1, Mint(0)), dpcum(n + 2, Mint(0));
  dp[0] = 1;
  dpcum[1] = 1;
  map<u32, int> pre;
  REP(i, 1, n + 1) {
    auto it = pre.find(b[i]);
    int j = (it == pre.end()) ? 0 : it->second;
    dp[i] = dpcum[i] - dpcum[j];
    dpcum[i + 1] = dpcum[i] + dp[i];
    pre[b[i]] = i;
  }
  Mint ans = 0;
  REP(i, n) ans += dp[i];
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  cout << solve() << "\n";
}
0