求差错
T3
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 多次求交叉乘
* @param a int整型vector a1,a2,...,an
* @param query int整型vector l1,r1,l2,r2,...,lq,rq
* @return int整型vector
*/
vector<int>ans;
long long sum1[500005],sum2[500005],mod=1e9+7;
vector<int> getSum(vector<int>& a, vector<int>& query) {
// write code here
sum1[1]=a[0];sum2[1]=a[0]*a[0]%mod;
for(long long i=1;i<a.size();i++)sum1[i+1]=(sum1[i]+a[i])%mod;
for(long long i=1;i<a.size();i++)sum2[i+1]=(sum2[i]+1ll*a[i]*a[i]%mod)%mod;
for(long long i=0;i<query.size();i+=2)
{
long long l=query[i],r=query[i+1];
long long tmp1=((sum1[r]-sum1[l-1])%mod+mod)%mod,tmp2=tmp1*tmp1%mod;
long long asd1=((sum2[r]-sum2[l-1])%mod+mod)%mod;tmp2=((tmp2-asd1)%mod+mod)%mod;
ans.push_back((int)(tmp2*500000004ll%mod));
}
return ans;
}
};
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 多次求交叉乘
* @param a int整型vector a1,a2,...,an
* @param query int整型vector l1,r1,l2,r2,...,lq,rq
* @return int整型vector
*/
vector<int>ans;
long long sum1[500005],sum2[500005],mod=1e9+7;
vector<int> getSum(vector<int>& a, vector<int>& query) {
// write code here
sum1[1]=a[0];sum2[1]=a[0]*a[0]%mod;
for(long long i=1;i<a.size();i++)sum1[i+1]=(sum1[i]+a[i])%mod;
for(long long i=1;i<a.size();i++)sum2[i+1]=(sum2[i]+1ll*a[i]*a[i]%mod)%mod;
for(long long i=0;i<query.size();i+=2)
{
long long l=query[i],r=query[i+1];
long long tmp1=((sum1[r]-sum1[l-1])%mod+mod)%mod,tmp2=tmp1*tmp1%mod;
long long asd1=((sum2[r]-sum2[l-1])%mod+mod)%mod;tmp2=((tmp2-asd1)%mod+mod)%mod;
ans.push_back((int)(tmp2*500000004ll%mod));
}
return ans;
}
};