QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105395#5500. BarsTime7#WA 410ms3528kbC++173.0kb2023-05-14 00:01:492023-05-14 00:01:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-14 00:01:53]
  • 评测
  • 测评结果:WA
  • 用时:410ms
  • 内存:3528kb
  • [2023-05-14 00:01:49]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using lint = int64_t;

using num = int64_t;
struct frac {
    num n, d;
    frac() : n(0), d(1) { }
    frac(num _n, num _d = 1) : n(_n), d(_d) {
        num g = gcd(n, d); n /= g, d /= g;
        if(d < 0) n *= -1, d *= -1;
        assert(d != 0);
    }
    friend bool operator<(const frac &l, const frac &r) {
        return __int128(1) * l.n * r.d < __int128(1) * r.n * l.d;
    }
    friend frac operator+(const frac &l, const frac &r) {
        num g = gcd(l.d, r.d);
        return frac(r.d / g * l.n + l.d / g * r.n, l.d/g * r.d);
    }
};

struct Line {
    mutable lint k, m, c;
    mutable frac p;
    bool operator<(const Line &o) const {return k < o.k; }
    bool operator<(frac x) const {return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
    static const lint inf = LLONG_MAX;
    frac div(lint a, lint b) {
        return frac(a, b);
    }
    bool isect(iterator x, iterator y) {
        if(y == end()) { x->p = frac(inf, 1); return false;}
        if(x->k == y->k) x->p = x->m > y->m ? frac(inf, 1) : frac(-inf, 1);
        else x->p = div(y->m - x->m, x->k - y->k);
        return !(x->p < y->p);
    }
    void add(lint k, lint m, lint c) {
        auto z = insert({k, m, c, frac(0, 1)}), 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, lint y) {
        assert(!empty());
        auto l = *lower_bound(frac(x, y));
        cout<<l.k<<" "<<l.m<<" "<<l.c<<"\n";
        return l.k * x + l.m * y + l.c;
    }
};




int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<lint>p(n+2);
        for(int i=1;i<=n;i++) cin>>p[i];
        vector<int>left(1), right(1, n+1);

        for(int i=1;i<=n;i++){
            if(p[i] > p[left.back()]) left.push_back(i);
        }
        for(int i=n;i>=1;i--){
            if(p[i] > p[right.back()]) right.push_back(i);
        }
        reverse(right.begin(), right.end());
        for(int u : right) left.push_back(u);
        int m = int(size(left));

        vector<int>ind(m);
        iota(ind.begin(), ind.end(), 0);
        sort(ind.begin(), ind.end(), [&](int i, int j){
            return p[i] > p[j];
        });
        set<int>s;
        s.insert(0);
        s.insert(n + 1);
        lint ans = 0;
        for(int i=0;i<m;i++){
            int j = ind[i];
            auto it = s.lower_bound(j);
            int l = *prev(it), r = *it;
            lint cur = (min(n, r) - max(1, l)) * (p[l] + p[r]);
            lint nxt = (min(n, r) - j) * (p[r] + p[j]) + (j - max(1, l)) * (p[j] + p[l]);
            //cout<<nxt<<" "<<cur<<" "<<j<<"\n";
            if(nxt > cur){
                ans += nxt - cur;
                s.insert(j);
            }
        }    
        cout<<ans<<"\n";    
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 410ms
memory: 3528kb

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
187252736727
346698863988
304281830652
459449868937
297269915919
428346440272
320695059639
284312726437
225878936030
353851234579
242493315841
192386414604
585703042277
102255213567
336650137239
242846093364
283189440799
298397220835
121529197738
430444665812
486685637501
438118447979
26480348...

result:

wrong answer 3rd lines differ - expected: '382465638565', found: '187252736727'