Submission #1333534

#TimeUsernameProblemLanguageResultExecution timeMemory
1333534Faisal_SaqibMeetings (IOI18_meetings)C++20
Compilation error
0 ms0 KiB
#include "meetings.h"
using namespace std;
typedef long long ll;
struct data
{
  int pre,suf,mx,len;
};
const int LG=20,N=1e5+10;
data sp[N][LG];
data merge(data a,data b)
{
  data ans;
  ans.mx=max(a.mx,b.mx);
  ans.pre=a.pre+b.pre*(a.pre==a.len);
  ans.suf=a.suf*(b.suf==b.len)+b.suf;
  ans.mx=max(ans.mx,a.suf+b.pre);
  ans.len=a.len+b.len;
  return ans;
}
int get(int ql,int qr)
{
  qr++;
  data cur={0,0,0,0};
  for(int j=LG-1;j>=0;j--)
  {
    if((ql+(1<<j))<=qr)
    {
      cur=merge(cur,sp[ql][j]);
      ql+=(1<<j);
    }
  }
  return cur.mx;
}
std::vector<long long> minimum_costs(std::vector<int> h, std::vector<int> l,
                                     std::vector<int> r) {
  int n=h.size(),q=l.size(),mx=2;
  for(int i=0;i<n;i++)
  {
    mx=max(mx,h[i]);
  }
  if(mx==2)
  {
    for(int i=0;i<n;i++)
    {
      if(h[i]==2)
      {
        sp[i][0]={0,0,0,1};
      }
      else if (h[i]==1)
      {
        sp[i][0]={1,1,1,1};
      }
    }
    for(int j=1;j<LG;j++)
    {
      for(int i=0;i+(1<<j)<=n;i++)
        sp[i][j]=merge(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
    }
    vector<ll> fpp;
    for(int i=0;i<q;i++)
    {
      fpp.push_back(2*(r[i]-l[i]+1)-get(l[i],r[i]));
    }
    return fpp;
    // we want the maximum segment of ones in range l,r
  }

  vector<ll> fnl(q);
  vector<ll> cst(n+2,0);
  for(int i=0;i<q;i++)
  {
    int ql=l[i],qr=r[i];
    vector<int> c;
    ll ans=0;
    for(int x=ql;x<=qr;x++)    
    {
      while(c.size()>0 and h[c.back()]<=h[x])
      {
        int z=c.back();
        c.pop_back();
        ans-=1ll*(z-((c.size()>0)?(c.back()):(ql-1)))*h[z];
      }
      int z=x;
      ans+=1ll*(z-((c.size()>0)?(c.back()):(ql-1)))*h[z];
      c.push_back(x);
      cst[x]=ans;
    }
    ans=0;
    ll mi=1e18;
    c.clear();
    for(int x=qr;x>=ql;x--)
    {
      while(c.size()>0 and h[c.back()]<=h[x])
      {
        int z=c.back();
        c.pop_back();
        ans-=1ll*(((c.size()>0)?(c.back()):(qr+1))-z)*h[z];
      }
      int z=x;
      ans+=1ll*(((c.size()>0)?(c.back()):(qr+1))-z)*h[z];
      c.push_back(x);
      mi=min(mi,cst[x]+ans-h[x]);
    }
    fnl[i]=mi;
  }
  return fnl;
}

Compilation message (stderr)

meetings.cpp:9:1: error: reference to 'data' is ambiguous
    9 | data sp[N][LG];
      | ^~~~
In file included from /usr/include/c++/13/vector:69,
                 from meetings.h:3,
                 from meetings.cpp:1:
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
meetings.cpp:4:8: note:                 'struct data'
    4 | struct data
      |        ^~~~
meetings.cpp:10:1: error: reference to 'data' is ambiguous
   10 | data merge(data a,data b)
      | ^~~~
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
meetings.cpp:4:8: note:                 'struct data'
    4 | struct data
      |        ^~~~
meetings.cpp: In function 'int get(int, int)':
meetings.cpp:23:3: error: reference to 'data' is ambiguous
   23 |   data cur={0,0,0,0};
      |   ^~~~
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
meetings.cpp:4:8: note:                 'struct data'
    4 | struct data
      |        ^~~~
meetings.cpp:28:7: error: 'cur' was not declared in this scope
   28 |       cur=merge(cur,sp[ql][j]);
      |       ^~~
meetings.cpp:28:21: error: 'sp' was not declared in this scope
   28 |       cur=merge(cur,sp[ql][j]);
      |                     ^~
meetings.cpp:28:11: error: 'merge' was not declared in this scope
   28 |       cur=merge(cur,sp[ql][j]);
      |           ^~~~~
meetings.cpp:32:10: error: 'cur' was not declared in this scope
   32 |   return cur.mx;
      |          ^~~
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:47:9: error: 'sp' was not declared in this scope
   47 |         sp[i][0]={0,0,0,1};
      |         ^~
meetings.cpp:51:9: error: 'sp' was not declared in this scope
   51 |         sp[i][0]={1,1,1,1};
      |         ^~
meetings.cpp:57:9: error: 'sp' was not declared in this scope
   57 |         sp[i][j]=merge(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
      |         ^~
meetings.cpp:57:18: error: 'merge' was not declared in this scope
   57 |         sp[i][j]=merge(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
      |                  ^~~~~