/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 484.0 KiB
#6 Accepted 3ms 532.0 KiB
#7 Accepted 188ms 18.441 MiB
#8 Accepted 194ms 18.586 MiB
#9 Accepted 201ms 18.465 MiB
#10 Accepted 189ms 18.438 MiB
#11 Accepted 143ms 18.066 MiB
#12 Accepted 256ms 18.945 MiB
#13 Accepted 127ms 18.469 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

template<class Fun> class y_combinator_result {
  Fun fun_;
public:
  template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
  template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

template<typename a, typename B> ostream& operator<<(ostream &os, const pair<a, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? ", " : "")), ...); }, t); return os << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename T>ostream& operator<<(ostream& os, queue<T>& _q) { queue<T> q = _q; os << '{'; string sep; while (!q.empty()) { os << sep << q.front(); sep = ", "; q.pop(); } return os << '}';}
template<typename T>ostream& operator<<(ostream& os, stack<T> st) { os << '{'; string sep; while (!st.empty()) { os << sep << st.top(); sep = ", "; st.pop(); } return os << '}';}
template<typename T, typename Container, typename Compare>ostream& operator<<(ostream& os, priority_queue<T, Container, Compare> pq) { os << '{'; string sep; while (!pq.empty()) { os << sep << pq.top(); sep = ", "; pq.pop(); } return os << '}';}
template<size_t n>ostream& operator<<(ostream& os, const bitset<n>& bs) { return os << bs.to_string();}

void debug_out() { cout << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << ' ' << H; debug_out(T...); }
#ifdef LOCAL_DEBUG
  #define debug(...) cout << "[Line " <<  __LINE__ << "] (" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
  #define debug(...)
#endif

/*

*/

const int MOD = 1e9 + 7;
const int MAXB = 21;

int n, q;
vector<int> a, pow2;

struct BIT {
  vector<int> tree;
  int size;

  void init(int n) {
    size = n;
    tree.assign(n + 2, 0);
  }

  void update(int i, int del) {
    while (i <= size) {
      tree[i] += del;
      i += i & -i;
    }
  }

  int query(int i) {
    int res = 0;
    while (i > 0) {
      res += tree[i];
      i -= i & -i;
    }
    return res;
  }

  int query(int l, int r) {
    return query(r) - query(l - 1);
  }
};

vector<BIT> bits;

void update(int pos, int x) {
  for (int bit = 0; bit < MAXB; bit++) {
    int was = (a[pos] >> bit) & 1;
    int is = (x >> bit) & 1;
    if (was != is) {
      bits[bit].update(pos, is - was);
    }
  }
  a[pos] = x;
}

void run_case() {
  cin >> n >> q;
  a.resize(n + 1);
  pow2.resize(n + 1);
  pow2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pow2[i] = (pow2[i - 1] * 2) % MOD;
  }

  bits.resize(MAXB);
  for (int bit = 0; bit < MAXB; bit++) {
    bits[bit].init(n);
  }

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int bit = 0; bit < MAXB; bit++) {
      if ((a[i] >> bit) & 1) {
        bits[bit].update(i, 1);
      }
    }
  }

  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, x;
      cin >> pos >> x;
      update(pos, a[pos] ^ x);
    } else {
      int l, r;
      cin >> l >> r;
      int res = 0;
      for (int bit = 0; bit < MAXB; bit++) {
        int cnt = bits[bit].query(l, r);
        if (cnt > 0) {
          res = (res + (1LL << bit) * pow2[r - l] % MOD) % MOD;
        }
      }
      cout << res << '\n';
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin.exceptions(cin.failbit);

  int T = 1;
  for (int t = 1; t <= T; t++) {
    run_case();
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1183 The Sorcerer’s Subsequence Sum
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 17:56:29
Judged At
2025-04-06 17:56:29
Judged By
Score
100
Total Time
256ms
Peak Memory
18.945 MiB