Submission #582725

#TimeUsernameProblemLanguageResultExecution timeMemory
582725Mr_HusanboyGlobal Warming (CEOI18_glo)C++14
10 / 100
102 ms19004 KiB
// Muallif: Mansuraliyev Husanboy Murotali o'g'li >> NamPS #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(a) a.begin(), a.end() #define F first #define S second #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) #define vii vector<int> #define vll vector<ll> // 0-9 >> 48-57; A-Z>>65-90 and a-z>>97-122 respectively; void solve(){ ll n; cin>>n; //t.resize(4*n); vll a;a.resize(n); ll x; cin>>x; for(ll i=0;i<n;i++) cin>>a[i]; vector<ll> check; /* if(n<=1000){ int ans=0; for(int j=0;j<n;j++){ for(int i=0;i<=j;i++){ a[i]-=x; } set<int> st; set<int>::iterator it; st.clear(); for(int i=0; i<n; i++) { it = st.lower_bound(a[i]); if (it != st.end()) st.erase(it); st.insert(a[i]); } check.push_back(st.size()); ans=max(ans,int(st.size())); for(int i=0;i<=j;i++) a[i]+=x; } cout<<ans<<"\n"; //return; }*/ set<ll> st; vector<pair<ll,ll>> l,r(n); for(int i=0;i<n;i++){ auto it=st.lower_bound(a[i]); if(it!=st.end()) st.erase(it); st.insert(a[i]); l.push_back({st.size(),*--st.end()}); } st.clear(); for(ll i=n-1;i>=0;i--){ auto it=st.lower_bound(-a[i]); if(it!=st.end()) st.erase(it); st.insert(-a[i]); r[i]={st.size(),-*--st.end()}; } /* cout<<"L and R:\n"; for(int i=0;i<n;i++) cout<<l[i].F<<" "<<l[i].S<<"\t"<<r[i].F<<' '<<r[i].S<<endl;; cout<<endl;*/ vector<ll> closer(n),closel(n); r.push_back({0,1e10}); stack<ll> s; s.push(n); for(ll i=n-1;i>=0;i--){ while(r[s.top()].S<=l[i].S) s.pop(); //cout<<l[i].S<<" "<<r[s.top()].S<<"\n"; closer[i]=s.top(); s.push(i); } while(!s.empty()) s.pop(); l.push_back({0,-1e10}); s.push(n); for(int i=0;i<n;i++){ while(l[s.top()].S>=r[i].S) s.pop(); closel[i]=s.top(); s.push(i); } ll ans=0; for(ll i=0;i<n;i++){ ans=max(ans,l[i].F+r[closer[i]].F); //cout<<max(l[i].F+r[closer[i]].F,r[i].F+l[closel[i]].F)<<' '<<check[i]<<endl; /*if(l[i].F+r[close[i]].F!=check[i]){ cout<<"error "<<i<<endl;break; }*/ } cout<<ans; } int main(){ ios; // int t; cin>>t; while(t--) solve(); }

Compilation message (stderr)

glo.cpp: In function 'void solve()':
glo.cpp:77:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   77 |  while(!s.empty()) s.pop(); l.push_back({0,-1e10}); s.push(n);
      |  ^~~~~
glo.cpp:77:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   77 |  while(!s.empty()) s.pop(); l.push_back({0,-1e10}); s.push(n);
      |                             ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...