結果

問題 No.1863 Xor Sum 2...?
ユーザー niuezniuez
提出日時 2022-03-04 22:53:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,176 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 201,252 KB
実行使用メモリ 4,772 KB
最終ジャッジ日時 2023-09-26 02:05:59
合計ジャッジ時間 4,814 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 11 ms
4,384 KB
testcase_06 AC 5 ms
4,384 KB
testcase_07 AC 18 ms
4,380 KB
testcase_08 AC 18 ms
4,384 KB
testcase_09 AC 45 ms
4,444 KB
testcase_10 AC 41 ms
4,380 KB
testcase_11 AC 24 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 33 ms
4,380 KB
testcase_14 AC 41 ms
4,384 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 34 ms
4,384 KB
testcase_17 AC 20 ms
4,380 KB
testcase_18 AC 9 ms
4,384 KB
testcase_19 AC 16 ms
4,384 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 38 ms
4,380 KB
testcase_22 AC 15 ms
4,384 KB
testcase_23 AC 48 ms
4,436 KB
testcase_24 AC 51 ms
4,600 KB
testcase_25 AC 54 ms
4,652 KB
testcase_26 AC 54 ms
4,772 KB
testcase_27 AC 54 ms
4,544 KB
testcase_28 AC 54 ms
4,600 KB
testcase_29 AC 54 ms
4,696 KB
testcase_30 AC 54 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];
  vector<i64> B(N);
  rep(i,0,N) cin >> B[i];

  i64 l = 0;
  i64 bits = 0;
  i64 b_sum = 0;
  i64 l_sum = 0;
  vector<i64> cnt(2);

  i64 ans = 0;
  for(int r = 0; r < N; r++) {
    while(bits & A[r]) {
      bits = bits & (~A[l]);
      l_sum ^= B[l];
      cnt[l_sum]--;
      l++;
    }
    bits |= A[r];
    b_sum ^= B[r];
    //cout << l << " " << r << " " << b_sum << "^" << l_sum << " " << cnt[0] << ":" << cnt[1] << endl;
    ans += cnt[b_sum] + (b_sum == l_sum);
    cnt[b_sum]++;
  }
  cout << ans << endl;
}
0