結果

問題 No.1493 隣接xor
ユーザー kenskens
提出日時 2021-05-01 00:35:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 207,752 KB
実行使用メモリ 14,668 KB
最終ジャッジ日時 2023-09-26 09:40:59
合計ジャッジ時間 7,445 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 219 ms
14,664 KB
testcase_04 AC 215 ms
14,604 KB
testcase_05 AC 215 ms
14,620 KB
testcase_06 AC 216 ms
14,600 KB
testcase_07 AC 222 ms
14,596 KB
testcase_08 AC 222 ms
14,668 KB
testcase_09 AC 216 ms
14,620 KB
testcase_10 AC 215 ms
14,616 KB
testcase_11 AC 211 ms
14,664 KB
testcase_12 AC 224 ms
14,612 KB
testcase_13 AC 84 ms
5,368 KB
testcase_14 AC 32 ms
5,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 93 ms
9,260 KB
testcase_21 AC 114 ms
9,880 KB
testcase_22 AC 76 ms
7,752 KB
testcase_23 AC 101 ms
9,116 KB
testcase_24 AC 215 ms
14,400 KB
testcase_25 AC 71 ms
7,928 KB
testcase_26 AC 122 ms
10,560 KB
testcase_27 AC 44 ms
6,224 KB
testcase_28 AC 197 ms
13,732 KB
testcase_29 AC 133 ms
10,656 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;
  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