結果

問題 No.1863 Xor Sum 2...?
ユーザー tnakao0123tnakao0123
提出日時 2022-03-06 17:22:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 42,552 KB
実行使用メモリ 16,308 KB
最終ジャッジ日時 2023-09-28 08:38:08
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,116 KB
testcase_01 AC 5 ms
15,192 KB
testcase_02 AC 6 ms
15,252 KB
testcase_03 AC 6 ms
15,120 KB
testcase_04 AC 5 ms
15,308 KB
testcase_05 AC 12 ms
15,356 KB
testcase_06 AC 8 ms
15,236 KB
testcase_07 AC 16 ms
15,468 KB
testcase_08 AC 16 ms
15,488 KB
testcase_09 AC 35 ms
15,976 KB
testcase_10 AC 32 ms
16,008 KB
testcase_11 AC 20 ms
15,520 KB
testcase_12 AC 16 ms
15,540 KB
testcase_13 AC 27 ms
15,784 KB
testcase_14 AC 32 ms
16,012 KB
testcase_15 AC 26 ms
15,764 KB
testcase_16 AC 27 ms
15,676 KB
testcase_17 AC 18 ms
15,572 KB
testcase_18 AC 10 ms
15,332 KB
testcase_19 AC 15 ms
15,456 KB
testcase_20 AC 22 ms
15,684 KB
testcase_21 AC 30 ms
15,880 KB
testcase_22 AC 14 ms
15,432 KB
testcase_23 AC 38 ms
16,108 KB
testcase_24 AC 40 ms
16,240 KB
testcase_25 AC 42 ms
16,300 KB
testcase_26 AC 41 ms
16,252 KB
testcase_27 AC 42 ms
16,308 KB
testcase_28 AC 41 ms
16,260 KB
testcase_29 AC 41 ms
16,240 KB
testcase_30 AC 41 ms
16,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1863.cc:  No.1863 Xor Sum 2...? - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int BN = 30;

/* typedef */

typedef long long ll;

struct Vec {
  int vs[BN];
  Vec(): vs() {}

  Vec operator+(const Vec &w) const {
    Vec r;
    for (int i = 0; i < BN; i++) r.vs[i] = vs[i] + w.vs[i];
    return r;
  }

  Vec operator-(const Vec &w) const {
    Vec r;
    for (int i = 0; i < BN; i++) r.vs[i] = vs[i] - w.vs[i];
    return r;
  }
};

/* global variables */

int as[MAX_N], bs[MAX_N], bcs[MAX_N + 1], ocs[MAX_N + 1];
Vec avs[MAX_N + 1];

/* subroutines */

bool check(Vec &v0, Vec &v1) {
  for (int i = 0; i < BN; i++)
    if (v0.vs[i] + 1 < v1.vs[i]) return false;
  return true;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);

  for (int i = 0; i < n; i++) {
    avs[i + 1] = avs[i];
    for (int j = 0; j < BN; j++)
      avs[i + 1].vs[j] += (as[i] >> j) & 1;
  }

  for (int i = 0; i < n; i++) {
    bcs[i + 1] = bcs[i] ^ bs[i];
    ocs[i + 1] = ocs[i] + bcs[i + 1];
  }

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int j0 = i, j1 = n + 1;
    while (j0 + 1 < j1) {
      int j = (j0 + j1) / 2;
      if (check(avs[i], avs[j])) j0 = j;
      else j1 = j;
    }
    //printf("i=%d, j0=%d\n", i, j0);

    int oc = ocs[j0] - ocs[i];
    if (! bcs[i]) oc = (j0 - i) - oc;
    sum += oc;
  }

  printf("%lld\n", sum);

  return 0;
}
0