树状数组

    科技2024-10-20  26

    树状数组

    1.求lowbit

    int lowbit(int x) {return x & -x;}

    2.更新(pudate)

    void _Update(int index, int x) { for(int i = index; i <= n; i += _Lowbit(i)) BIT[i] += x; return; }

    3.求前缀和

    int _Sum(int x) { int sum = 0; for(int i = x; i > 0; i -= _Lowbit(i)) sum += BIT[i]; return sum; }
    Processed: 0.025, SQL: 8