QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372536#3035. GhostSolitaryDream#WA 811ms4040kbC++173.8kb2024-03-31 15:04:582024-03-31 15:04:58

Judging History

你现在查看的是最新测评结果

  • [2024-03-31 15:04:58]
  • 评测
  • 测评结果:WA
  • 用时:811ms
  • 内存:4040kb
  • [2024-03-31 15:04:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
typedef pair<double, double> pdd;
pdd operator+(pdd a, pdd b) {
    return pdd(a.first + b.first, a.second + b.second);
}
struct Line {
    double k, c;
};
struct Convex {
    vector<Line> line;
    vector<double> cross;
    void Push(double k, double c) {
        line.push_back({k, c});
    }
    inline double CrossX(Line a, Line b) {
        return -(a.c - b.c) / (a.k - b.k); 
    }
    void Solve(vector<double> &sp) {
        sort(line.begin(), line.end(), [](Line a, Line b) {
            if (a.k == b.k) return a.c > b.c;
            return a.k > b.k;
        });
        int top = 0;
        for (int i = 1; i < line.size(); ++i) {
            while (top >= 0) {
                if (line[i].k == line[top].k) {
                    --top;
                } else if (top >= 1 && CrossX(line[i], line[top - 1]) <= CrossX(line[top], line[top - 1])) {
                    --top;
                } else break;
            }
            line[++top] = line[i];
        }
        line.resize(top + 1);
        cross.resize(line.size() - 1);
        for (int i = 0; i < cross.size(); ++i) cross[i] = CrossX(line[i], line[i + 1]);
        for (auto x : cross) if (x > 0) sp.push_back(x);
    }
    pdd Get(double x) {
        int p = lower_bound(cross.begin(), cross.end(), x) - cross.begin();
        return {line[p].k, line[p].c};
    }
    void Clear() {
        line.clear();
        cross.clear();
    }
} U, D, R, L;
vector<pair<double, double>> A;
namespace Seg {
    double f[N];
    int D;
    inline void Init() {
        D = A.size() + 2;
        for (int i = 0; i < A.size(); ++i) {
            f[D + i] = A[i].second;
        }
        for (int i = D - 1; i; --i) f[i] = max(f[i << 1], f[i << 1 | 1]);
    }
    inline double Ask(int x, int y) {
        double ans = 0;
        for (int l = D + x - 1, r = D + y + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
            if (~l & 1) ans = max(ans, f[l ^ 1]);
            if ( r & 1) ans = max(ans, f[r ^ 1]);
        }
        return ans;
    }
}
inline double GetArea(double x) {
    auto [k1, c1] = U.Get(x) + D.Get(x);
    auto [k2, c2] = R.Get(x) + L.Get(x);
    return max(k1 * x + c1, 0.) * max(k2 * x + c2, 0.);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(15);
    int Case;
    cin >> Case;
    while (Case--) {
        L.Clear(); R.Clear();
        U.Clear(); D.Clear();
        int n;
        cin >> n;
        for (int i = 1; i <= n; ++i) {
            int x, y, u, v, dx, dy;
            cin >> x >> y >> u >> v >> dx >> dy;
            U.Push(dy, v); D.Push(-dy, -y);
            R.Push(dx, u); L.Push(-dx, -x); 
        }
        vector<double> sp;
        U.Solve(sp); D.Solve(sp);
        R.Solve(sp); L.Solve(sp);
        sort(sp.begin(), sp.end());
        sp.erase(unique(sp.begin(), sp.end()), sp.end());
        double last = 0;
        A.clear();
        A.push_back({0, GetArea(0)});
        for (auto cur : sp) {
            double mid = (last + cur) * 0.5;
            auto [k1, c1] = U.Get(mid) + D.Get(mid);
            auto [k2, c2] = R.Get(mid) + L.Get(mid);
            double x = -(k1 * c1 + k2 * c2) * 0.5 / (k1 * k2);
            if (x >= last && x <= cur) A.push_back({x, GetArea(x)});
            A.push_back({cur, GetArea(cur)});
        }
        Seg::Init();
        int m;
        cin >> m;
        for (int i = 1; i <= m; ++i) {
            double x, y;
            cin >> x >> y;
            double ans = max(GetArea(x), GetArea(y));
            int p1 = lower_bound(A.begin(), A.end(), pdd(x, 0)) - A.begin();
            int p2 = lower_bound(A.begin(), A.end(), pdd(y, 0)) - A.begin() - 1;
            ans = max(ans, Seg::Ask(p1, p2));
            cout << ans << '\n';
        }
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 811ms
memory: 4040kb

input:

4000
2
-5 -5 3 1 1 -5
-3 -4 -1 2 -2 1
169
4.5924 9.7635
4.9674 5.3219
8.2418 9.6649
6.5743 8.6108
5.3524 6.4199
2.1932 4.3636
1.7115 6.6926
0.5762 4.0628
5.0348 7.5678
6.2170 6.3381
7.1571 8.0276
1.7285 2.3730
0.3843 2.9644
0.0038 0.3971
3.8448 9.7040
4.0458 9.4878
1.6425 7.9132
8.9195 9.4455
4.2563...

output:

0.000000000000000
0.000000000000000
0.000000000000000
0.000000000000000
0.000000000000000
0.000000000000000
0.000000000000000
3.085599999999999
0.000000000000000
0.000000000000000
0.000000000000000
0.000000000000000
5.388400000000001
9.954400000000000
0.000000000000000
0.000000000000000
0.0000000000...

result:

wrong answer Error is to high: expected 1.146825, but got 1.142857