QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#838438#9920. Money Game 2kkkgjyismine4ML 153ms154456kbC++201.1kb2024-12-31 11:17:112024-12-31 11:17:13

Judging History

This is the latest submission verdict.

  • [2024-12-31 22:17:02]
  • hack成功,自动添加数据
  • (/hack/1322)
  • [2024-12-31 21:57:13]
  • hack成功,自动添加数据
  • (/hack/1321)
  • [2024-12-31 11:17:13]
  • Judged
  • Verdict: ML
  • Time: 153ms
  • Memory: 154456kb
  • [2024-12-31 11:17:11]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define N 2000005
#define ll long long
#define pii pair<ll,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;ll a[N];
vector<pii>L[N],R[N];
void solve(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=n+1;i<=2*n;++i)a[i]=a[i-n];
	n*=2,R[n+1].clear();
	for(int i=1;i<=n;++i)L[i].clear(),R[i].clear();
	for(int i=1;i<=n;++i){
		L[i].pb(mp(a[i],i));ll lst=a[i];
		for(auto v:L[i-1]){
			if((v.fi/2ll+a[i])==lst)continue;
			lst=v.fi/2ll+a[i],L[i].pb(mp(v.fi/2ll+a[i],v.se));
		}
	}
	for(int i=n;i;--i){
		R[i].pb(mp(a[i],i));ll lst=a[i];
		for(auto v:R[i+1]){
			if((v.fi/2ll+a[i])==lst)continue;
			lst=v.fi/2ll+a[i],R[i].pb(mp(v.fi/2ll+a[i],v.se));
		}
	}
	for(int i=n/2+1;i<=n;++i){
		ll mx=0;
		int n1=(int)(R[i-n/2].size())-1;
		for(auto v:L[i]){
			while(n1>=0&&R[i-n/2][n1].se>=v.se)--n1;
			if(n1>=0)mx=max(mx,v.fi+R[i-n/2][n1].fi-a[i]);
		}
		cout<<mx<<" ";
	}cout<<endl;
}
int main(){
	ios::sync_with_stdio(0);
	int T;cin>>T;
	while(T--)solve();
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5676kb

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: 4ms
memory: 5628kb

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: 5620kb

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: 6ms
memory: 5680kb

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: 0
Accepted
time: 122ms
memory: 152540kb

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...

output:

4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

result:

ok 500000 numbers

Test #6:

score: 0
Accepted
time: 126ms
memory: 154444kb

input:

1
499999
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 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Limit Exceeded

input:

1
500000
50831937 44675374 26273308 55922669 39121681 59988372 34492729 33442351 51180456 41692596 39437453 54897084 38001252 46544549 55093280 38264131 54229588 51914925 28566111 46796223 48610138 48548724 51107017 44611895 37985173 46091996 45517937 53008497 48179451 47964156 42155259 47184755 267...

output:

137137494 130644721 122461248 136098437 133900842 139971148 126044470 123400935 132294341 130564235 131577353 139222968 134134442 139111260 143826886 137816035 143317006 139132099 126640855 134620873 139716994 141756406 141850936 136210410 131757247 136204948 139617130 144560973 142272557 138851244 ...

result: