結果

問題 No.1493 隣接xor
ユーザー keijak
提出日時 2021-05-01 05:10:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 205,292 KB
最終ジャッジ日時 2025-01-21 04:58:54
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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