結果
問題 | No.1493 隣接xor |
ユーザー |
|
提出日時 | 2023-12-01 11:37:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 2,283 bytes |
コンパイル時間 | 1,919 ms |
コンパイル使用メモリ | 180,160 KB |
実行使用メモリ | 20,480 KB |
最終ジャッジ日時 | 2024-09-26 15:16:55 |
合計ジャッジ時間 | 5,773 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define repd(i,a,b) for (ll i=(a);i<(b);i++)#define rep(i,n) repd(i,0,n)#define all(x) (x).begin(),(x).end()template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }typedef long long ll;typedef pair<ll,ll> P;typedef vector<ll> vec;using Graph = vector<vector<ll>>;const long long INF = 1LL<<60;const long long MOD = 1000000007;// auto mod int// https://youtu.be/L8grWxBlIZ4?t=9858// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize// https://youtu.be/8uowVvQ_-Mo?t=1329 : divisionconst int mod = MOD;struct mint {ll x; // typedef long long ll;mint(ll x=0):x((x%mod+mod)%mod){}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 { return mint(*this) += a;}mint operator-(const mint a) const { return mint(*this) -= a;}mint operator*(const mint a) const { return mint(*this) *= 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 modmint inv() const { return pow(mod-2);}mint& operator/=(const mint a) { return *this *= a.inv();}mint operator/(const mint a) const { return mint(*this) /= a;}};istream& operator>>(istream& is, mint& a) { return is >> a.x;}ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}int main(){ios::sync_with_stdio(false);cin.tie(0);ll n;cin>>n;vec a(n);rep(i,n)cin>>a[i];map<ll,ll> mp;mp[0]=0;vec memo(n+1,-1);ll x=0;rep(i,n){x^=a[i];if(mp.count(x)){memo[i+1]=mp[x];}mp[x]=i+1;}mint tot=1;vector<mint> cnt(n);cnt[0]=1;repd(i,1,n){mint now=tot+1;cnt[i]=now;tot+=now;if(memo[i+1]!=-1&&memo[i+1]-1>=0){tot-=cnt[memo[i+1]-1];}}cout<<cnt[n-1]<<endl;return 0;}