Submission #889467

# Submission time Handle Problem Language Result Execution time Memory
889467 2023-12-19T19:14:31 Z ace5 Fire (JOI20_ho_t5) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define int int64_t

const int maxn = 200001;
const int sqr = 450;

vector<int> que[maxn];
int pr[maxn];
vector<pair<int,int>> otr;
int co[maxn];
int s[maxn];
int ans[maxn];
int bl[maxn];
pair<int,int> z[maxn];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    for(int i = 0;i < n;++i)
    {
        cin >> s[i];
    }
    for(int i = 0;i < q;++i)
    {
        int t,l,r;
        cin >> t >> l >> r;
        l--;
        r--;
        z[i] = {l,r};
        que[t].push_back(i);
    }
    for(int i = 1;i <= sqr;++i)
    {
        for(int j = n-1;j >= 1;--j)
        {
            s[j] = max(s[j],s[j-1]);
        }
        pr[0] = 0;
        for(int j = 0;j < n;++j)
        {
            pr[j+1] = pr[j] + s[j];
        }
        for(auto j : que[i])
        {
            ans[j] = pr[z[j].second+1]-pr[z[j].first];
        }
    }
    for(int i = sqr;i <= n;i *= 2)
    {
        otr.clear();
        int bnr = -1;
        int yk = -1;
        vector<int> st;
        int tl =  -1;
        vector<vector<int>> m(i+1);
        for(int j = 0;j < n;++j)
        {
            if(j != 0 && s[j] != s[j-1])
            {
                bnr = j-1;
            }
            while(st.size() && s[st.back()] <= s[j])
            {
                st.pop_back();
            }
            if(st.size() == 0 || st.back() != bnr)
            {
                if(tl == -1)
                {
                    tl = j;
                    co[j] = yk++;
                }
                else
                    co[j] = yk;
                if(st.size() != 0 && j-st.back() < i+1)
                {
                    m[j-st.back()].push_back(yk);
                }
            }
            else
            {
                if(tl != -1)
                {
                    otr.push_back({tl,j-1});
                    tl = -1;
                }
            }
            st.push_back(j);
        }
        if(tl != -1)
        {
            otr.push_back({tl,n-1});
        }
        for(int k = i+1;k <= 2*i;++k)
        {
            for(int u = 0;u < m[k-i].size();++u)
            {
                otr[m[k-i][u]].first++;
            }
            for(auto j : que[k])
            {
                int l = z[j].first;
                int r = z[j].second;
                int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
                for(auto [ll,rr] : otr)
                {
                    ll = max(ll,l);
                    rr = min(rr,r);
                    if(ll <= rr)
                    {
                        res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
                        res += pr[rr+1] - pr[ll];
                    }
                }
                ans[j] = res;
            }
        }
        for(int j = n-1;j >= i;--j)
        {
            s[j] = max(s[j],s[j-i]);
        }
        for(int j = 0;j < n;++j)
        {
            pr[j+1] = pr[j] + s[j];
        }
    }
    for(int j = 0;j < q;++j)
    {
        cout << ans[j] << "\n";
    }
    return 0;
}

Compilation message

ho_t5.cpp: In function 'int main()':
ho_t5.cpp:102:29: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             for(int u = 0;u < m[k-i].size();++u)
      |                           ~~^~~~~~~~~~~~~~~
ho_t5.cpp:110:47: error: no matching function for call to 'max(long long int, int64_t)'
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:47: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:47: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                               ^
ho_t5.cpp:110:68: error: no matching function for call to 'max(long long int, int64_t)'
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:68: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:68: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:68: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:110:68: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  110 |                 int res = pr[max(0ll,r+1-(k-i))]-pr[max(0ll,l-(k-i))];
      |                                                                    ^
ho_t5.cpp:117:53: error: no matching function for call to 'max(long long int, std::tuple_element<1, std::pair<long int, long int> >::type)'
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::tuple_element<1, std::pair<long int, long int> >::type' {aka 'long int'})
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::tuple_element<1, std::pair<long int, long int> >::type' {aka 'long int'})
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                     ^
ho_t5.cpp:117:75: error: no matching function for call to 'max(long long int, std::tuple_element<0, std::pair<long int, long int> >::type)'
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:75: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::tuple_element<0, std::pair<long int, long int> >::type' {aka 'long int'})
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:75: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::tuple_element<0, std::pair<long int, long int> >::type' {aka 'long int'})
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:75: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ho_t5.cpp:1:
/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:
ho_t5.cpp:117:75: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  117 |                         res -= pr[max(0ll,rr+1-(k-i))]-pr[max(0ll,ll-(k-i))];
      |                                                                           ^