結果

問題 No.1493 隣接xor
ユーザー kenskens
提出日時 2021-05-01 00:38:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,573 bytes
コンパイル時間 2,537 ms
コンパイル使用メモリ 207,028 KB
実行使用メモリ 14,952 KB
最終ジャッジ日時 2023-09-26 09:42:57
合計ジャッジ時間 6,506 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 130 ms
14,760 KB
testcase_04 AC 138 ms
14,744 KB
testcase_05 AC 135 ms
14,884 KB
testcase_06 AC 137 ms
14,948 KB
testcase_07 AC 137 ms
14,748 KB
testcase_08 AC 129 ms
14,952 KB
testcase_09 AC 134 ms
14,820 KB
testcase_10 AC 134 ms
14,892 KB
testcase_11 AC 130 ms
14,880 KB
testcase_12 AC 131 ms
14,764 KB
testcase_13 AC 89 ms
5,560 KB
testcase_14 AC 38 ms
5,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 63 ms
9,000 KB
testcase_21 AC 70 ms
9,296 KB
testcase_22 AC 48 ms
7,160 KB
testcase_23 AC 63 ms
8,976 KB
testcase_24 AC 133 ms
14,656 KB
testcase_25 AC 46 ms
7,224 KB
testcase_26 AC 76 ms
9,852 KB
testcase_27 AC 31 ms
6,016 KB
testcase_28 AC 120 ms
14,656 KB
testcase_29 AC 81 ms
9,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
constexpr ll mod = 1e9+7;

struct mint {
  ll x;
  mint(ll _x = 0) {if((_x %= mod) < 0) _x += mod; x = _x;}
  bool operator==(const mint a) {return x == a.x;}
  mint operator-() const {return mint(-x);}
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {return pow(mod-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
  ll val() {return x;}
};

int main(){
  int n, a;
  cin >> n;
  vector<int> b(n+1);
  int res = 0;
  rep(i,n) {
    cin >> a;
    res ^= a;
    b[i+1] = res;
  }
  vector<mint> dp(n+1);
  dp[0] = 1;
  unordered_map<int,int> last;
  for(int i = 1; i <= n-1; i++) {
    dp[i] += dp[i-1]*2;
    if(last[b[i]]) dp[i] -= dp[last[b[i]]-1];
    last[b[i]] = i;
  }
  cout << dp[n-1].val() << endl;
  return 0;
}
0