結果

問題 No.1493 隣接xor
ユーザー ぷらぷら
提出日時 2021-06-11 18:09:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,303 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 212,920 KB
実行使用メモリ 13,048 KB
最終ジャッジ日時 2023-08-21 05:46:18
合計ジャッジ時間 12,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 404 ms
12,780 KB
testcase_04 AC 380 ms
12,904 KB
testcase_05 AC 405 ms
13,048 KB
testcase_06 AC 402 ms
12,792 KB
testcase_07 AC 398 ms
12,904 KB
testcase_08 AC 390 ms
12,784 KB
testcase_09 AC 395 ms
12,736 KB
testcase_10 AC 399 ms
12,784 KB
testcase_11 AC 386 ms
12,736 KB
testcase_12 AC 406 ms
12,996 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 193 ms
8,204 KB
testcase_21 AC 220 ms
8,296 KB
testcase_22 AC 149 ms
7,668 KB
testcase_23 AC 191 ms
8,352 KB
testcase_24 AC 371 ms
12,704 KB
testcase_25 AC 144 ms
7,712 KB
testcase_26 AC 220 ms
8,096 KB
testcase_27 AC 88 ms
5,704 KB
testcase_28 AC 354 ms
12,756 KB
testcase_29 AC 243 ms
8,236 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;
    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(i+1 == N) {
            cout << tmp << endl;
        }
    }
}
0