2 solutions

  • 1
    @ 2026-3-15 14:36:55
    #include<bits/stdc++.h>
    typedef long long LL;
    using namespace std;
    const int N=2e5+10;
    LL ans=1e9+7;
    int a[N];
    int main()
    {
    	long long n;
    	cin>>n;
    	
    	LL cnt=0;
    	LL sum=0;
    	for(int i=0;i<n;i++)
    	{
    		cin>>a[i];
    		sum+=a[i];
    		sum=sum%ans;
    	}
    	for(int i=0;i<n;i++)
    	{
    		sum-=a[i];
    		if(sum<0) sum+=ans;
    		cnt+=sum*a[i];
    		cnt%=ans;
    	}
    	cout<<cnt;
    	return 0;
    }

    [ABC177C] 数对乘积之和(Sum of product of pairs)

    Information

    ID
    2712
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    # Submissions
    15
    Accepted
    6
    Uploaded By