Advertisement
limimage

taskJ

Apr 21st, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = 1e5 + 5;
  10.  
  11. vector<ld> pref;
  12. int n, q, l, r;
  13.  
  14. ld get(ld cl, ld cr) {
  15. return (cr - cl + 1) / (pref[cr] - pref[cl - 1]);
  16. }
  17.  
  18. void Solve() {
  19. cin >> n;
  20. pref.resize(n + 1);
  21. pref[0] = 0;
  22. for (int i = 1; i <= n; i++) {
  23. cin >> pref[i];
  24. pref[i] = 1 / pref[i];
  25. pref[i] += pref[i - 1];
  26. }
  27. cin >> q;
  28. while(q--) {
  29. cin >> l >> r;
  30. l++, r++;
  31. cout << fixed << setprecision(20) << get(l, r) << endl;
  32. }
  33. }
  34.  
  35. int main() {
  36. ios::sync_with_stdio(false);
  37. cin.tie(nullptr);
  38. cout.tie(nullptr);
  39. // cin >> t;
  40. // while(t--)
  41. //auto start = chrono::high_resolution_clock::now();
  42. Solve();
  43. //auto end = chrono::high_resolution_clock::now();
  44. //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement