fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n,k;
  5. cin>>n;
  6. int a[n+1];
  7. long long pr[n+2]={0,};
  8. for(int i=1; i<=n; i++)
  9. cin>>a[i];
  10. cin>>k;
  11. for(int i=1; i<=n; i++)
  12. pr[i]=pr[i-1]+a[i];
  13. for(int i=0; i<k; i++){
  14. int x,y;
  15. cin>>x>>y;
  16. cout<<pr[y]*pr[x-1]<<endl;
  17. }
  18. }
Success #stdin #stdout 0.01s 5260KB
stdin
3 3 2
1 2 3
4 5 6
7 8 9
2 2 3 3
1 1 2 3
stdout
0
0