/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.02 MiB
#2 Wrong Answer 3ms 2.066 MiB
#3 Wrong Answer 3ms 2.02 MiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/
struct FenwickTree {
    vector<int> bit; // binary indexed tree
    int n;

    FenwickTree(int n)
    {
        this->n = n;
        bit.assign(n, 0);
    }

    int sum(int r)
    {
        int ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

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

    void add(int idx, int delta)
    {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};
ll modpow(ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = (res * a) % MOD;
        }
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
pair<ll, ll> jorBijor[100001] {};
void Solve()
{
    ll n, q;
    cin >> n >> q;
    vector<ll> arr(n);
    for (ll i = 0; i < n; i++) {
        cin >> arr[i];
    }
    ll mxPos = 1 + __lg(1000000);
    // dbg(mxPos);
    // cerr << (1 << mxPos) << '\n';
    vector<FenwickTree> fen(mxPos, FenwickTree(n + 1));
    for (ll i = 0; i < n; i++) {
        for (int j = 0; j < mxPos; j++) {
            if (arr[i] & (1 << j)) {
                fen[j].add(i, 1);
            }
        }
    }
    while (q--) {
        ll qt;
        cin >> qt;
        if (qt == 1) {
            ll idx, x;
            cin >> idx >> x;
            idx--;
            for (int j = 0; j < mxPos; j++) {
                if (arr[idx] & (1 << j)) {
                    fen[j].add(idx, -1);
                }
                if (x & (1 << j)) {
                    fen[j].add(idx, 1);
                }
            }
            arr[idx] = x;
        } else {
            ll l, r;
            cin >> l >> r;
            l--, r--;
            ll ans = 0;
            for (int j = 0; j < mxPos; j++) {
                ll oneCount = fen[j].sum(l, r);
                ll zerCount = (r - l + 1) - oneCount;
                ans = (ans + modpow(2, j) * ((jorBijor[oneCount].yy * (modpow(2, zerCount))) % MOD)) % MOD;
            }
            cout << ans << '\n';
        }
    }
}

int32_t main()
{
    jorBijor[0] = { 1, 0 };
    jorBijor[1] = { 1, 1 };
    for (ll i = 2; i <= 100000; i++) {
        jorBijor[i].xx = (jorBijor[i - 1].xx + jorBijor[i - 1].yy) % MOD;
        jorBijor[i].yy = (jorBijor[i - 1].xx + jorBijor[i - 1].yy) % MOD;
    }
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

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 16:51:57
Judged At
2025-04-06 16:51:57
Judged By
Score
1
Total Time
3ms
Peak Memory
2.066 MiB