QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#756876#5122. Strange Sumhikaritocm#WA 2ms6316kbC++141.2kb2024-11-16 22:24:422024-11-16 22:24:42

Judging History

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

  • [2024-11-16 22:24:42]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6316kb
  • [2024-11-16 22:24:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> tree(400005,-1e9-5);
void upd(int node, int l, int r, int pos, int val){
	if(l==r) tree[node]=val;
	else{
		int mid=(l+r)/2;
		if(pos<=mid)upd(node*2,l,mid,pos,val);
		else upd(node*2+1,mid+1,r,pos,val);
		tree[node]=max(tree[node*2],tree[node*2+1]);
	}
}
int query(int node, int l, int r, int lx, int rx){
	if(lx<=l and r<=rx){
		return tree[node];
	}
	if(r<lx or rx<l){
		return -1e9-5;
	}
	int mid=(l+r)/2;
	return max(query(node*2,l,mid,lx,rx),query(node*2+1,mid+1,r,lx,rx));
}
void solve(){
	int n;
	cin>>n;
	vector<int> a(n+1);
	vector<int> mx(n+1);
	for(int i=1; i<=n; i++){
		cin>>a[i];
		upd(1,1,n,i,a[i]);
//		ans=max(ans,a[i]+)
	}
	int ans=a[n];
	ans=max(ans,0LL);
	for(int i=1; i<=n; i++){
		int j=i+i-1;
		j=min(j,n);
		if(i==1){
			ans=max(ans,query(1,1,n,2,n)+a[i]);
		}
		else if(i==n){
			ans=max(ans,query(1,1,n,1,n-1)+a[i]);
		}
		ans=max(ans,a[i]+max(query(1,1,n,1,i-1),query(1,1,n,i+1,n)));
	}
	cout<<ans<<endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
//	cin>>t;
	while(t--) solve();
}

詳細信息

Test #1:

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

input:

4
1 4 3 2

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 1ms
memory: 6228kb

input:

3
-10 -10 -10

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 6216kb

input:

2
-394027216 -486855090

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 1ms
memory: 6140kb

input:

3
-357735986 584247758 118625500

output:

702873258

result:

ok 1 number(s): "702873258"

Test #5:

score: 0
Accepted
time: 0ms
memory: 6232kb

input:

100
56104366 -596757183 -563118094 -754585503 -108568019 320836846 955898372 745823264 942812454 -13940121 510253952 538293489 -683482556 159329401 -488586607 718665544 -560503132 167141318 -121480647 873802880 -642178792 64201005 -768929811 383561940 -993409166 441561051 -205099595 858985447 181520...

output:

1932124867

result:

ok 1 number(s): "1932124867"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 6316kb

input:

100
-567600476 -894106086 -223725076 -909882978 -400731198 -189239097 -462293199 -238554058 -941987047 -722267978 -296331743 -93421496 -940651029 -80663430 -930158710 -549118977 -793669840 -994577540 -617696981 -976257121 -982653934 -418566026 -527080389 -35686402 -90648977 -289869319 -933020191 -42...

output:

225158686

result:

wrong answer 1st numbers differ - expected: '229738661', found: '225158686'