QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194105#7520. Monster Generatorucup-team1191#WA 0ms3788kbC++205.4kb2023-09-30 18:59:082023-11-04 18:36:26

Judging History

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

  • [2023-11-04 18:36:26]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2023-11-04 17:09:43]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:3864kb
  • [2023-09-30 18:59:09]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3568kb
  • [2023-09-30 18:59:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

const int M = 110;

ll dv(ll a, ll b) {
    if (a >= 0 || a % b == 0) {
        return a / b;
    }
    return (a / b) - 1;
}

ll dvup(ll a, ll b) {
    if (a % b == 0 || a < 0) {
        return (a / b);
    }
    return (a / b) + 1;
}

int n;
ll m;
ll a[M], da[M], b[M], db[M];

void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> da[i] >> b[i] >> db[i];
    }
    vector<ll> vx;
    vx.emplace_back(0);
    vx.emplace_back(m);
    auto add = [&](ll x) {
        if (x <= 0 || x >= m) {
            return;
        }
        vx.emplace_back(x);
    };
    for (int i = 0; i < n; i++) {
        ll u = b[i] - a[i];
        ll v = db[i] - da[i];
        if (v == 0) {
            continue;
        }
        if (v > 0) {
            add(dvup(-u, v));
        } else {
            add(dv(u, -v) + 1);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ll u = a[i] - a[j];
            ll v = da[i] - da[j];
            if (v == 0) {
                continue;
            }
            if (v > 0) {
                add(dvup(-u, v));
            } else {
                add(dv(u, -v) + 1);
            }
        }
    }
    sort(vx.begin(), vx.end());
    vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
    auto func = [&](ll k) {
        vector<pair<__int128, __int128>> pos;
        vector<pair<__int128, __int128>> neg;
        for (int i = 0; i < n; i++) {
            __int128 u = (__int128)a[i] + (__int128)da[i] * k;
            __int128 v = (__int128)b[i] + (__int128)db[i] * k;
            v -= u;
            if (v < 0) {
                neg.emplace_back(u, v);
            } else {
                pos.emplace_back(u, v);
            }
        }
        sort(pos.begin(), pos.end());
        sort(neg.rbegin(), neg.rend());
        __int128 delta = 0;
        __int128 ans = 0;
        for (auto& [ch, df] : pos) {
            ans = max(ans, ch - delta);
            delta += df;
        }
        for (auto& [ch, df] : neg) {
            ans = max(ans, ch - delta);
            delta += df;
        }
        return (ull)ans;
    };
    ull res = func(0);
    for (int ps = 0; ps + 1 < (int)vx.size(); ps++) {
        ll L = vx[ps] + 1;
        ll R = vx[ps + 1];
        if (L == R) {
            res += func(L);
            continue;
        }
        vector<tuple<__int128, __int128, int>> pos;
        vector<tuple<__int128, __int128, int>> neg;
        for (int i = 0; i < n; i++) {
            __int128 u = (__int128)a[i] + (__int128)da[i] * L;
            __int128 v = (__int128)b[i] + (__int128)db[i] * L;
            v -= u;
            if (v < 0) {
                neg.emplace_back(u, v, i);
            } else {
                pos.emplace_back(u, v, i);
            }
        }
        sort(pos.begin(), pos.end());
        sort(neg.rbegin(), neg.rend());

        vector<int> order;
        order.reserve(n);
        for (const auto& t : pos) {
            order.emplace_back(get<2>(t));
        }
        for (const auto& t : neg) {
            order.emplace_back(get<2>(t));
        }

        pair<ll, ll> delta = {0, 0};
        vector<pair<ll, ll>> lines;
        lines.reserve(n);
        for (int i : order) {
            lines.emplace_back(a[i] - delta.first, da[i] - delta.second);
            delta.first += b[i] - a[i];
            delta.second += db[i] - da[i];
        }

        sort(lines.begin(), lines.end(), [&](const auto& v1, const auto& v2) {
            if (v1.second != v2.second) {
                return v1.second < v2.second;
            }
            return v1.first < v2.first;
        });

        vector<pair<pair<ll, ll>, ll>> st;
        for (const auto& t : lines) {
            while (!st.empty()) {
                auto u = st.back().first;
                if (u.second == t.second) {
                    st.pop_back();
                    continue;
                }
                ll cx = dvup(u.first - t.first, t.second - u.second);
                if (cx <= st.back().second) {
                    st.pop_back();
                    continue;
                }
                st.emplace_back(t, cx);
                break;
            }
            if (st.empty()) {
                st.emplace_back(t, L);
            }
        }

        for (int i = 0; i < (int)st.size(); i++) {
            auto t = st[i].first;
            auto gl = st[i].second;
            if (gl > R) {
                continue;
            }
            auto gr = R;
            if (i + 1 < (int)st.size()) {
                gr = min(gr, st[i + 1].second - 1);
            }
            res += (ull)t.first * (ull)(gr - gl + 1);
            __int128 coef = (__int128)(gr - gl + 1) * (gr + gl) / 2;
            res += (ull)t.second * (ull)coef;
        }
    }

#ifdef ONPC
    ll slow = 0;
    for (int i = 0; i <= m; i++) {
        slow += func(i);
    }
    cout << "slow: " << slow << "\n";
#endif

    cout << res << "\n";
}

int main() {
#ifdef ONPC
    freopen("input", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

3 5
3 1 5 2
4 2 1 3
1 9 100 1

output:

113

result:

ok single line: '113'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

3 100000000
3 1 5 2
4 2 1 3
1 9 100 1

output:

35000000549999998

result:

ok single line: '35000000549999998'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3788kb

input:

10 1000000000000000000
776874380544333 197 471391764744275 33
159838820333814 107 677112662750393 41
962335658276824 48 255593531071176 11
127404116579775 209 268525254990127 34
647620110614714 76 897947476313307 13
146196843402516 221 772928712898807 39
637929916804442 2 716937021892338 15
64200226...

output:

16687200746544394352

result:

wrong answer 1st lines differ - expected: '17883317185357051350', found: '16687200746544394352'