結果

問題 No.1493 隣接xor
ユーザー KudeKude
提出日時 2021-04-30 23:17:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 4,284 ms
コンパイル使用メモリ 267,688 KB
実行使用メモリ 27,580 KB
最終ジャッジ日時 2023-09-26 08:15:51
合計ジャッジ時間 9,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 237 ms
27,388 KB
testcase_04 AC 228 ms
27,268 KB
testcase_05 AC 226 ms
27,572 KB
testcase_06 AC 227 ms
27,320 KB
testcase_07 AC 226 ms
27,580 KB
testcase_08 AC 219 ms
27,392 KB
testcase_09 AC 226 ms
27,452 KB
testcase_10 AC 222 ms
27,324 KB
testcase_11 AC 224 ms
27,320 KB
testcase_12 AC 229 ms
27,264 KB
testcase_13 AC 30 ms
6,412 KB
testcase_14 AC 17 ms
6,252 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 94 ms
15,380 KB
testcase_21 AC 114 ms
17,356 KB
testcase_22 AC 69 ms
13,088 KB
testcase_23 AC 98 ms
15,716 KB
testcase_24 AC 210 ms
26,276 KB
testcase_25 AC 65 ms
12,936 KB
testcase_26 AC 118 ms
18,172 KB
testcase_27 AC 36 ms
9,312 KB
testcase_28 AC 193 ms
25,008 KB
testcase_29 AC 124 ms
18,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VI a(n);
    rep(i, n) cin >> a[i];
    map<int, VI> m;
    int now = 0;
    m[now].push_back(0);
    rep(i, n) {
        now ^= a[i];
        m[now].push_back(i + 1);
    }
    VI nxt(n + 1, -1);
    for(auto& [k, v]: m) {
        int now = n;
        reverse(all(v));
        for(int i: v) {
            if (i) nxt[now] = i;
            now = i;
        }
    }
    vector<mint> s(n + 1);
    mint cur = 0;
    mint ans = 0;
    rep(i, n) {
        mint t;
        if (i) t += s[i];
        else t += 1;
        if (nxt[i] != -1) t -= s[nxt[i]];
        ans += t;
        s[i + 1] = s[i] + t;
    }
    cout << ans.val() << '\n';
}
0