fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. ll n,x,y,ans,res,d,k,sum,testcase=1,a[100005],i,j,b[100005],c[100005];
  5. void stake13007(){
  6. cin>>n>>k;
  7. b[0]=0;
  8. c[0]=0;
  9. for (i=1; i<=n; i++) {
  10. cin>>a[i];
  11. b[i]=b[i-1]+a[i];
  12. c[i]=c[i-1]+a[i]*a[i];
  13. }
  14. while (k--) {
  15. ans=0; res=0;
  16. cin>>x>>y;
  17. res=b[y]-b[x-1];
  18. ans=(res*res+c[x-1]-c[y])/2;
  19. cout<<ans<<endl;
  20. }
  21. }
  22. int main() {
  23. //cin>>testcase;
  24. while (testcase--){
  25. stake13007();
  26. }
  27. }
  28.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty