結果

問題 No.1493 隣接xor
ユーザー Mister
提出日時 2021-05-08 15:29:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 83,972 KB
最終ジャッジ日時 2025-01-21 09:16:58
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <iostream>
#include <vector>
#include <map>

using namespace std;
using mint = atcoder::modint1000000007;

// xsの部分列を数える(空列含む)
template <class Int, class T>
Int count_subsequence(const vector<T>& xs) {
    map<T, Int> ds;
    Int dsum = 0;

    for (auto x : xs) {
        Int pat = dsum + 1;

        dsum += pat - ds[x];
        ds[x] = pat;
    }

    return dsum + 1;
}

void solve() {
    int n;
    cin >> n;

    vector<int> xs;
    {
        int xsum = 0;
        while (n--) {
            int x;
            cin >> x;
            xsum ^= x;
            xs.push_back(xsum);
        }
        xs.pop_back();
    }

    cout << count_subsequence<mint>(xs).val() << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0