Submission #897868

#TimeUsernameProblemLanguageResultExecution timeMemory
897868WhiteBigger segments (IZhO19_segments)C++14
0 / 100
1593 ms348 KiB
#pragma GCC optimize <"O3"> #include <bits/stdc++.h> #define endl "\n" using namespace std; long long red[500005]; vector<long long>clr,cur; long long binary(long long now){ long long l=0,r=cur.size()-1,mid,kr=cur.size()-1; if(cur.empty())return -1; //cout<<l<<" - "<<r<<endl; //cur.push_back(100000000007); while(l<r){ mid=(l+r)/2; if(cur[kr]-cur[mid]<now)r=mid-1; else l=mid; //cout<<"nicere"<<endl; } //cur.pop_back(); if(cur[kr]<now)return -1; return l; } int main(){ //ios_base::sync_with_stdio(false); //cin.tie(NULL); long long n; cin>>n; for(int i=0;i<n;i++)cin>>red[i]; long long br=1,L=red[0]; //cur.push_back(1);cur.push_back(3);cur.push_back(3);cur.push_back(3);cur.push_back(4);cur.push_back(4); //cout<<binary(0)<<endl; for(int i=1;i<n;i++){ long long N=red[i]; if(N>=L){ br++; L=N; cur=clr; }else{ //cout<<L<<" "<<N<<" "<<cur.size()<<endl; long long kude=binary(L-N); //cout<<kude<<endl; if(kude==-1){ if(cur.empty()==true)cur.push_back(N); else cur.push_back(cur[cur.size()-1]+N); }else{ br++; if(kude>0)L=N+cur[cur.size()-1]-cur[kude-1]; else L=N+cur[cur.size()-1]; cur=clr; } } } cout<<br<<endl; return 0; }

Compilation message (stderr)

segments.cpp:1:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
    1 | #pragma GCC optimize <"O3">
      |                      ^
#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...