大佬们我这是那个细节没处理好吗?一直全wa
查看原帖
大佬们我这是那个细节没处理好吗?一直全wa
938991
zdrtgb159753楼主2025/1/15 11:31
#include<iostream>
#include<cstdio>

using namespace std;

const int  N = 2e5+10;
long long a[N],b[N];

int main(){
    int n;
    long long res;
    cin>>n;
    
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    
    for(int i = 1; i <= n; i++){
        b[i] = b[i-1] + a[i];
    }
    
    for(int i = 1; i <= n-1; i++){
        res += a[i]*(b[n]-b[i]);    
    }
    
    cout<<res<<endl;
    
    return 0;
}
2025/1/15 11:31
加载中...