結果

問題 No.1493 隣接xor
ユーザー miyo2580miyo2580
提出日時 2023-12-01 11:37:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 2,283 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 180,204 KB
実行使用メモリ 20,608 KB
最終ジャッジ日時 2023-12-01 11:37:15
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 197 ms
20,608 KB
testcase_04 AC 205 ms
20,608 KB
testcase_05 AC 207 ms
20,608 KB
testcase_06 AC 204 ms
20,608 KB
testcase_07 AC 201 ms
20,608 KB
testcase_08 AC 223 ms
20,608 KB
testcase_09 AC 200 ms
20,608 KB
testcase_10 AC 202 ms
20,608 KB
testcase_11 AC 196 ms
20,608 KB
testcase_12 AC 202 ms
20,608 KB
testcase_13 AC 33 ms
8,064 KB
testcase_14 AC 18 ms
8,064 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 93 ms
12,288 KB
testcase_21 AC 103 ms
13,440 KB
testcase_22 AC 63 ms
10,496 KB
testcase_23 AC 85 ms
12,416 KB
testcase_24 AC 198 ms
19,840 KB
testcase_25 AC 61 ms
10,240 KB
testcase_26 AC 110 ms
14,080 KB
testcase_27 AC 47 ms
7,808 KB
testcase_28 AC 175 ms
18,816 KB
testcase_29 AC 113 ms
14,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 : division
const 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 mod
  mint 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;
}
0