#1第11128行出错求助
查看原帖
#1第11128行出错求助
1074084
asd890123楼主2024/8/9 08:51

感觉那么后面再出错应该是小问题,麻烦大家看一下哪里没处理好,code:

#include <iostream>

typedef long long LL;

const int N = 500005;

int n,m;
LL a[N],b[N],tree_sum[N],tree_gcd[N];

LL gcd(LL a,LL b){return b ? gcd(b,a % b) : a;}
int lowbit(int x){return x & (-x);}

void update(int x,LL y){

    for (;x <= n;x += lowbit(x)){

        tree_sum[x] += y;
        tree_gcd[x] = gcd(tree_gcd[x],y);
        
    }

}

LL query_sum(int x){

    LL sum = 0;

    for (;x;x -= lowbit(x)) sum += tree_sum[x];

    return sum;
}

LL query_gcd(int x,int y){

    if (y > x){

        if (y - lowbit(y) > x) return gcd(tree_gcd[y],query_gcd(x,y - lowbit(y)));
        else return gcd(b[y],query_gcd(x,y - 1));

    }

    return b[x];
}

int main(){

    #ifndef ONLINE_JUDGE
        freopen("P10463.in","r",stdin);
    #endif

    std::cin.tie(0)->sync_with_stdio(0);

    std::cin >> n >> m;
    for (int i = 1;i <= n;i++){

        std::cin >> a[i];
        b[i] = a[i] - a[i - 1];
        update(i,b[i]);

    }
    while (m--){

        LL d;
        char op;
        int l,r;

        std::cin >> op >> l >> r;
        switch (op){

            case 'C':{
                
                std::cin >> d;
                update(l,d);
                b[l] += d;
                update(r + 1,-d);
                b[r + 1] -= d;
                break;
                
            }
            case 'Q':std::cout << std::abs(gcd(query_sum(l),query_gcd(l + 1,r))) << '\n';break;

        }

    }

    return 0;
}
2024/8/9 08:51
加载中...