Asa's CP Library

a01sa01to's competitive programming library.

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub a01sa01to/cp-library

:heavy_check_mark: tests/data-structure/bit/abc185-f.test.cpp

Depends on

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#include "../../../cpp/library/data-structure/bit.hpp"
#define PROBLEM "https://atcoder.jp/contests/abc185/tasks/abc185_f"

int op(int a, int b) { return a ^ b; }
int e() { return 0; }

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  asalib::ds::BIT<int, op, op, e> b(n);
  rep(i, n) {
    int a;
    cin >> a;
    b.add(i, a);
  }
  while (q--) {
    int t, x, y;
    cin >> t >> x >> y;
    --x;
    if (t == 1) {
      b.add(x, y);
    }
    else {
      cout << b.sum(x, y) << '\n';
    }
  }
  return 0;
}
#line 1 "tests/data-structure/bit/abc185-f.test.cpp"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#line 2 "library/data-structure/bit.hpp"

#line 4 "library/data-structure/bit.hpp"
using namespace std;

#line 2 "library/_internal/types.hpp"

#include <concepts>
#include <type_traits>
using namespace std;

#line 2 "library/_internal/modint-base.hpp"

#line 5 "library/_internal/modint-base.hpp"
using namespace std;

namespace asalib {
  namespace _internal {
    class modint_base {};

    template<typename T>
    concept is_modint = is_base_of_v<modint_base, T>;
  }  // namespace _internal
}  // namespace asalib
#line 8 "library/_internal/types.hpp"

namespace asalib {
  namespace _internal {
    // ---------- concept definition ---------- //
    template<class T>
    concept integral_like = integral<T> || is_modint<T>;

    template<class T>
    concept floating_like = floating_point<T>;

    template<class T>
    concept numeric_like = integral_like<T> || floating_like<T>;

    // ---------- function definition ---------- //
    template<class T>
    T plus(T a, T b) { return a + b; }

    template<class T>
    T minus(T a, T b) { return a - b; }

    // ---------- constant definition ---------- //
    template<class T>
    T zero() { return 0; }
  }  // namespace _internal
}  // namespace asalib
#line 7 "library/data-structure/bit.hpp"

namespace asalib {
  namespace ds {
    template<_internal::numeric_like T, T (*op)(T, T) = _internal::plus<T>, T (*invop)(T, T) = _internal::minus<T>, T (*e)() = _internal::zero<T>>
    class BIT {
      public:
      BIT(): _n(0) {}
      explicit BIT(size_t n) {
        _n = n;
        data.reserve(n);
        data.resize(n, 0);
      }

      void add(size_t i, T x) {
        assert(0 <= i && i < _n);
        ++i;
        while (i <= _n) {
          data[i - 1] = op(data[i - 1], x);
          i += i & -i;
        }
      }

      T sum(size_t l, size_t r) const {
        assert(0 <= l && l <= r && r <= _n);
        return invop(_sum(r), _sum(l));
      }

      private:
      size_t _n;
      vector<T> data;
      T _sum(size_t i) const {
        T s = e();
        while (i > 0) {
          s = op(s, data[i - 1]);
          i -= i & -i;
        }
        return s;
      }
    };
  }  // namespace ds
}  // namespace asalib
#line 8 "tests/data-structure/bit/abc185-f.test.cpp"
#define PROBLEM "https://atcoder.jp/contests/abc185/tasks/abc185_f"

int op(int a, int b) { return a ^ b; }
int e() { return 0; }

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  asalib::ds::BIT<int, op, op, e> b(n);
  rep(i, n) {
    int a;
    cin >> a;
    b.add(i, a);
  }
  while (q--) {
    int t, x, y;
    cin >> t >> x >> y;
    --x;
    if (t == 1) {
      b.add(x, y);
    }
    else {
      cout << b.sum(x, y) << '\n';
    }
  }
  return 0;
}
Back to top page