Submission #151367

# Submission time Handle Problem Language Result Execution time Memory
151367 2019-09-02T14:34:03 Z theboatman Bigger segments (IZhO19_segments) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;

typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 30000 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        short add;
    };

    int v, tl, tr;
    vector <node> t;

    void build(int n) {
        v = 1;
        tl = 0;
        tr = n - 1;

        t.assign(n * 4, make_struct(-inf, -inf));
    }

    void push(int v) {
        t[v * 2].add = max(t[v * 2].add, t[v].add);
        t[v * 2 + 1].add = max(t[v * 2 + 1].add, t[v].add);
    }

    void modify(int v, int tl, int tr, int l, int r, int x) {
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].add = max(t[v].add, x);
            return;
        }

        int tm = (tl + tr) / 2;
        modify(v * 2, tl, tm, l, min(r, tm), x);
        modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x);
    }

    int get(int v, int tl, int tr, int pos) {

        if (tl == tr) {
            return t[v].add;
        }

        push(v);

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            return get(v * 2, tl, tm, pos);
        }
        else {
            return get(v * 2 + 1, tm + 1, tr, pos);
        }
    }

    int get(int pos) {
        return get(v, tl, tr, pos);
    }

    void modify(int l, int r, int x) {
        modify(v, tl, tr, l, r, x);
    }
};

tree dp[3010];
vector <long long> pref;

long long get(int l, int r) {
    long long res = pref[r];

    return (l ? res - pref[l - 1] : res);
}

int32_t main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int i = 0; i < n; i++) {
        dp[i].build(n);
    }

    dp[0].modify(0, n - 1, 1);

    pref.resize(n);
    for(int i = 0; i < n; i++) {
        pref[i] = (i ? pref[i - 1] + a[i] : a[i]);
    }


    for(int i = 0; i < n; i++) {
        for(int j = i; j < n; j++) {
            int l = j + 1, r = n;
            while(l < r) {
                int c = (l + r) / 2;
                if (get(i, j) > get(j + 1, c)) {
                    l = c + 1;
                }
                else {
                    r = c;
                }
            }

//            l = j + 1;
//            while(l < n && get(i, j) > get(j + 1, l)) {
//                l++;
//            }

            //cout << i << " " << j << " " << dp[i].get(j) + 1 << " " << l << " " << n - 1 << "\n";
            dp[j + 1].modify(l, n - 1, dp[i].get(j) + 1);
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans = max(ans, dp[i].get(j));
        }
    }

    cout << ans << "\n";
    return 0;
}
/*
*/

Compilation message

segments.cpp: In member function 'void tree::build(int)':
segments.cpp:27:48: error: no matching function for call to 'std::vector<tree::node>::assign(int, <brace-enclosed initializer list>)'
         t.assign(n * 4, make_struct(-inf, -inf));
                                                ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from segments.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:501:7: note: candidate: void std::vector<_Tp, _Alloc>::assign(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = tree::node; _Alloc = std::allocator<tree::node>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = tree::node]
       assign(size_type __n, const value_type& __val)
       ^~~~~~
/usr/include/c++/7/bits/stl_vector.h:501:7: note:   no known conversion for argument 2 from '<brace-enclosed initializer list>' to 'const value_type& {aka const tree::node&}'
/usr/include/c++/7/bits/stl_vector.h:520:2: note: candidate: template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = tree::node; _Alloc = std::allocator<tree::node>]
  assign(_InputIterator __first, _InputIterator __last)
  ^~~~~~
/usr/include/c++/7/bits/stl_vector.h:520:2: note:   template argument deduction/substitution failed:
/usr/include/c++/7/bits/stl_vector.h:546:7: note: candidate: void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = tree::node; _Alloc = std::allocator<tree::node>]
       assign(initializer_list<value_type> __l)
       ^~~~~~
/usr/include/c++/7/bits/stl_vector.h:546:7: note:   candidate expects 1 argument, 2 provided
segments.cpp: In member function 'void tree::modify(int, int, int, int, int, int)':
segments.cpp:41:39: error: no matching function for call to 'max(short int&, int&)'
             t[v].add = max(t[v].add, x);
                                       ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from segments.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
segments.cpp:41:39: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
             t[v].add = max(t[v].add, x);
                                       ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from segments.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
segments.cpp:41:39: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
             t[v].add = max(t[v].add, x);
                                       ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from segments.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
segments.cpp:41:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
             t[v].add = max(t[v].add, x);
                                       ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from segments.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
segments.cpp:41:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
             t[v].add = max(t[v].add, x);
                                       ^