fork download
  1. #include <bits/stdc++.h>
  2. #define el '\n'
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  6. using namespace std;
  7.  
  8. void TienDat()
  9. {
  10. int k; cin >> k;
  11. vector<ll> X(k) , PW(k + 1 , 0) , PWX (k + 1 , 0);
  12. for (int i = 0 ; i < k ; i++){
  13. ll x , w; cin >> x >> w;
  14. X[i] = x;
  15. PW[i + 1] = PW[i] + w;
  16. PWX[i + 1] = PWX[i] + (w * x);
  17. }
  18. int q; cin >> q;
  19. while (q--){
  20. ll l , r; cin >> l >> r;
  21. cout << X[r - 1] * (PW[r - 1] - PW[l - 1]) - (PWX[r - 1] - PWX[l - 1]) << el;
  22. }
  23. }
  24. int main()
  25. {
  26. ios_base::sync_with_stdio(0);
  27. cin.tie(0);
  28. TienDat();
  29. return 0;
  30. }
  31.  
Runtime error #stdin #stdout 1.13s 2095748KB
stdin
Standard input is empty
stdout
Standard output is empty