QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426509#2582. 物理实验Max_s_xaM60 962ms11880kbC++146.3kb2024-05-31 13:33:422024-05-31 13:33:42

Judging History

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

  • [2024-05-31 13:33:42]
  • 评测
  • 测评结果:60
  • 用时:962ms
  • 内存:11880kb
  • [2024-05-31 13:33:42]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 2e4 + 10;

int n, L;

struct Point
{
    lf x, y;
    Point(lf _x = 0, lf _y = 0) : x(_x), y(_y) {}
    Point operator + (const Point u) const {return Point(x + u.x, y + u.y);}
    Point operator - (const Point u) const {return Point(x - u.x, y - u.y);}
    lf operator * (const Point u) const {return x * u.x + y * u.y;}
    lf operator ^ (const Point u) const {return x * u.y - y * u.x;}
}a1[MAXN], a2[MAXN], sg[MAXN], b1, b2, ln;

bool type[MAXN];
lf mult[MAXN], pos1[MAXN], pos2[MAXN], dis1[MAXN], dis2[MAXN];
lf pt[MAXN]; int tot;

struct Data
{
    lf k, b; int id;
    Data(lf _k = 0, lf _b = 1e18, int _id = 0) : k(_k), b(_b), id(_id) {}
    lf Calc(lf x) {return k * x + b;}
};

struct SegTree
{
    Data tr[MAXN << 2];
    void Build(int cur, int l, int r)
    {
        tr[cur] = Data();
        if (l == r) return;
        int mid = l + r >> 1;
        Build(cur << 1, l, mid), Build(cur << 1 | 1, mid + 1, r);
    }
    void Update(int cur, int l, int r, int x, int y, Data k)
    {
        // cerr << "Up " << cur << ' ' << l << ' ' << r << '\n';
        // cerr << tr[cur].k << ' ' << tr[cur].b << ' ' << k.k << ' ' << k.b << '\n';
        if (x <= l && r <= y)
        {
            if (k.Calc(pt[l]) < tr[cur].Calc(pt[l]) && k.Calc(pt[r]) < tr[cur].Calc(pt[r])) return tr[cur] = k, void();
            if (k.Calc(pt[l]) > tr[cur].Calc(pt[l]) && k.Calc(pt[r]) > tr[cur].Calc(pt[r])) return;
        }
        int mid = l + r >> 1;
        if (x <= mid) Update(cur << 1, l, mid, x, y, k);
        if (y > mid) Update(cur << 1 | 1, mid + 1, r, x, y, k);
    }
    pair <lf, int> Query(int cur, int l, int r, int x)
    {
        auto res = make_pair(tr[cur].Calc(pt[x]), tr[cur].id);
        if (l == r) return res;
        int mid = l + r >> 1;
        if (x <= mid) res = min(res, Query(cur << 1, l, mid, x));
        else res = min(res, Query(cur << 1 | 1, mid + 1, r, x));
        return res;
    }
}S[2];

lf f[MAXN], g[MAXN];

