/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 328.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Wrong Answer 1ms 328.0 KiB
#7 Wrong Answer 150ms 9.297 MiB

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <numeric>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::cprint(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

using llong = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using II = pair<int,int>;

class BinaryIndexedTree {
   int N;
   vector<int> tree;
public:
   BinaryIndexedTree(int _N) : N(_N), tree(_N+1) {}

   int query(int idx) const {
      assert(idx <= N);
      int res = 0;
      for (int i = idx; i > 0; i -= (i & -i))
         res += tree[i];
      return res;
   }

   int query(int L, int R) const {
      R = min(R, N);
      L = max(L, 1);
      return L <= R ? query(R) - query(L-1) : 0;
   }

   void update(int idx, int val = 1) {
      for (int i = idx; i <= N; i += (i & -i))
         tree[i] += val;
   }
};

const int MOD = 1000000007;

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N, Q;
   cin >> N >> Q;
   VI A(N+1);
   FOR(i, 1, N) {
      llong x;
      cin >> x;
      assert(x <= 1000000);
      A[i] = x;
   }

   vector<BinaryIndexedTree> BITs(20, BinaryIndexedTree(N));
   REP(j, 20) {
      FOR(i, 1, N) {
         if ((A[i] >> j) & 1) {
            BITs[j].update(i, 1);
         }
      }
   }

   vector<int> POW2(N+1);
   POW2[0] = 1;
   FOR(n, 1, N)
      POW2[n] = (POW2[n-1] * 2LL) % MOD;

   FOR(q, 1, Q) {
      int t;
      cin >> t;
      if (t == 1) {
         int pos;
         llong x;
         cin >> pos >> x;
         assert(x <= 1000000);
         REP(j, 20) {
            if ((x >> j) & 1) {
               // flip j-th bit
               if ((A[pos] >> j) & 1) {
                  // 1 => 0
                  BITs[j].update(pos, -1);
               }
               else {
                  // 0 => 1
                  BITs[j].update(pos, 1);
               }
            }
         }
         A[pos] ^= x;
      }
      else {
         int l, r;
         cin >> l >> r;
         llong res = 0;
         REP(j, 20) {
            int len = r - l + 1;
            int cnt1 = BITs[j].query(l, r);
            if (cnt1 > 0) {
               llong add = POW2[len-1] * POW2[j];
            // DEBUG(j, cnt1, len, add);
               res = (res + add) % MOD;
            }
         }
         cout << res << '\n';
      }
   }

   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:29:12
Judged At
2025-04-06 17:29:12
Judged By
Score
5
Total Time
150ms
Peak Memory
9.297 MiB