Submission #1078055

# Submission time Handle Problem Language Result Execution time Memory
1078055 2024-08-27T12:05:31 Z ASN49K Peru (RMI20_peru) C++14
Compilation error
0 ms 0 KB
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
using i64=long long;
const i64 INF=1e18;
const i64 inf=1e9;
const int mod=1e9+7;
const int BASE=23;
int lsb(int x)
{
    return x&(-x);
}
int add(int x,int y)
{
    return (x+y)%mod;
}
int prod(int x,int y)
{
    return (1LL*x*y)%mod;
}
struct Aint
{
    int n;
    vector<i64>aint,lazy;
    void init(int n)
    {
        this->n=n;
        int aint_size=n;
        while(aint_size!=lsb(aint_size))
        {
            aint_size+=lsb(aint_size);
        }
        aint_size<<=1;
        aint.assign(aint_size+1 , 0);
        lazy.assign(aint_size+1 , 0);
    }
    void add(int nod,i64 val)
    {
        aint[nod]+=val;
        lazy[nod]+=val;
    }
    void push_down(int nod)
    {
        add(nod<<1 , lazy[nod]);
        add(nod<<1|1 , lazy[nod]);
        lazy[nod]=0;
    }
    void update(int nod,int st,int dr,int l,int r,i64 val) {
        if (st > r || dr < l) {
            return;
        }
        if (l <= st && dr <= r)
        {
            add(nod , val);
            return;
        }
        push_down(nod);
        int m=(st+dr)/2;
        update(nod<<1,st,m,l,r,val);
        update(nod<<1|1,m+1,dr,l,r,val);
        aint[nod]=min(aint[nod<<1] , aint[nod<<1|1]);
    }
    i64 query(int nod,int st,int dr,int l,int r)
    {
        if (st > r || dr < l) {
            return INF;
        }
        if (l <= st && dr <= r)
        {
            return aint[nod];
        }
        push_down(nod);
        int m=(st+dr)/2;
        return min(query(nod<<1,st,m,l,r) , query(nod<<1|1,m+1,dr,l,r));
    }
};
int solve(int n, int k, int* v)
{
    vector<int>a(n+2 , 2*inf+1);
    for(int i=1;i<=n;i++)
    {
        a[i]=v[i-1];
    }

    stack<int>sk;
    sk.push(0);
    Aint dp;
    dp.init(n+1);
    dp.update(1,0,n,0,0,a[1]);

    int rez=0;
    for(int i=1;i<=n;i++)
    {
        while(a[i]>=a[sk.top()])
        {
            int r=sk.top()-1;
            sk.pop();
            int l=sk.top();
            dp.update(1,0,n,l,r,a[i]-a[r+1]);
        }
        i64 val=dp.query(1,0,n,max(i-k , 0LL),i-1);
        rez=prod(rez , BASE);
        rez=add(rez , val%mod);
        dp.update(1,0,n,i,i,val+a[i+1]);
        sk.push(i);
    }
    return rez;
}

Compilation message

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:101:45: error: no matching function for call to 'max(int, long long int)'
  101 |         i64 val=dp.query(1,0,n,max(i-k , 0LL),i-1);
      |                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from peru.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
peru.cpp:101:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  101 |         i64 val=dp.query(1,0,n,max(i-k , 0LL),i-1);
      |                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from peru.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
peru.cpp:101:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  101 |         i64 val=dp.query(1,0,n,max(i-k , 0LL),i-1);
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from peru.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
peru.cpp:101:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  101 |         i64 val=dp.query(1,0,n,max(i-k , 0LL),i-1);
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from peru.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
peru.cpp:101:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  101 |         i64 val=dp.query(1,0,n,max(i-k , 0LL),i-1);
      |                                             ^