제출 #376501

#제출 시각아이디문제언어결과실행 시간메모리
376501jamielimBigger segments (IZhO19_segments)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef pair<ll,ll> pll;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n;
int arr[500005];
int ans[500005];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&arr[i]);
	queue<ii> q;
	ans[0]=1;
	q.push(mp(arr[0],0)); // last segment sum, index
	ll pref=arr[0];
	int lst=0;
	for(int i=1;i<n;i++){
		pref+=arr[i];
		while(!q.empty()&&q.front().fi<=pref-arr[q.front().se]){
			pref-=arr[q.front().se];
			lst=ans[q.front().se];
			//printf("pop %d\n",q.front().se);
			q.pop();
		}
		ans[i]=lst+1;
		q.push(mp(pref,i));
		//printf("%d\n",ans[i]);
	}
	printf("%d",ans[n-1]);
}

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

segments.cpp: In function 'int main()':
segments.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
segments.cpp:26:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  for(int i=0;i<n;i++)scanf("%d",&arr[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...