제출 #201337

#제출 시각아이디문제언어결과실행 시간메모리
201337guangxuanBigger segments (IZhO19_segments)C++14
73 / 100
1574 ms142052 KiB
#include <bits/stdc++.h>

using namespace std;

int a[500009];
long long rs[500009];
pair<int,long long> dp[500009];
unordered_map<long long,pair<int,long long> >fw;

pair<int,long long> query(long long x){
	pair<int,long long> ans = {-1,-1};
	for(x++;x;x-=x&(-x)){
		if(fw.find(x)==fw.end())continue;
		ans = max(ans,fw[x]);
	}
	return ans;
}

void up(long long x,pair<int,long long> v ){
	for(x++;x<1e15;x+=x&(-x)){
		if(fw.find(x)==fw.end())fw[x] = v;
		else fw[x] = max(fw[x],v);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		rs[i+1]=rs[i]+a[i];
	}
	up(0,{0,0});
	for(int i=1;i<=n;i++){
		pair<int,long long> res = query(rs[i]); 
		dp[i] = {res.first,res.second - rs[i]};
		dp[i].first++;
		up(rs[i] - dp[i].second,{dp[i].first,rs[i]});
		//cout << dp[i].first << ' ' << dp[i].second << '\n';
		// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
	}
	printf("%d", dp[n].first);
}

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'int main()':
segments.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
segments.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...