Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iomanip>
- #include <iostream>
- double* Production(const double* arr, double* product, int amount) {
- double lower = static_cast<double>(1) / static_cast<double>(10000);
- product[0] = pow(arr[0], lower);
- for (int i = 1; i < amount; ++i) {
- product[i] = product[i - 1] * pow(arr[i], lower);
- }
- return product;
- }
- void FindNoise() {
- int num_of_plants = 0;
- std::cin >> num_of_plants;
- double* arr = new double[num_of_plants];
- double* product = new double[num_of_plants];
- for (int i = 0; i < num_of_plants; ++i) {
- std::cin >> arr[i];
- }
- product = Production(arr, product, num_of_plants);
- CountNoise(product, arr);
- delete[] arr;
- delete[] product;
- }
- void CountNoise(const double* product, const double* arr) {
- int func_calls = 0, left = 0, right = 0;
- double LowerFirstCase =
- static_cast<double>(10000) / static_cast<double>(right - left + 1);
- double LowerSecondCase =
- static_cast<double>(10000) / static_cast<double>(right + 1);
- std::cin >> func_calls;
- for (int i = 0; i < func_calls; ++i) {
- std::cin >> left;
- std::cin >> right;
- if (left != right && left != 0) {
- std::cout << std::fixed << std::setprecision(10)
- << pow(product[right] / product[left - 1], LowerFirstCase)
- << "\n";
- } else if (left == right) {
- std::cout << std::fixed << std::setprecision(10) << arr[right] << "\n";
- } else if (left == 0) {
- std::cout << std::fixed << std::setprecision(10)
- << pow(product[right], LowerSecondCase) << "\n";
- }
- }
- }
- int main() {
- FindNoise();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement