Advertisement
limimage

task C

Feb 9th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 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-18;
  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>> coef[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 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. if (r - l < eps) {
  34. return 0;
  35. }
  36. auto [a1, b1, c1] = a;
  37. auto [a2, b2, c2] = b;
  38. a1 -= a2, b1 -= b2, c1 -= c2;
  39. if (abs(a1) < eps) {
  40. if (abs(b1) < eps) {
  41. return abs(c1 * abs(r - l));
  42. }
  43. ld x1 = -c1 / b1;
  44. if (b1 < eps) {
  45. return
  46. func(0, b1, c1, l, min(x1, r)) +
  47. func(0, -b1, -c1, max(l, x1), r);
  48. }
  49. else {
  50. return
  51. func(0, -b1, -c1, l, min(x1, r)) +
  52. func(0, b1, c1, max(l, x1), r);
  53. }
  54. }
  55. ld disc = b1 * b1 - a1 * c1 * 4;
  56. if (disc < eps) {
  57. if (a1 < eps)
  58. a1 *= -1, b1 *= -1, c1 *= -1;
  59. return func(a1, b1, c1, l, r);
  60. }
  61. else {
  62. ld x1 = (-b1 - sqrtl(disc)) / (2 * a1);
  63. ld x2 = (-b1 + sqrtl(disc)) / (2 * a1);
  64. if (x1 > x2)
  65. swap(x1, x2);
  66. if (a1 < -eps) {
  67. return
  68. func(-a1, -b1, -c1, l, min(x1, r)) +
  69. func(a1, b1, c1, max(l, x1), min(x2, r)) +
  70. func(-a1, -b1, -c1, max(l, x2), r);
  71. }
  72. else {
  73. return
  74. func(a1, b1, c1, l, min(x1, r)) +
  75. func(-a1, -b1, -c1, max(l, x1), min(x2, r)) +
  76. func(a1, b1, c1, max(l, x2), r);
  77. }
  78. }
  79. }
  80.  
  81. void Solve() {
  82. for (int i = 0; i < 2; i++)
  83. cin >> n[i];
  84. for (int i = 0; i < 2; i++) {
  85. for (int j = 0, v; j <= n[i]; j++) {
  86. cin >> v;
  87. vec[i].emplace_back(v, j, i);
  88. }
  89. for (int j = 0, a, b, c; j < n[i]; j++) {
  90. cin >> a >> b >> c;
  91. coef[i].emplace_back(a, b, c);
  92. }
  93. }
  94. merge(vec[0].begin(), vec[0].end(),
  95. vec[1].begin(), vec[1].end(),
  96. back_inserter(events));
  97. for (auto [d, id, i]: events) {
  98. if (c1 != INT32_MIN && c2 != INT32_MIN && le != INT32_MIN) {
  99. ans += get_ans(coef[0][c1], coef[1][c2], le, d);
  100. le = d;
  101. if (i)
  102. c2 = id;
  103. else
  104. c1 = id;
  105. }
  106. else if (i) {
  107. le = d;
  108. c2 = id;
  109. }
  110. else {
  111. le = d;
  112. c1 = id;
  113. }
  114. }
  115. cout << fixed << setprecision(40) << ans;
  116. }
  117.  
  118. int main(){
  119. ios::sync_with_stdio(false);
  120. cin.tie(nullptr);
  121. cout.tie(nullptr);
  122. //auto start = chrono::high_resolution_clock::now();
  123. Solve();
  124. //auto end = chrono::high_resolution_clock::now();
  125. //cout << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  126. return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement