Submission #334155

#TimeUsernameProblemLanguageResultExecution timeMemory
334155KerimBigger segments (IZhO19_segments)C++17
37 / 100
1581 ms11756 KiB
#include "bits/stdc++.h" #define MAXN 500009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} int dp[MAXN],arr[MAXN],n,ok,tmp; ll par[MAXN]; set<int>one,zero; int get(int i){ return lower_bound(par+i+1,par+n+1,2*par[i]-par[dp[i]])-par; } int main(){ // freopen("file.in", "r", stdin); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",arr+i); par[i]=par[i-1]+arr[i]; } for(int i=1;i<=n;i++) one.insert(i); stack<int>add,rem,far; for(int j=2;j<=n;j++){ ok=0; __typeof((one).begin())a=one.end(); while(a!=one.begin()){a--; if(*a<j-1) break; tmp=get(*a); __typeof((zero).begin())b=zero.end(); while(b!=zero.begin()){b--; if(*b<tmp) break; dp[*b]=*a;ok=1; add.push(*b); far.push(*b); } zero.insert(*a); while(!far.empty()) zero.erase(far.top()),far.pop(); rem.push(*a); } while(!rem.empty()) one.erase(rem.top()),rem.pop(); while(!add.empty()) one.insert(add.top()),add.pop(); if(!ok){ printf("%d\n",j-1); return 0; } }printf("%d\n",n); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:58:6: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   58 |      while(!add.empty())
      |      ^~~~~
segments.cpp:60:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   60 |   if(!ok){
      |   ^~
segments.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
segments.cpp:30:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |      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...