-
Notifications
You must be signed in to change notification settings - Fork 3
/
B.cpp
102 lines (88 loc) · 2.85 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std::literals;
using ll = long long;
using ld = long double;
using ii [[maybe_unused]] = std::pair<int, int>;
using vi [[maybe_unused]] = std::vector<int>;
using vl [[maybe_unused]] = std::vector<ll>;
using vvi [[maybe_unused]] = std::vector<vi>;
using vii [[maybe_unused]] = std::vector<ii>;
using vb [[maybe_unused]] = std::vector<bool>;
using vd [[maybe_unused]] = std::vector<ld>;
using vs [[maybe_unused]] = std::vector<std::string>;
#define FOR(_i, _a, _b) for (int _i = (_a); _i <= (_b); ++(_i))
#define FORD(_i, _a, _b) for (int _i = (_a); _i >= (_b); --(_i))
#define RNG(_l) (_l).begin(), (_l).end()
#define SORT(_l) std::sort((_l).begin(), (_l).end())
#define CI(_v) static_cast<int>(_v)
#define CL(_v) static_cast<ll>(_v)
#define CD(_v) static_cast<ld>(_v)
#define F first
#define S second
#define PB push_back
void Solution([[maybe_unused]] std::istream& cin, [[maybe_unused]] std::ostream& cout) {
int n, T;
ld c;
cin >> n >> T >> c;
vd c_pow(n+1);
c_pow[0] = 1;
FOR(i, 1, n) {
c_pow[i] = c_pow[i-1]*c;
}
vl a(n+1);
vl a_psum(n+1);
vd mean(n+1);
FOR(i, 1, n) {
cin >> a[i];
a_psum[i] = a_psum[i-1] + a[i];
mean[i] = (mean[i-1] + CD(a[i])/T)/c;
}
int m; cin >> m;
FOR(i, 0, m-1) {
int p; cin >> p;
const auto t0 = p-T+1;
const auto t_psum = a_psum[p] - a_psum[t0-1];
ld real = CD(t_psum)/T;
const auto err = std::abs(mean[p]-real)/real;
cout << std::fixed << std::setprecision(6) << real << ' ' << mean[p] << ' ' << err << '\n';
}
}
#ifndef NDEBUG
[[maybe_unused]] std::stringstream ReadFile(const std::string& path) {
std::ifstream file(path);
assert(file);
std::stringstream ss;
ss << file.rdbuf();
file.close();
return ss;
}
[[maybe_unused]] void RunTest(const std::string& in_path, const std::string& out_path) {
std::stringstream cin = ReadFile(in_path);
std::stringstream cout;
const auto e_out = ReadFile(out_path).str();
const auto start_t = std::chrono::high_resolution_clock::now();
Solution(cin, cout);
const auto end_t = std::chrono::high_resolution_clock::now();
const auto total_t = std::chrono::duration_cast<std::chrono::milliseconds>(end_t - start_t).count();
std::cerr << in_path << ", "sv << total_t << " ms"sv << std::endl;
const auto a_out = cout.str();
assert(a_out == e_out);
}
[[maybe_unused]] void TestSolution() {
const std::string dir("../"s);
RunTest(dir + "input1.txt"s, dir + "output1.txt"s);
std::cerr << "TestSolution OK"sv << std::endl;
}
#endif
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
// #ifndef NDEBUG
// TestSolution();
// #endif
Solution(std::cin, std::cout);
return 0;
}