답안 #749440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749440 2023-05-28T03:37:31 Z ThMinh_ 3단 점프 (JOI19_jumps) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#define forin(i,a,b) for(int i=a;i<=b;++i)
#define forde(i,a,b) for(int i=a;i>=b;--i)
#define ll long long
using namespace std;
const int N = 5e5 + 10;
int n, q;
ll d[N], tr[N << 2], lazy[N << 2], ans[N], sp[20][N];
struct query {
    int f, l, pos;
};
query r[N];
void build() {
    forin(i,1,n) sp[0][i] = d[i];
    forin(j,1,log2(n)) {
        forin(i,1,n - (1 << j - 1) + 1) {
            sp[j][i] = max(sp[j - 1][i], sp[j - 1][i + (1 << j - 1)]);
        }
    }
}
ll mx(int f, int l) {
    if(f == l) return d[f];
    int j = log2(l - f + 1);
    return max(sp[j][f], sp[j][l - (1 << j) + 1]);
}
void push(int id, int f, int l) {
    ll t = lazy[id];
    if(t) {
        tr[id] = max(tr[id], t + mx(f, l));
        if(f < l) {
            lazy[id << 1] = max(lazy[id << 1], t);
            lazy[id << 1 | 1] = max(lazy[id << 1 | 1], t);
        }
        lazy[id] = 0;
    }
}
void up(int u, int v, ll val, int id = 1, int f = 1, int l = n) {
    push(id, f, l);
    if(v < f || l < u) return;
    if(u <= f && l <= v) {
        lazy[id] = max(lazy[id], val);
        push(id, f, l);
        return;
    }
    int mid = f + l >> 1;
    up(u, v, val, id << 1, f, mid);
    up(u, v, val, id << 1 | 1, mid + 1, l);
    tr[id] = max(tr[id << 1], tr[id << 1 | 1]);
}
ll get(int u, int v, int id = 1, int f = 1, int l = n) {
    push(id, f, l);
    if(v < f || l < u) return 0;
    if(u <= f && l <= v) return tr[id];
    int mid = f + l >> 1;
    return max(get(u, v, id << 1, f, mid), get(u, v, id << 1 | 1, mid + 1, l));
}
int main () {
    cin.tie(0)->sync_with_stdio(0);
    if(fopen("Task.inp","r")) {
        freopen("Task.inp","r",stdin);
        freopen("WA.out","w",stdout);
    }
    cin>>n;
    forin(i,1,n) cin>>d[i];
    build();
    cin>>q;
    forin(i,1,q) {
        r[i].pos = i;
        cin>>r[i].f>>r[i].l;
    }
    sort(r + 1, r + q + 1, [] (querysa a, query b) {
        return a.f > b.f;
    });
    stack<int> st;
    vector<pair<int, int>> vt;
    vt.push_back({0, 0});
    forde(i,n,1) {
        while(!st.empty() && d[st.top()] <= d[i]) {
            vt.push_back({i, st.top()});
            st.pop();
        }
        if(!st.empty()) vt.push_back({i, st.top()});
        st.push(i);
    }
    int j = 1;
    forin(i,1,q) {
        while(j <= vt.size() - 1 && vt[j].first >= r[i].f) {
            int a, b; tie(a, b) = vt[j++];
            if(2 * b - a > n) continue;
            up(2 * b - a, n, d[a] + d[b]);
        }
        ans[r[i].pos] = get(r[i].f, r[i].l);
    }
    forin(i,1,q) cout<<ans[i]<<"\n";
}

Compilation message

jumps.cpp: In function 'void build()':
jumps.cpp:16:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   16 |         forin(i,1,n - (1 << j - 1) + 1) {
      |                             ~~^~~
jumps.cpp:2:37: note: in definition of macro 'forin'
    2 | #define forin(i,a,b) for(int i=a;i<=b;++i)
      |                                     ^
jumps.cpp:17:64: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   17 |             sp[j][i] = max(sp[j - 1][i], sp[j - 1][i + (1 << j - 1)]);
      |                                                              ~~^~~
jumps.cpp: In function 'void up(int, int, long long int, int, int, int)':
jumps.cpp:45:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |     int mid = f + l >> 1;
      |               ~~^~~
jumps.cpp: In function 'long long int get(int, int, int, int, int)':
jumps.cpp:54:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |     int mid = f + l >> 1;
      |               ~~^~~
jumps.cpp: In function 'int main()':
jumps.cpp:71:32: error: 'querysa' has not been declared
   71 |     sort(r + 1, r + q + 1, [] (querysa a, query b) {
      |                                ^~~~~~~
jumps.cpp: In lambda function:
jumps.cpp:72:18: error: request for member 'f' in 'a', which is of non-class type 'int'
   72 |         return a.f > b.f;
      |                  ^
jumps.cpp: In function 'int main()':
jumps.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         while(j <= vt.size() - 1 && vt[j].first >= r[i].f) {
      |               ~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 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 jumps.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = query*; _Iterator2 = query*; _Compare = main()::<lambda(int, query)>]':
/usr/include/c++/10/bits/stl_algo.h:82:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1924:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1958:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = query*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = query*; _Compare = main()::<lambda(int, query)>]'
jumps.cpp:73:6:   required from here
/usr/include/c++/10/bits/predefined_ops.h:156:30: error: no match for call to '(main()::<lambda(int, query)>) (query&, query&)'
  156 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
jumps.cpp:71:28: note: candidate: 'main()::<lambda(int, query)>'
   71 |     sort(r + 1, r + q + 1, [] (querysa a, query b) {
      |                            ^
jumps.cpp:71:28: note:   no known conversion for argument 1 from 'query' to 'int'
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 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 jumps.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = query; _Iterator = query*; _Compare = main()::<lambda(int, query)>]':
/usr/include/c++/10/bits/stl_algo.h:1826:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Val_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1854:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1886:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1977:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = query*; _Compare = main()::<lambda(int, query)>]'
jumps.cpp:73:6:   required from here
/usr/include/c++/10/bits/predefined_ops.h:238:23: error: no match for call to '(main()::<lambda(int, query)>) (query&, query&)'
  238 |  { return bool(_M_comp(__val, *__it)); }
      |                ~~~~~~~^~~~~~~~~~~~~~
jumps.cpp:71:28: note: candidate: 'main()::<lambda(int, query)>'
   71 |     sort(r + 1, r + q + 1, [] (querysa a, query b) {
      |                            ^
jumps.cpp:71:28: note:   no known conversion for argument 1 from 'query' to 'int'
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 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 jumps.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = query*; _Value = query; _Compare = main()::<lambda(int, query)>]':
/usr/include/c++/10/bits/stl_heap.h:139:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = query*; _Distance = long int; _Tp = query; _Compare = __gnu_cxx::__ops::_Iter_comp_val<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_heap.h:246:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = query*; _Distance = long int; _Tp = query; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_heap.h:355:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1666:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1937:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1953:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = query*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = query*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(int, query)> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = query*; _Compare = main()::<lambda(int, query)>]'
jumps.cpp:73:6:   required from here
/usr/include/c++/10/bits/predefined_ops.h:194:23: error: no match for call to '(main()::<lambda(int, query)>) (query&, query&)'
  194 |  { return bool(_M_comp(*__it, __val)); }
      |                ~~~~~~~^~~~~~~~~~~~~~
jumps.cpp:71:28: note: candidate: 'main()::<lambda(int, query)>'
   71 |     sort(r + 1, r + q + 1, [] (querysa a, query b) {
      |                            ^
jumps.cpp:71:28: note:   no known conversion for argument 1 from 'query' to 'int'
jumps.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("Task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("WA.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~