Submission #291674

#TimeUsernameProblemLanguageResultExecution timeMemory
291674TheLoraxMeetings (IOI18_meetings)C++11
19 / 100
5600 ms7272 KiB
#include <bits/stdc++.h>
#include "meetings.h"

#define F first
#define S second
#define SZ(a) ((int)(a).size())
#define PB push_back
#define ALL(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;



std::vector<long long> minimum_costs(std::vector<int> h, std::vector<int> l, std::vector<int> r) {
  int q = SZ(l), n=SZ(h);

  std::vector<long long> c(q,LLONG_MAX);
  for(int i=0; i<q; i++){
    std::vector<ll> a(r[i]-l[i]+1), b(r[i]-l[i]+1);
    std::vector<ii> m;
    for(int j=l[i]; j<=r[i]; j++){
      ll t=1;
      a[j-l[i]]=(j>l[i]?a[j-l[i]-1]:0);
      while (!m.empty() && m.back().F<=h[j]) {
        a[j-l[i]]-=m.back().F*m.back().S;
        t+=m.back().S;
        m.pop_back();
      }
      a[j-l[i]]+=h[j]*t;
      m.PB({h[j],t});
    }
    m.clear();
    for(int j=r[i]; j>=l[i]; j--){
      ll t=1;
      b[j-l[i]]=(j<r[i]?b[j-l[i]+1]:0);
      while (!m.empty() && m.back().F<=h[j]) {
        b[j-l[i]]-=m.back().F*m.back().S;
        t+=m.back().S;
        m.pop_back();
      }
      b[j-l[i]]+=h[j]*t;
      m.PB({h[j],t});
    }
    for(int j=0; j<r[i]-l[i]+1; j++){
      // fprintf(stderr, "%lld %lld\n", a[j], b[j]);
      c[i]=min(c[i],a[j]+b[j]-h[j+l[i]]);
    }
  }
  return c;
}

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:18:18: warning: unused variable 'n' [-Wunused-variable]
   18 |   int q = SZ(l), n=SZ(h);
      |                  ^
#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...