QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599252#8577. 평균 최대화Matutino24 360ms270212kbC++143.1kb2024-09-29 02:49:062024-09-29 02:49:07

Judging History

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

  • [2024-09-29 02:49:07]
  • 评测
  • 测评结果:24
  • 用时:360ms
  • 内存:270212kb
  • [2024-09-29 02:49:06]
  • 提交

answer

// #include"average.h"
#include<bits/stdc++.h>
#define register
#define int long long
const int N=6e5+10;
int n,a[N],st[20][N],idx,qwq,Rt[N];
std::mt19937 rnd(233);
std::vector<int> vc[N],G[N];
std::map<std::pair<int,int>,int> id;
std::pair<int,int> ID[N];
struct Node{int x,y,sz,sx,sy,val,ls,rs;}t[N];
std::map<int,std::pair<int,int>> ans;
int chk(int x,int y){return a[x]==a[y]?std::min(x,y):a[x]<a[y]?x:y;}
int qry(int l,int r){int L=std::__lg(r-l+1); return chk(st[L][l],st[L][r-(1<<L)+1]);}
int build(int l,int r){
    if (r==l+1){
        ++qwq,id[ID[qwq]={l,r}]=qwq;
        ans[qwq]={a[l]+a[r],2};
        return 0;
    }
    int p=l+1,rt=++qwq,lst=0; id[{l,r}]=qwq;
    ID[qwq]={l,r};
    vc[rt].push_back(l); 
    while (p<r){
        int now=qry(p,r-1); if (lst&&a[now]!=a[lst]) break;
        vc[rt].push_back(lst=now),p=lst+1;
    }
    vc[rt].push_back(r);
    for (int i=0;i+1<vc[rt].size();i++){
        int v=build(vc[rt][i],vc[rt][i+1]);
        if (v) G[rt].push_back(v);
    }
    return rt;
}
int newnode(int x,int y){return t[++idx]={x,y,1,x,y,rnd(),0,0},idx;}
void pushup(int o){
    t[o].sx=t[t[o].ls].sx+t[o].x+t[t[o].rs].sx,
    t[o].sy=t[t[o].ls].sy+t[o].y+t[t[o].rs].sy,
    t[o].sz=t[t[o].ls].sz+1+t[t[o].rs].sz;
}
#define ll __int128
void split(int o,int dx,int dy,int &x,int &y){
    if (!o) return x=y=0,void();
    if ((ll)dy*t[o].x>=(ll)t[o].y*dx) y=o,split(t[o].ls,dx,dy,x,t[y].ls),pushup(y);
    else x=o,split(t[o].rs,dx,dy,t[x].rs,y),pushup(x);
}
void Split(int o,int dx,int dy,int &x,int &y){
    if (!o) return x=y=0,void();
    if ((ll)(dy+t[t[o].ls].sy)*t[o].x>=(ll)t[o].y*(dx+t[t[o].ls].sx)) y=o,Split(t[o].ls,dx,dy,x,t[y].ls),pushup(y);
    else x=o,Split(t[o].rs,dx+t[t[o].ls].sx+t[o].x,dy+t[t[o].ls].sy+t[o].y,t[x].rs,y),pushup(x);
}
int merge(int x,int y){
    if (!x||!y) return x+y;
    if (t[x].val>t[y].val) return t[x].rs=merge(t[x].rs,y),pushup(x),x;
    return t[y].ls=merge(x,t[y].ls),pushup(y),y;
}
int nd[N],tot;
void dfs(int o){if (!o) return; dfs(t[o].ls),nd[++tot]=o,dfs(t[o].rs);}
void Dfs(int u){
    int sx=0,sy=0,A,B; auto [l,r]=ID[u];
    for (int i=1;i+1<vc[u].size();i++) sx++,sy+=a[vc[u][i]];
    for (auto v:G[u]){
        Dfs(v);  
        if (t[Rt[u]].sz<t[Rt[v]].sz) std::swap(Rt[u],Rt[v]);
        tot=0,dfs(Rt[v]); 
        for (int i=1,a,b,x;x=nd[i],i<=tot;i++){
            t[x].ls=t[x].rs=0,t[x].sx=t[x].x,t[x].sy=t[x].y,t[x].sz=1;
            split(Rt[u],t[x].x,t[x].y,A,B);
            Rt[u]=merge(merge(A,x),B);
        }
    }
    Split(Rt[u],sx+a[l]+a[r],sy+2,A,B);
    ans[u]={sy+t[A].sy+a[l]+a[r],sx+t[A].sx+2},Rt[u]=merge(A,B);
    Split(Rt[u],sx,sy,A,B),Rt[u]=merge(newnode(sx+t[A].sx,sy+t[A].sy),B);
}
#undef int
void initialize(std::vector<int> A){
    n=A.size(); for (int i=1;i<=n;i++) a[i]=A[i-1],st[0][i]=i;
    for (int j=1;1<<j<=n;j++) for (int i=1;i+(1<<j)-1<=n;i++) st[j][i]=chk(st[j-1][i],st[j-1][i+(1<<j-1)]);
    Dfs(build(0,n+1)); 
}
std::array<long long, 2> maximum_average(int i, int j){
    auto [x,y]=ans[id[{i+1,j+1}]]; 
    return {x,y};
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 6ms
memory: 46752kb

input:

10
2 4 3 9 9 9 9 9 9 1
2
0 2
0 9

output:

9 3
60 9

result:

ok correct!

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 48828kb

input:

15
4596730 8340349 4612555 5692442 3914918 5213545 5248236 1276073 3844119 2943960 9231647 5091649 2239006 9139001 4735414
100
7 8
5 6
2 4
0 4
8 9
10 11
3 4
0 1
10 11
10 11
3 4
4 5
12 13
0 2
2 4
11 12
12 14
2 3
7 8
12 14
6 7
4 5
11 12
10 11
7 12
8 9
8 9
0 2
2 3
12 14
7 9
7 9
12 13
10 11
9 11
13 14
8...

output:

5120192 2
10461781 2
14219915 3
27156994 5
6788079 2
14323296 2
9607360 2
12937079 2
14323296 2
14323296 2
9607360 2
9128463 2
11378007 2
17549634 3
14219915 3
7330655 2
16113421 3
10304997 2
5120192 2
16113421 3
6524309 2
9128463 2
7330655 2
14323296 2
24626454 6
6788079 2
6788079 2
17549634 3
1030...

result:

wrong answer Wrong Answer on query #25: 24626454/6 != 20782335/5

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 7
Accepted

Test #15:

score: 7
Accepted
time: 257ms
memory: 189660kb

input:

300000
1 2 4 4 4 4 3 2 4 4 3 4 4 4 4 4 4 4 4 4 3 4 3 4 4 4 4 4 4 4 4 3 3 4 4 4 3 4 3 4 4 4 4 4 4 4 4 4 4 3 3 4 4 4 3 4 4 3 4 4 4 4 4 4 4 3 2 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 4 4 4 4 4 4 2 4 4 2 4 4 3 4 4 4 2 3 4 4 4 4 4 4 3 2 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 2 4 4 4 4 4 4 3 4 4 3 4 4 4 4 4 4 4 4 4...

output:

1041675 278497
23 7
3 2
8 2
6 2
8 2
8 2
7 2
5 2
21 6
224 60
8 2
6 2
7 2
42 11
13 4
8 2
7 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
7 2
10 3
7 2
7 2
38 10
8 2
7 2
8 2
8 2
8 2
8 2
8 2
8 2
7 2
6 2
18 5
8 2
7 2
8 2
7 2
10 3
7 2
7 2
46 12
8 2
7 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
7 2
6 2
18 5
8 2
7 2
8 2
7 2
14 4
8 2
...

result:

ok correct!

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 17
Accepted

Test #28:

score: 17
Accepted
time: 331ms
memory: 270212kb

input:

300000
1 300000 300001 299999 300003 299998 300005 299997 300007 299996 300009 299995 300011 299994 300013 299993 300015 299992 300017 299991 300019 299990 300021 299989 300023 299988 300025 299987 300027 299986 300029 299985 300031 299984 300033 299983 300035 299982 300037 299981 300039 299980 3000...

output:

917250302 2450

result:

ok correct!

Test #29:

score: 17
Accepted
time: 253ms
memory: 207536kb

input:

262143
1 36 17 55 17 36 16 94 16 36 17 55 17 36 15 173 15 36 17 55 17 36 16 94 16 36 17 55 17 36 14 332 14 36 17 55 17 36 16 94 16 36 17 55 17 36 15 173 15 36 17 55 17 36 16 94 16 36 17 55 17 36 13 651 13 36 17 55 17 36 16 94 16 36 17 55 17 36 15 173 15 36 17 55 17 36 16 94 16 36 17 55 17 36 14 332 ...

output:

1310726 5

result:

ok correct!

Test #30:

score: 17
Accepted
time: 19ms
memory: 80224kb

input:

30000
1 8655519 5053769 2 3 4 5 6991720 3321347 8718018 4464302 8356978 6 7 8 8314637 5910310 3734266 7192139 9183941 9 4352483 6266035 4417558 10 6855725 6999520 4363735 11 12 3499845 8360666 13 14 15 16 9638440 7317746 17 9282787 18 7466678 7930596 9367029 9821794 19 9771448 5441062 6451096 328952...

output:

1506711094 313

result:

ok correct!

Test #31:

score: 17
Accepted
time: 267ms
memory: 221676kb

input:

290000
1 2 6720098 9810682 9668570 8703077 7145578 8284345 5251625 6142206 3 4 5 6 9581548 3001002 3225039 8794590 7 7045505 4451229 5589636 8 5839563 9 4221964 4476182 9093685 6987982 8939207 10 5185060 5575428 4771993 6420287 11 5731640 9062305 12 4033948 6267196 9720880 9696770 8607688 7778692 13...

output:

105901076 21

result:

ok correct!

Test #32:

score: 17
Accepted
time: 262ms
memory: 224388kb

input:

300000
1 8082711 2 3 4 8191165 3057929 5 3281578 6 6806849 5907196 7 9351806 3531744 7705686 6432789 9157615 8 9 6375173 10 11 9085831 12 8260525 5405870 5874520 5080934 9030605 4739400 3087365 13 14 3952382 8426580 15 3670130 3487971 16 9726802 6241396 5894014 9251026 17 3933416 6097186 8936104 857...

output:

54234185 11

result:

ok correct!

Test #33:

score: 17
Accepted
time: 360ms
memory: 249096kb

input:

300000
1 30001 30002 30000 30004 29999 30006 29998 30008 29997 30010 29996 30012 29995 30014 29994 30016 29993 30018 29992 30020 29991 30022 29990 30024 29989 30026 29988 30028 29987 30030 29986 30032 29985 30034 29984 30036 29983 30038 29982 30040 29981 30042 29980 30044 29979 30046 29978 30048 299...

output:

261884792 7016

result:

ok correct!

Test #34:

score: 17
Accepted
time: 343ms
memory: 247272kb

input:

300000
1 30001 30002 30000 30004 29999 30006 29998 30008 29997 30010 29996 30012 29995 30014 29994 30016 29993 30018 29992 30020 29991 30022 29990 30024 29989 30026 29988 30028 29987 30030 29986 30032 29985 30034 29984 30036 29983 30038 29982 30040 29981 30042 29980 30044 29979 30046 29978 30048 299...

output:

261884792 7016

result:

ok correct!

Test #35:

score: 17
Accepted
time: 352ms
memory: 249180kb

input:

300000
1 30001 30002 30000 30004 29999 30006 29998 30008 29997 30010 29996 30012 29995 30014 29994 30016 29993 30018 29992 30020 29991 30022 29990 30024 29989 30026 29988 30028 29987 30030 29986 30032 29985 30034 29984 30036 29983 30038 29982 30040 29981 30042 29980 30044 29979 30046 29978 30048 299...

output:

261884792 7016

result:

ok correct!

Test #36:

score: 17
Accepted
time: 359ms
memory: 254836kb

input:

300000
1 100001 100002 100000 100004 99999 100006 99998 100008 99997 100010 99996 100012 99995 100014 99994 100016 99993 100018 99992 100020 99991 100022 99990 100024 99989 100026 99988 100028 99987 100030 99986 100032 99985 100034 99984 100036 99983 100038 99982 100040 99981 100042 99980 100044 999...

output:

492457470 3950

result:

ok correct!

Test #37:

score: 17
Accepted
time: 344ms
memory: 256776kb

input:

300000
1 100001 100002 100000 100004 99999 100006 99998 100008 99997 100010 99996 100012 99995 100014 99994 100016 99993 100018 99992 100020 99991 100022 99990 100024 99989 100026 99988 100028 99987 100030 99986 100032 99985 100034 99984 100036 99983 100038 99982 100040 99981 100042 99980 100044 999...

output:

492457470 3950

result:

ok correct!

Test #38:

score: 17
Accepted
time: 355ms
memory: 250748kb

input:

300000
1 100001 100002 100000 100004 99999 100006 99998 100008 99997 100010 99996 100012 99995 100014 99994 100016 99993 100018 99992 100020 99991 100022 99990 100024 99989 100026 99988 100028 99987 100030 99986 100032 99985 100034 99984 100036 99983 100038 99982 100040 99981 100042 99980 100044 999...

output:

492457470 3950

result:

ok correct!

Test #39:

score: 17
Accepted
time: 345ms
memory: 246748kb

input:

300000
1 1001 1002 1000 1004 999 1006 998 1008 997 1010 996 1012 995 1014 994 1016 993 1018 992 1020 991 1022 990 1024 989 1026 988 1028 987 1030 986 1032 985 1034 984 1036 983 1038 982 1040 981 1042 980 1044 979 1046 978 1048 977 1050 976 1052 975 1054 974 1056 973 1058 972 1060 971 1062 970 1064 9...

output:

46134492 37796

result:

ok correct!

Test #40:

score: 17
Accepted
time: 334ms
memory: 244780kb

input:

300000
1 1001 1002 1000 1004 999 1006 998 1008 997 1010 996 1012 995 1014 994 1016 993 1018 992 1020 991 1022 990 1024 989 1026 988 1028 987 1030 986 1032 985 1034 984 1036 983 1038 982 1040 981 1042 980 1044 979 1046 978 1048 977 1050 976 1052 975 1054 974 1056 973 1058 972 1060 971 1062 970 1064 9...

output:

46134492 37796

result:

ok correct!

Test #41:

score: 17
Accepted
time: 354ms
memory: 246936kb

input:

300000
1 1001 1002 1000 1004 999 1006 998 1008 997 1010 996 1012 995 1014 994 1016 993 1018 992 1020 991 1022 990 1024 989 1026 988 1028 987 1030 986 1032 985 1034 984 1036 983 1038 982 1040 981 1042 980 1044 979 1046 978 1048 977 1050 976 1052 975 1054 974 1056 973 1058 972 1060 971 1062 970 1064 9...

output:

46134492 37796

result:

ok correct!

Test #42:

score: 17
Accepted
time: 313ms
memory: 255472kb

input:

300000
1 843582 2 873021 3 643266 4 825520 5 612939 6 642259 7 867008 8 688306 9 735154 10 728530 11 855292 12 766900 13 680592 14 756837 15 644649 16 886591 17 718665 18 883840 19 603356 20 877389 21 657101 22 799281 23 859838 24 818703 25 708095 26 833634 27 819313 28 837566 29 621548 30 603778 31...

output:

61577207644 159986

result:

ok correct!

Test #43:

score: 17
Accepted
time: 278ms
memory: 233840kb

input:

300000
1 6835493 2 4021139 3 4948020 4 9277118 5 4836220 6 7333822 7 5477584 8 8207990 9 4016733 10 9290125 11 8744708 12 6270566 13 5111629 14 8762765 15 5761419 16 9228542 17 5577763 18 6444537 19 5966457 20 4038485 21 9462991 22 6349304 23 7657234 24 9631830 25 6433737 26 9269204 27 4684626 28 74...

output:

1173288731382 293817

result:

ok correct!

Subtask #7:

score: 0
Wrong Answer

Dependency #4:

100%
Accepted

Test #44:

score: 0
Wrong Answer
time: 276ms
memory: 193688kb

input:

300000
1 18 20 20 20 18 20 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 13 20 18 20 20 20 20 20 20 20 16 20 20 20 20 20 20 19 18 20 20 20 20 20 18 20 20 20 20 19 20 20 20 20 20 20 20 20 20 20 14 19 20 20 19 20 20 20 19 19 20 18 18 12 20 19 20 20 20 20 20 20 20 11 20 20 14 20 19 19 20 20 20 20 20 20 ...

output:

398307 20360
96 5
19 2
40 2
38 2
40 2
38 2
349 18
39 2
38 2
38 2
57 3
292 15
40 2
39 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
33 2
1039 54
428 23
38 2
33 2
174 9
51 3
40 2
38 2
40 2
40 2
40 2
40 2
40 2
36 2
604 31
207 11
40 2
36 2
40 2
40 2
40 2
40 2
39 2
37 2
155 8
136 7
173 9
40 2
...

result:

wrong answer Wrong Answer on query #113: 53979/2763 != 31055/1587

Subtask #8:

score: 0
Skipped

Dependency #1:

0%