結果
| 問題 |
No.1493 隣接xor
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-01 00:35:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 233 ms / 2,000 ms |
| コード長 | 1,563 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 202,952 KB |
| 最終ジャッジ日時 | 2025-01-21 04:56:27 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#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;
}