結果

問題 No.1493 隣接xor
ユーザー SSRSSSRS
提出日時 2021-04-30 22:13:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 174,836 KB
実行使用メモリ 15,748 KB
最終ジャッジ日時 2023-09-26 06:17:34
合計ジャッジ時間 6,868 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 230 ms
15,388 KB
testcase_04 AC 234 ms
15,464 KB
testcase_05 AC 224 ms
15,548 KB
testcase_06 AC 228 ms
15,504 KB
testcase_07 AC 230 ms
15,512 KB
testcase_08 AC 239 ms
15,740 KB
testcase_09 AC 227 ms
15,500 KB
testcase_10 AC 232 ms
15,500 KB
testcase_11 AC 242 ms
15,696 KB
testcase_12 AC 230 ms
15,748 KB
testcase_13 AC 100 ms
6,260 KB
testcase_14 AC 49 ms
6,204 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 97 ms
9,368 KB
testcase_21 AC 113 ms
10,476 KB
testcase_22 AC 79 ms
8,624 KB
testcase_23 AC 105 ms
9,668 KB
testcase_24 AC 206 ms
14,984 KB
testcase_25 AC 73 ms
8,120 KB
testcase_26 AC 121 ms
10,628 KB
testcase_27 AC 46 ms
6,256 KB
testcase_28 AC 196 ms
14,356 KB
testcase_29 AC 135 ms
11,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
struct binary_indexed_tree{
  int N;
  vector<long long> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  void add(int i, long long x){
    i++;
    while (i <= N){
      BIT[i] += x;
      BIT[i] %= MOD;
      i += i & -i;
    }
  }
  long long sum(int i){
    long long ans = 0;
    while (i > 0){
      ans += BIT[i];
      ans %= MOD;
      i -= i & -i;
    }
    return ans;
  }
  long long sum(int L, int R){
    return (sum(R) + MOD - sum(L)) % MOD;
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> X(N + 1);
  X[0] = 0;
  for (int i = 0; i < N; i++){
    X[i + 1] = X[i] ^ A[i];
  }
  map<int, int> pr;
  binary_indexed_tree dp(N);
  dp.add(0, 1);
  for (int i = 1; i < N; i++){
    long long tmp = dp.sum(pr[X[i]], i);
    dp.add(i, tmp);
    pr[X[i]] = i;
  }
  cout << dp.sum(N) << endl;
}
0