inline void Solve()
{
    Read(n);
    for (int i = 1; i <= n; i++)
        Read(a1[i].x), Read(a1[i].y), Read(a2[i].x), Read(a2[i].y), sg[i] = a2[i] - a1[i];
    Read(b1.x), Read(b1.y), Read(b2.x), Read(b2.y), Read(L);
    ln = b2 - b1, tot = 0;
    lf len = sqrt(ln * ln);
    for (int i = 1; i <= n; i++)
    {
        type[i] = ((a1[i] - b1) ^ ln) > 0;
        mult[i] = fabs(1.0 / (sg[i] * ln) * len * sqrt(sg[i] * sg[i]));
        pt[++tot] = pos1[i] = (a1[i] - b1) * ln / len;
        pt[++tot] = pos2[i] = (a2[i] - b1) * ln / len;
        dis1[i] = fabs(((a1[i] - b1) ^ ln) / len);
        dis2[i] = fabs(((a2[i] - b1) ^ ln) / len);
    }
    sort(pt + 1, pt + tot + 1), tot = unique(pt + 1, pt + tot + 1) - pt - 1;
    // for (int i = 1; i <= tot; i++) cout << pt[i] << ' '; cout << '\n';
    // for (int i = 1; i <= n; i++) cout << mult[i] << ' '; cout << '\n';
    // cout << tot << "\n";
    S[0].Build(1, 1, tot), S[1].Build(1, 1, tot);
    for (int i = 1; i <= n; i++)
    {
        Data cur = Data((dis2[i] - dis1[i]) / (pos2[i] - pos1[i]), (dis1[i] * pos2[i] - dis2[i] * pos1[i]) / (pos2[i] - pos1[i]), i);
        int lb = lower_bound(pt + 1, pt + tot + 1, pos1[i]) - pt, rb = lower_bound(pt + 1, pt + tot + 1, pos2[i]) - pt;
        if (lb > rb) swap(lb, rb); rb--;
        S[type[i]].Update(1, 1, tot, lb, rb, cur);
    }
    for (int i = 1; i < tot; i++)
    {
        auto c1 = S[0].Query(1, 1, tot, i), c2 = S[1].Query(1, 1, tot, i);
        g[i] = (c1.second ? mult[c1.second] : 0) + (c2.second ? mult[c2.second] : 0), f[i] = f[i - 1] + g[i] * (pt[i + 1] - pt[i]);
        // cout << g[i] << ' ' << f[i] << '\n';
    }
    // cout << "#\n";
    lf ans = 0;
    for (int i = 1; i < tot; i++)
    {
        int nxt = lower_bound(pt + 1, pt + tot + 1, pt[i] + L) - pt - 1;
        // cout << i << ' ' << nxt << '\n';
        ans = max(ans, f[nxt - 1] - f[i - 1] + g[nxt] * (pt[i] + L - pt[nxt]));
        // cout << ans << "\n";
    }
    for (int i = tot - 1; i; i--)
    {
        int nxt = lower_bound(pt + 1, pt + tot + 1, pt[i + 1] - L) - pt;
        ans = max(ans, f[i] - f[nxt - 1] + g[nxt - 1] * (pt[nxt] - pt[i + 1] + L));
    }
    cout << ans << '\n';
}

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    cout.precision(10);
    int T;
    Read(T);
    while (T--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 10052kb

input:

100
100
7143 -4407 6148 -4332
-3698 1987 -3674 2827
-2240 -6374 -3784 -6054
149 599 327 597
-2580 -4497 -2820 -4347
9219 -1818 6904 502
-5893 1341 -4357 -1890
-3503 -3287 -1087 -1211
-1579 7118 -229 7556
6456 502 1926 -1748
540 6714 -528 6825
1561 8432 -701 8357
422 6998 -41 7462
-1793 3676 1602 517...

output:

939.7746774
454.2962581
270.0970129
17826.67862
693.633849
649.8851852
16421.69396
1046.519449
1243.731543
620.6825538
1320.056628
19054.04065
1062.022274
684.4295602
421.1793538
1051.711171
850.6338037
22608.7457
13436.19315
261.7821713
304.1380711
916.0257133
346.0687906
474.1366754
28578.8282
878...

result:

wrong answer wrong answer, 7th numbers differ - expected: '16035.001859', found: '16421.693960', error = '0.024116'

Test #2:

score: 40
Accepted
time: 903ms
memory: 10972kb

input:

100
10000
954303 48690 -14339 924721
464270 12166 -1609 433494
873644 42682 -12246 843861
449837 10414 -1919 418980
537496 14550 -6578 506603
552080 15962 -6594 521226
870138 42252 -12332 840332
57161 -702218 -671596 -43163
38907 -433607 -402515 -34409
445719 9913 -1981 414808
399734 5765 -1530 3686...

output:

23150.53687
1591692.183
21928.60438
2894.660855
14332
10772.20012
61378.57525
113952.2762
34711.41136
54764.07872
76852.12248
87090.61784
5004.104596
79872.51685
69493.49706
90559.40478
86547.59555
17134.66504
25861.52098
129826.1283
55853.34233
24438.20191
22124.25578
16452.78807
86333.31367
14422....

result:

ok ok, 100 numbers

Test #3:

score: 20
Accepted
time: 962ms
memory: 11880kb

input:

100
10000
-636684471 -90006000 664665488 86376811
-263230447 -307903883 362658164 -223073366
-575841687 -121133860 614287459 40176834
-258935135 -268238570 347975250 -185982857
-287828480 -521064727 443096738 -422002609
-315452625 -391084040 435133968 -289354496
-560776752 -215271244 624810954 -5458...

output:

13997587.66
17046702.42
46390075.52
7797517.42
24229463.21
13387746.94
11290240.3
55253758.74
60559802.18
80996320.54
16696606
18751679.5
76860841.81
22030848.05
68197919.17
240324280.7
24528596
15482269.82
55237600.53
14731602.31
65393781.04
74259854.81
8098494.693
55469930.43
23796798.53
55979488....

result:

ok ok, 100 numbers