Submission #870862

#TimeUsernameProblemLanguageResultExecution timeMemory
870862pccDischarging (NOI20_discharging)C++14
100 / 100
86 ms25108 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const ll mxn = 1e6+10; vector<pll> v; ll sum[mxn],dp; deque<pll> dq; int n; ll total = 0; inline ll calc(pll line,ll val){ return line.fs*val+line.sc; } inline bool out(pll a,pll b,pll c){ return (a.sc-b.sc)*(c.fs-b.fs)>=(b.sc-c.sc)*(b.fs-a.fs); } main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n; for(int i = 0;i<n;i++){ int k; cin>>k; if(v.empty()||v.back().fs < k)v.push_back({k,1}); else v.back().sc++; } dq.push_back(make_pair(0ll,0ll)); sum[0] = v[0].sc; for(int i = 1;i<v.size();i++){ sum[i] = sum[i-1]+v[i].sc; } for(int i = 0;i<v.size();i++){ pll p = v[i]; while(dq.size()>1&&calc(dq[1],p.fs)<=calc(dq[0],p.fs))dq.pop_front(); dp = p.fs*n+calc(dq.front(),p.fs); pll now = make_pair(-sum[i],dp); while(dq.size()>1&&out(dq.end()[-2],dq.end()[-1],now))dq.pop_back(); dq.push_back(make_pair(-sum[i],dp)); } cout<<dp; }

Compilation message (stderr)

Discharging.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main(){
      | ^~~~
Discharging.cpp: In function 'int main()':
Discharging.cpp:38:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i = 1;i<v.size();i++){
      |                ~^~~~~~~~~
Discharging.cpp:41:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i = 0;i<v.size();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...
#Verdict Execution timeMemoryGrader output
Fetching results...