Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <string>
- #include <queue>
- #include <map>
- #include <bitset>
- #include <vector>
- #include <set>
- #include <cmath>
- #include <iomanip>
- #include <algorithm>
- #include <fstream>
- #include <cmath>
- #include <unordered_map>
- #include <stack>
- #include <math.h>
- #include <queue>
- typedef long long ll;
- using namespace std;
- const ll inf = 1e18;
- double pow(double n, ll power)
- {
- if (power == 0)
- return 1;
- if (power == 1)
- return n;
- double a = pow(n, power / 2);
- if (power % 2 == 0)
- return a * a;
- else
- return a * a * n;
- }
- struct Event
- {
- char type;
- double day, w;
- double val;
- Event()
- {
- type = 'n';
- day = -1;
- w = -1;
- val = -1;
- }
- Event(double day, double w)
- {
- this->type = 'w';
- this->day = day;
- this->w = w;
- }
- Event(double day)
- {
- this->type = 'a';
- this->day = day;
- }
- };
- bool cmp(const Event& e1, const Event& e2)
- {
- return (e1.day == e2.day ? e1.type == 'w' : e1.day < e2.day);
- }
- int main()
- {
- double n, m;
- double r;
- cin >> n >> m >> r;
- vector<Event> v(n + m);
- for (int i = 0; i < n; ++i)
- {
- double d, w;
- cin >> d >> w;
- v[i] = { d, w };
- }
- vector<int> questions(m);
- for (int i = n; i < n + m; ++i)
- {
- double d;
- cin >> d;
- v[i] = { d };
- questions[i - n] = d;
- }
- sort(v.begin(), v.end(), cmp);
- double prev_val = 0;
- double prev_day = 0;
- map<double, double> q_ind;
- for (int i = 0; i < n + m; ++i)
- {
- Event& e = v[i];
- if (e.type == 'a')
- {
- e.val = prev_val * pow(1 - r, e.day - prev_day);
- q_ind[e.day] = i;
- }
- else
- {
- double x = pow(1 - r, e.day - prev_day);
- e.val = (prev_val * x) + (e.w * r);
- prev_day = e.day;
- prev_val = e.val;
- }
- }
- for (int q : questions)
- cout << v[q_ind[q]].val << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement