P2068为什么开了long long也爆了
  • 板块P2068 统计和
  • 楼主Kiichi
  • 当前回复12
  • 已保存回复12
  • 发布时间2022/7/19 10:18
  • 上次更新2023/10/27 19:36:28
查看原帖
P2068为什么开了long long也爆了
381817
Kiichi楼主2022/7/19 10:18

RT

是普通的树状数组解法,为了防爆我还每个数据都换成long long来着 本地调的时候会少输出一行 但是仔细检查了一下没什么问题这样(对手指

希望dalao可以帮忙解答一下(对手指

#include <bits/stdc++.h>
#define ll long long
#define ln inline
#define lowerbit(x) x & -x
#define saysth ilovekanoforever
using namespace std;
const int N = 5 * 1e5 + 5;
ll n, m, a[N], bit[N];
ln void update(ll i, ll x) {for(int pos = i; pos <= n; pos += lowerbit(pos)) bit[pos] += x; }
ln ll bitplus(ll n) {
    ll ans = 0;
    for(ll pos = n; pos; pos -= lowerbit(pos)) ans += bit[pos];
    return ans;
}
ln ll query(ll l, ll r) {return bitplus(r) - bitplus(l - 1); }
int main() {
    scanf("%lld%lld", &n, &m);
    for(ll i = 1; i <= m; ++i) {
        ll a, b; char k;
        scanf("%c%lld%lld", &k, &a, &b);
        if(k == 'x') update(a, b);
        if(k == 'y') printf("%lld\n", query(a, b));
    }
    return 0;
}
2022/7/19 10:18
加载中...