Submission #285468

#TimeUsernameProblemLanguageResultExecution timeMemory
285468arnold518Discharging (NOI20_discharging)C++14
100 / 100
175 ms22500 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; const ll INF = 1e15; int N; ll dp[MAXN+10], A[MAXN+10]; struct Line { ll a, b; }; double cross(Line p, Line q) { return (double)(q.b-p.b)/(p.a-q.a); } struct CHT { int pos=0; vector<Line> S; void push(Line p) { while(S.size()>1 && cross(S[S.size()-1], S[S.size()-2])>=cross(S[S.size()-1], p)) S.pop_back(); S.push_back(p); } ll query(ll x) { if(pos>=S.size()) pos=S.size()-1; else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++; return S[pos].a*x+S[pos].b; } }cht; int main() { scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%lld", &A[i]); reverse(A+1, A+N+1); A[0]=INF; vector<int> S; S.push_back(0); for(int i=1; i<=N; i++) { while(!S.empty() && A[S.back()]<=A[i]) S.pop_back(); S.push_back(i); } for(int i=1; i<S.size(); i++) { cht.push({A[S[i]], dp[i-1]}); dp[i]=cht.query(S[i]); } printf("%lld\n", dp[S.size()-1]); }

Compilation message (stderr)

Discharging.cpp: In member function 'll CHT::query(ll)':
Discharging.cpp:28:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   if(pos>=S.size()) pos=S.size()-1;
      |      ~~~^~~~~~~~~~
Discharging.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
      |              ~~~~~^~~~~~~~~
Discharging.cpp: In function 'int main()':
Discharging.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i=1; i<S.size(); i++)
      |               ~^~~~~~~~~
Discharging.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Discharging.cpp:37:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  for(int i=1; i<=N; i++) scanf("%lld", &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...
#Verdict Execution timeMemoryGrader output
Fetching results...