Advertisement
limimage

task C

Apr 6th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 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 ld eps = 1e-9;
  10.  
  11. int n[2], c1 = INT32_MIN, c2 = INT32_MIN, le = INT32_MIN;
  12. vector<tuple<int, int, bool>> vec[2], events;
  13. vector<tuple<int, int, int>> coefs[2];
  14. ld ans = 0;
  15.  
  16. ld t(ld x) {
  17. return x * x * x;
  18. }
  19.  
  20. ld s(ld x) {
  21. return x * x;
  22. }
  23.  
  24. ld func(ld a, ld b, ld c, ld l, ld r) {
  25. if (r - l < eps)
  26. return 0;
  27. return abs(a / 3 * (t(r) - t(l)) +
  28. b / 2 * (s(r) - s(l)) +
  29. c * (r - l));
  30. }
  31.  
  32. ld get_ans(tuple<ld, ld, ld> a, tuple<ld, ld, ld> b, ld l, ld r) {
  33. auto [a1, b1, c1] = a;
  34. auto [a2, b2, c2] = b;
  35. a1 -= a2, b1 -= b2, c1 -= c2;
  36. if (abs(a1) < eps) {
  37. if (abs(b1) < eps) {
  38. return func(a1, b1, c1, l, r);
  39. }
  40. ld x1 = -c1 / b1;
  41. return
  42. func(0, b1, c1, l, min(x1, r)) +
  43. func(0, b1, c1, max(l, x1), r);
  44. }
  45. ld disc = b1 * b1 - a1 * c1 * 4;
  46. if (disc < eps) {
  47. return func(a1, b1, c1, l, r);
  48. }
  49. else {
  50. ld x1 = (-b1 - sqrtl(disc)) / (2 * a1);
  51. ld x2 = (-b1 + sqrtl(disc)) / (2 * a1);
  52. if (x1 > x2)
  53. swap(x1, x2);
  54. return
  55. func(a1, b1, c1, l, min(x1, r)) +
  56. func(a1, b1, c1, max(l, x1), min(x2, r)) +
  57. func(a1, b1, c1, max(l, x2), r);
  58. }
  59. }
  60.  
  61. void Solve() {
  62. for (int i = 0; i < 2; i++)
  63. cin >> n[i];
  64. for (int i = 0; i < 2; i++) {
  65. for (int j = 0, v; j <= n[i]; j++) {
  66. cin >> v;
  67. vec[i].emplace_back(v, j, i);
  68. }
  69. for (int j = 0, a, b, c; j < n[i]; j++) {
  70. cin >> a >> b >> c;
  71. coefs[i].emplace_back(a, b, c);
  72. }
  73. }
  74. merge(vec[0].begin(), vec[0].end(),
  75. vec[1].begin(), vec[1].end(),
  76. back_inserter(events));
  77. for (auto [d, id, i]: events) {
  78. if (c1 != INT32_MIN && c2 != INT32_MIN && le != INT32_MIN) {
  79. ans += get_ans(coefs[0][c1], coefs[1][c2], le, d);
  80. le = d;
  81. if (i)
  82. c2 = id;
  83. else
  84. c1 = id;
  85. }
  86. else if (i) {
  87. le = d;
  88. c2 = id;
  89. }
  90. else {
  91. le = d;
  92. c1 = id;
  93. }
  94. }
  95. cout << fixed << setprecision(10) << ans;
  96. }
  97.  
  98. int main(){
  99. ios::sync_with_stdio(false);
  100. cin.tie(nullptr);
  101. cout.tie(nullptr);
  102. //auto start = chrono::high_resolution_clock::now();
  103. Solve();
  104. //auto end = chrono::high_resolution_clock::now();
  105. //cout << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement