Submission #336450

#TimeUsernameProblemLanguageResultExecution timeMemory
336450tengiz05Bigger segments (IZhO19_segments)C++17
100 / 100
118 ms20060 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 5e5+5, inf = 1e18;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
int pr[N];
int dp[N];
void solve(int test_case){
	int i, j;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		pr[i]=a[i];pr[i]+=pr[i-1];
	}
	priority_queue<pii, vector<pii>, greater<pii>> q;
	q.push({0,0});
	int tmp=0;
	for(i=1;i<=n;i++){
		while(!q.empty() && q.top().ff <= pr[i]){
			if(dp[q.top().ss] > dp[tmp]){
				tmp = q.top().ss;
			}else if(dp[q.top().ss] == dp[tmp]){
				tmp = max(tmp, q.top().ss);
			}q.pop();
		}q.push({pr[i]*2-pr[tmp], i});
		dp[i] = dp[tmp]+1;
	}cout << dp[n] << '\n';
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message (stderr)

segments.cpp: In function 'void solve(long long int)':
segments.cpp:19:10: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   19 |  scanf("%d",&n);
      |         ~^  ~~
      |          |  |
      |          |  long long int*
      |          int*
      |         %lld
segments.cpp:21:11: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   21 |   scanf("%d",&a[i]);
      |          ~^  ~~~~~
      |           |  |
      |           |  long long int*
      |           int*
      |          %lld
segments.cpp:18:9: warning: unused variable 'j' [-Wunused-variable]
   18 |  int i, j;
      |         ^
segments.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
segments.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |   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...