QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249057#7520. Monster GeneratorUFRJ#WA 0ms3616kbC++201.8kb2023-11-12 00:07:352023-11-12 00:07:35

Judging History

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

  • [2023-11-12 00:07:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2023-11-12 00:07:35]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using lint = int64_t;

struct Line {
    mutable lint k, m, p;
    bool operator<(const Line &o) const { return k < o.k;}
    bool operator<(lint x) const { return p < x;}
};

struct LineContainer : multiset<Line, less<>> {
    static const lint inf = LLONG_MAX;
    lint div(lint a, lint b) {
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if(y == end()) { x->p = inf; return false; }
        if(x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y ->k);
        return x->p >= y->p;
    }
    void add(lint k, lint m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while(isect(y, z)) z = erase(z);
        if(x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    lint query(lint x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};

using ll = __int128_t;
using ulint = uint64_t;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    lint m;
    cin>>n>>m;
    vector<lint>a(n), b(n), c(n), d(n);
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    lint x = 0, y = 0;
    LineContainer g;
    for(int i=0;i<n;i++){
        x += a[i], y += b[i];
        g.add(y, x);
        x -= c[i], y -= d[i];
    }
    lint last = 0;
    ulint ans = 0;
    for(auto [k, z, p] : g){
        if(p <= 0) continue;
        if(last > m) break;
        ll l = last, r = min(p - 1, m);
        ll cur = (l + r) * (r - l + 1) / 2;
        ans += ulint(cur) * ulint(k) + ulint(z);
        last = p;
    }
    cout<<ans<<"\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

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

output:

107

result:

wrong answer 1st lines differ - expected: '113', found: '107'