結果

問題 No.1493 隣接xor
ユーザー the-xin
提出日時 2021-07-12 10:23:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 84,200 KB
実行使用メモリ 18,172 KB
最終ジャッジ日時 2024-07-02 03:22:45
合計ジャッジ時間 3,545 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<unordered_map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,a[1000500],c[1000500],f[1000500],ans=0;
unordered_map<int,int>last;
const int mod=1e9+7;
int main() {
    ios::sync_with_stdio(0);
    int n,m;
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>c[i];
    	a[i]=a[i-1]^c[i];
	}
	ans=0;
    memset(f,0,sizeof(f));
    last[0]=0;
    f[0]=1;
    for(int i=1;i<=n;i++) {
        if(last[a[i]]-1<0)f[i]=(2ll*f[i-1])%mod;
        else f[i]=(2ll*f[i-1]-f[last[a[i]]-1]+mod)%mod;
        last[a[i]]=i;
    }
    ans=(f[n-1]%mod+mod)%mod;
    cout<<ans<<endl;
    return 0;
}
0