QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#756845#5122. Strange Sumhikaritocm#Compile Error//C++141.0kb2024-11-16 22:15:462024-11-16 22:15:46

Judging History

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

  • [2024-11-16 22:15:46]
  • 评测
  • [2024-11-16 22:15:46]
  • 提交

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;
	int ans=a[n];
	ans=max(ans,0LL);
	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]+)
	}
	for(int i=1; i<=n-1; i++){
		int j=i+i-1;
		j=min(j,n);
		ans=max(ans,a[i]+query(1,1,n,i+1,j));
	}
	cout<<ans<<endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
//	cin>>t;
	while(t--) solve();
}

Details

answer.code: In function ‘void solve()’:
answer.code:27:17: error: ‘a’ was not declared in this scope
   27 |         int ans=a[n];
      |                 ^