結果

問題 No.1493 隣接xor
ユーザー ぷらぷら
提出日時 2021-06-11 19:29:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,372 bytes
コンパイル時間 2,640 ms
コンパイル使用メモリ 212,184 KB
実行使用メモリ 13,168 KB
最終ジャッジ日時 2023-08-21 07:40:01
合計ジャッジ時間 10,877 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 402 ms
12,856 KB
testcase_04 AC 384 ms
13,040 KB
testcase_05 AC 403 ms
12,828 KB
testcase_06 AC 399 ms
12,856 KB
testcase_07 AC 409 ms
12,916 KB
testcase_08 AC 400 ms
12,884 KB
testcase_09 AC 400 ms
12,892 KB
testcase_10 AC 403 ms
12,888 KB
testcase_11 AC 395 ms
13,168 KB
testcase_12 AC 404 ms
12,892 KB
testcase_13 WA -
testcase_14 AC 37 ms
4,796 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 194 ms
8,172 KB
testcase_21 AC 226 ms
8,356 KB
testcase_22 AC 154 ms
7,820 KB
testcase_23 AC 193 ms
8,172 KB
testcase_24 AC 386 ms
12,852 KB
testcase_25 AC 146 ms
7,808 KB
testcase_26 AC 230 ms
8,248 KB
testcase_27 AC 88 ms
5,736 KB
testcase_28 AC 362 ms
12,920 KB
testcase_29 AC 243 ms
8,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int mod = 1000000007;

template <typename T>
struct LazySegmentTree{
    int n;
    vector<T> dat;
    vector<T>lazy;
    LazySegmentTree() {};
    LazySegmentTree(int N) {
        n = 1;
        while(n < N) {
            n *= 2;
        }
        dat.resize(n*2-1,0);
        lazy.resize(n*2-1,0);
    }
    void eval(int k,int l,int r) {
        if(lazy[k] == 0) return;
        if(k < n-1) {
            lazy[k*2+1] += lazy[k];
            lazy[k*2+1] %= mod;
            lazy[k*2+2] += lazy[k];
            lazy[k*2+2] %= mod;
        }
        dat[k] += lazy[k];
        dat[k] %= mod;
        lazy[k] = 0;
    }
    void update(int a, int b, T x, int k, int l, int r) {
        eval(k,l,r);
        if(a <= l && r <= b) {
            lazy[k] += x;
            lazy[k] %= mod;
            eval(k,l,r);
        }
        else if(a < r && l < b) {
            update(a, b, x, k*2+1, l, (l+r)/2);
            update(a, b, x, k*2+2, (l+r)/2, r);
            dat[k] = dat[k*2+1]+dat[k*2+2];
            dat[k] %= mod;
        }
    }
    void update(int a, int b, T x) {//[a,b)
        update(a, b, x, 0, 0, n);
    }
    T query_sub(int a, int b, int k, int l, int r) {
        eval(k,l,r);
        if (r <= a || b <= l) {
            return 0;
        }
        else if (a <= l && r <= b) {
            return dat[k];
        }
        else {
            T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
            T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
            return (vl+vr)%mod;
        }
    }
    T query(int a, int b) {//[a,b)
        return query_sub(a, b, 0, 0, n);
    }
};

int main() {
    int N;
    cin >> N;
    vector<int>A(N),B;
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum ^= A[i];
        B.push_back(sum);
    }
    sort(B.begin(),B.end());
    B.erase(unique(B.begin(),B.end()),B.end());
    LazySegmentTree<long long>tree(B.size());
    tree.update(0,B.size(),1);
    sum = 0;
    long long ans = 0;
    for(int i = 0; i < N; i++) {
        sum ^= A[i];
        int it = lower_bound(B.begin(),B.end(),sum)-B.begin();
        long long tmp = tree.query(it,it+1);
        tree.update(it,it+1,-tmp);
        tree.update(0,B.size(),tmp);
        if(A[N-1] == A[i]) {
            ans += tmp;
            ans %= mod;
        }
    }
    cout << ans << endl;
}
0