QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629669#8242. V-DiagramMiniLongWA 357ms8032kbC++143.5kb2024-10-11 14:09:552024-10-11 14:09:58

Judging History

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

  • [2024-10-11 14:09:58]
  • 评测
  • 测评结果:WA
  • 用时:357ms
  • 内存:8032kb
  • [2024-10-11 14:09:55]
  • 提交

answer

#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
    #ifdef ONLINE_JUDGE
    char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244353;
    ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 3e5 + 5;
typedef long double lb;
const lb eps = 1e-10;
ll n, a[N], L[N], R[N];
lb pre[N], suf[N];
bool check(lb mid){
    _rep(i, 1, n) pre[i] = pre[i - 1] + (lb)a[i] - mid;
    _req(i, n, 1) suf[i] = suf[i + 1] + (lb)a[i] - mid;
    int pos = 0;
    _rep(i, 2, n - 1){
        if(!L[i] || !R[i]) continue;
        pos = i;
        break;
    }
    lb minx = 0;
    _rep(i, 0, pos - 2) minx = min(minx, pre[i]);
    lb res = pre[pos - 1] + suf[pos + 1] + (lb)a[pos] - mid;
    res -= minx;
    minx = 0;
    _rep(i, pos + 2, n) minx = min(minx, suf[i]);
    res -= minx;
    if(res > -eps) return 1;
    return 0;
}
int main(){
    multitest(){
        read(n);
        _rep(i, 1, n) read(a[i]);
        _rep(i, 2, n){
            if(a[i] < a[i - 1]) L[i] = !L[i - 1] ? i - 1 : L[i - 1];
            else L[i] = 0;
        }
        _req(i, n - 1, 1){
            if(a[i] < a[i + 1]) R[i] = !R[i + 1] ? i + 1 : R[i + 1];
            else R[i] = 0;
        }
        lb l = 0, r = 1e15, res = 0;
        while(r - l > eps){
            lb mid = (l + r) / 2.00;
            if(check(mid)) l = mid + eps, res = mid;
            else r = mid - eps;
        }
        printf("%.10Lf\n", res);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
8 2 7 10
6
9 6 5 3 4 8

output:

6.7500000000
5.8333333332

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 357ms
memory: 7996kb

input:

100000
3
948511478 739365502 813471668
3
881046825 27458122 398507422
3
987554257 399092415 924260278
3
984128569 125199021 716360525
3
529589236 45783262 313507287
3
645443456 85994112 226010681
3
914820717 228360911 572267310
3
418958362 56703604 195276041
3
64461646 26764720 26995581
3
914535039 ...

output:

833782882.6666666665
435670789.6666666667
770302316.6666666665
608562705.0000000000
296293261.6666666665
319149416.3333333333
571816312.6666666666
223646002.3333333334
39407315.6666666666
383253737.6666666666
734363638.6666666666
779975824.3333333333
490276408.3333333332
574448413.9999999999
3379802...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 210ms
memory: 5916kb

input:

10000
4
194123849 79274911 191162487 570110764
86
957917218 915359202 914726017 873273226 867724859 867674150 809652204 805531383 745262007 743835491 727071232 714782071 645394643 639432679 594879540 587173904 583418126 560538589 518721836 469558994 427721766 411582333 404948350 402948978 357228675 ...

output:

258668002.7499999999
527118856.7555555553
468429960.6363636364
647875217.8544444443
449920924.8888888886
546154003.1250000000
743418098.5412544806
0.0000000000
678500282.5665017921
698447457.1403937534
274582027.5262729127
479468115.1182795700
453881712.8372093022
540832942.0714285712
505763041.7692...

result:

wrong answer 3rd numbers differ - expected: '495489050.3529412', found: '468429960.6363636', error = '0.0546109'