Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr ld eps = 1e-18;
- int n[2], c1 = INT32_MIN, c2 = INT32_MIN, le = INT32_MIN;
- vector<tuple<int, int, bool>> vec[2], events;
- vector<tuple<int, int, int>> coef[2];
- ld ans = 0;
- ld t(ld x) {
- return x * x * x;
- }
- ld s(ld x) {
- return x * x;
- }
- ld func(ld a, ld b, ld c, ld l, ld r) {
- if (r - l < eps)
- return 0;
- return a / 3 * (t(r) - t(l)) +
- b / 2 * (s(r) - s(l)) +
- c * (r - l);
- }
- ld get_ans(tuple<ld, ld, ld> a, tuple<ld, ld, ld> b, ld l, ld r) {
- if (r - l < eps) {
- return 0;
- }
- auto [a1, b1, c1] = a;
- auto [a2, b2, c2] = b;
- a1 -= a2, b1 -= b2, c1 -= c2;
- if (abs(a1) < eps) {
- if (abs(b1) < eps) {
- return abs(c1 * abs(r - l));
- }
- ld x1 = -c1 / b1;
- if (b1 < eps) {
- return
- func(0, b1, c1, l, min(x1, r)) +
- func(0, -b1, -c1, max(l, x1), r);
- }
- else {
- return
- func(0, -b1, -c1, l, min(x1, r)) +
- func(0, b1, c1, max(l, x1), r);
- }
- }
- ld disc = b1 * b1 - a1 * c1 * 4;
- if (disc < eps) {
- if (a1 < eps)
- a1 *= -1, b1 *= -1, c1 *= -1;
- return func(a1, b1, c1, l, r);
- }
- else {
- ld x1 = (-b1 - sqrtl(disc)) / (2 * a1);
- ld x2 = (-b1 + sqrtl(disc)) / (2 * a1);
- if (x1 > x2)
- swap(x1, x2);
- if (a1 < -eps) {
- return
- func(-a1, -b1, -c1, l, min(x1, r)) +
- func(a1, b1, c1, max(l, x1), min(x2, r)) +
- func(-a1, -b1, -c1, max(l, x2), r);
- }
- else {
- return
- func(a1, b1, c1, l, min(x1, r)) +
- func(-a1, -b1, -c1, max(l, x1), min(x2, r)) +
- func(a1, b1, c1, max(l, x2), r);
- }
- }
- }
- void Solve() {
- for (int i = 0; i < 2; i++)
- cin >> n[i];
- for (int i = 0; i < 2; i++) {
- for (int j = 0, v; j <= n[i]; j++) {
- cin >> v;
- vec[i].emplace_back(v, j, i);
- }
- for (int j = 0, a, b, c; j < n[i]; j++) {
- cin >> a >> b >> c;
- coef[i].emplace_back(a, b, c);
- }
- }
- merge(vec[0].begin(), vec[0].end(),
- vec[1].begin(), vec[1].end(),
- back_inserter(events));
- for (auto [d, id, i]: events) {
- if (c1 != INT32_MIN && c2 != INT32_MIN && le != INT32_MIN) {
- ans += get_ans(coef[0][c1], coef[1][c2], le, d);
- le = d;
- if (i)
- c2 = id;
- else
- c1 = id;
- }
- else if (i) {
- le = d;
- c2 = id;
- }
- else {
- le = d;
- c1 = id;
- }
- }
- cout << fixed << setprecision(40) << ans;
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- //auto start = chrono::high_resolution_clock::now();
- Solve();
- //auto end = chrono::high_resolution_clock::now();
- //cout << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement