QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#866908 | #9920. Money Game 2 | ucup-team073 | TL | 4ms | 8016kb | C++23 | 2.6kb | 2025-01-22 21:37:21 | 2025-01-22 21:37:23 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define st first
#define nd second
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar())f^=ch=='-';
for(;isdigit(ch);ch=getchar())x=x*10+(ch^48);
return f?x:-x;
}
const int N=5e5+5,LOG=32;
int a[N<<1],n;
pii L[N<<1][LOG],R[N<<1][LOG];
int calc(vector<int> arr){
for(int i=arr.size()-1;i>=1;--i)
arr[i-1]+=arr[i]/2;
return arr[0]/2;
}
void solve(){
n=read();
for(int i=1;i<=n;++i)a[i]=a[i+n]=read();
for(int i=n*2;i>=1;--i){
vector<int> tmp;
L[i][0]={0,i};
for(int x=1;x+1<LOG;++x){
if(i+x<=n*2){
tmp.pb(a[i+x]);
L[i][x]={calc(tmp),i+x};
}else L[i][x]={-1,-1};
}
int pos=i+LOG-1;
if(pos<=n*2){
tmp.pb(a[pos]);
int val=-1,FIND=-1;
for(int j=0;j<LOG;++j){
if(L[pos][j].st==-1)break;
tmp[tmp.size()-1]=a[pos]+L[pos][j].st;
val=calc(tmp);
if(val>L[i][LOG-2].st){
FIND=L[pos][j].nd;
break;
}
}
if(FIND==-1)L[i][LOG-1]={-1,-1};
else L[i][LOG-1]={val,FIND};
}else L[i][LOG-1]={-1,-1};
}
for(int i=1;i<=n*2;++i){
vector<int> tmp;
R[i][0]={0,i};
for(int x=1;x+1<LOG;++x){
if(i-x>=1){
tmp.pb(a[i-x]);
R[i][x]={calc(tmp),i-x};
}else R[i][x]={-1,-1};
}
int pos=i-LOG+1;
if(pos>=1){
tmp.pb(a[pos]);
int val=-1,FIND=-1;
for(int j=0;j<LOG;++j){
if(R[pos][j].st==-1)break;
tmp[tmp.size()-1]=a[pos]+R[pos][j].st;
val=calc(tmp);
if(val>R[i][LOG-2].st){
FIND=R[pos][j].nd;
break;
}
}
if(FIND==-1)R[i][LOG-1]={-1,-1};
else R[i][LOG-1]={val,FIND};
}else R[i][LOG-1]={-1,-1};
}
for(int i=1;i<=n;++i){
int ans=0;
for(int x=0;x<LOG;++x)for(int y=0;y<LOG;++y){
if(L[i][x].nd>=R[i+n][y].nd)continue;
if(L[i][x].st==-1||R[i+n][y].st==-1)continue;
ans=max(ans,a[i]+L[i][x].st+R[i+n][y].st);
}
printf("%lld ",ans);
}
puts("");
}
signed main(){
for(int cas=read();cas--;)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8016kb
input:
3 5 2 1 4 3 5 5 2 1 3 1 2 1 1000000000
output:
6 5 7 8 8 4 4 5 4 4 1000000000
result:
ok 11 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 7884kb
input:
1 10 8 15 18 15 13 4 14 4 17 5
output:
30 37 41 39 34 27 29 26 31 27
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 3ms
memory: 8012kb
input:
1000 4 8 9 7 9 1 9 1 10 2 3 9 3 4 3 2 4 0 4 3 1 4 10 8 4 6 1 9 1 4 4 10 10 1 6 1 9 1 0 2 4 6 4 8 1 6 7 2 5 10 4 9 2 1 4 3 5 5 9 3 9 8 9 4 4 8 5 6 2 10 1 1 7 3 9 2 4 4 2 4 1 2 3 5 2 1 1 4 3 2 0 9 4 7 3 10 1 3 4 1 2 2 6 4 1 2 3 3 1 5 3 5 8 4 2 9 3 4 5 9 10 3 4 6 5 4 0 1 6 4 3 1 10 1 4 1 9 5 7 4 8 1 6 ...
output:
18 18 17 18 9 10 7 10 6 6 5 3 5 5 3 18 16 13 15 9 4 18 17 11 14 9 0 7 8 13 9 11 14 10 12 12 7 6 9 11 11 13 17 16 17 12 14 13 12 10 6 7 12 8 9 5 6 4 4 6 4 4 4 6 5 10 11 11 13 10 5 4 4 8 7 2 5 4 6 11 12 10 10 7 13 17 16 12 9 10 8 6 6 6 7 11 7 9 13 12 11 14 10 12 1...
result:
ok 2420 numbers
Test #4:
score: 0
Accepted
time: 4ms
memory: 7868kb
input:
1000 2 45733740 736448710 1 384264719 4 658671808 379716865 553196572 534986092 1 668964623 4 711670857 237459905 849354895 187613938 2 394629064 371184128 2 616819808 937720703 1 43217931 3 934395080 888433507 810476236 1 587663687 2 542163302 508453558 4 313836277 584869499 445629251 225398284 4 2...
output:
413958095 759315580 384264719 1254322429 1119397578 1175216002 1235849498 668964623 1136546502 1064876265 1239809530 1027491789 580221128 568498660 1085680159 1246130607 43217931 1783849951 1760869165 1721890529 587663687 796390081 779535209 830377481 1020951833 929222211 751348422 70477...
result:
ok 2440 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
1 500000 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...