結果

問題 No.1493 隣接xor
ユーザー penguinmanpenguinman
提出日時 2021-04-05 01:03:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 209,344 KB
実行使用メモリ 29,804 KB
最終ジャッジ日時 2023-09-02 12:33:53
合計ジャッジ時間 10,376 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using ll = long long;
const ll mod = 1e9+7;
#define rep(i,j,k) for(int i=int(j); i<int(k); i++)
#define REP(i,j,k) for(int i=int(j); i<=int(k); i++)

int main(){
    ll N; cin >> N;
    vector<ll> A(N), sum(N+1);
    std::map<ll,vector<ll>> mem;
    rep(i,0,N){
        cin >> A[i];
        sum[i+1] = A[i]^sum[i];
        mem[sum[i+1]].push_back(i+1);
    }
    //sum[1] ~ sum[N-1] までの部分列を数える
    vector<ll> dp(N);
    dp[0] = 1;
    //dp[i] = i番目までの総和
    rep(i,1,N){
        dp[i] = dp[i-1]*2%mod;
        ll index = std::lower_bound(mem[sum[i]].begin(), mem[sum[i]].end(), i)-mem[sum[i]].begin()-1;
        if(0 <= index){
            dp[i] -= dp[mem[sum[i]][index]-1];
            if(dp[i] < 0) dp[i] += mod;
        }
    }
    ll ans = 1;
    rep(i,1,N) ans = ans*2%mod;
    cout << ans << endl;
}
0