Advertisement
Alex-Flexer

Untitled

Sep 26th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <string>
  4. #include <queue>
  5. #include <map>
  6. #include <bitset>
  7. #include <vector>
  8. #include <set>
  9. #include <cmath>
  10. #include <iomanip>
  11. #include <algorithm>
  12. #include <fstream>
  13. #include <cmath>
  14. #include <unordered_map>
  15. #include <stack>
  16. #include <math.h>
  17. #include <queue>
  18.  
  19. typedef long long ll;
  20. using namespace std;
  21.  
  22. const ll inf = 1e18;
  23.  
  24. double pow(double n, ll power)
  25. {
  26. if (power == 0)
  27. return 1;
  28. if (power == 1)
  29. return n;
  30. double a = pow(n, power / 2);
  31. if (power % 2 == 0)
  32. return a * a;
  33. else
  34. return a * a * n;
  35. }
  36.  
  37. struct Event
  38. {
  39. char type;
  40. double day, w;
  41. double val;
  42.  
  43. Event()
  44. {
  45. type = 'n';
  46. day = -1;
  47. w = -1;
  48. val = -1;
  49. }
  50.  
  51. Event(double day, double w)
  52. {
  53. this->type = 'w';
  54. this->day = day;
  55. this->w = w;
  56. }
  57. Event(double day)
  58. {
  59. this->type = 'a';
  60. this->day = day;
  61. }
  62. };
  63.  
  64. bool cmp(const Event& e1, const Event& e2)
  65. {
  66. return (e1.day == e2.day ? e1.type == 'w' : e1.day < e2.day);
  67. }
  68.  
  69. int main()
  70. {
  71. double n, m;
  72. double r;
  73. cin >> n >> m >> r;
  74. vector<Event> v(n + m);
  75. for (int i = 0; i < n; ++i)
  76. {
  77. double d, w;
  78. cin >> d >> w;
  79. v[i] = { d, w };
  80. }
  81. vector<int> questions(m);
  82. for (int i = n; i < n + m; ++i)
  83. {
  84. double d;
  85. cin >> d;
  86. v[i] = { d };
  87. questions[i - n] = d;
  88. }
  89. sort(v.begin(), v.end(), cmp);
  90.  
  91. double prev_val = 0;
  92. double prev_day = 0;
  93. map<double, double> q_ind;
  94. for (int i = 0; i < n + m; ++i)
  95. {
  96. Event& e = v[i];
  97. if (e.type == 'a')
  98. {
  99. e.val = prev_val * pow(1 - r, e.day - prev_day);
  100. q_ind[e.day] = i;
  101. }
  102. else
  103. {
  104. double x = pow(1 - r, e.day - prev_day);
  105. e.val = (prev_val * x) + (e.w * r);
  106. prev_day = e.day;
  107. prev_val = e.val;
  108. }
  109. }
  110.  
  111. for (int q : questions)
  112. cout << v[q_ind[q]].val << ' ';
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement