답안 #140194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140194 2019-08-02T08:48:24 Z arman_ferdous 3단 점프 (JOI19_jumps) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int N = 5e5+10;
const ll oo = 1e18;

int n;
ll a[N];
deque<pair<int,int>>q;
vector<pair<int,int>> rel;

struct data{
	ll ab, c, sum;
	data(ll x = -oo,ll y = -oo, ll z = -oo) {
		ab = x, c = y, sum = z;
	}
}t[N<<2];

data merge(data L, data R) {
	return data({max(L.ab, R.ab), max(L.c, R.c), max({L.sum, R.sum, L.ab + R.c})});
}

void updAB(int node, int L, int R, int pos, ll x) {
	if(L == R) {
		t[node].ab = max(t[node].ab, x);
		t[node].sum = t[node].ab + t[node].c;
		return;
	} int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;
	if(pos <= mid) updAB(lc, L, mid, pos, x);
	else updAB(rc, mid + 1, R, pos, x);
	t[node] = merge(t[lc], t[rc]);
}

void updC(int node, int L, int R, int pos, ll x) {
	if(L == R) {
		t[node].c = x;
		t[node].sum = t[node].ab + t[node].c;
		return;
	} int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;
	if(pos <= mid) updC(lc, L, mid, pos, x);
	else updC(rc, mid + 1, R, pos, x);
	t[node] = merge(t[lc], t[rc]);
}

data get(int node, int L, int R, int l, int r) {
	if(r < L || R < l) return data();
	if(l <= L && R <= r) return t[node];
	int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;
	data le = get(lc, L, mid, l, r);
	data ri = get(rc, mid + 1, R, l, r);
	return merge(le, ri);
}

vector<pair<int,int>> off[N];
vector<int> candi[N];
ll ans[N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	q.push_back({INT_MAX, -1});
	for(int i = 1; i <= n; i++) {
		while(q.back().first < a[i]) {
			rel.push_back({q.back().second, i});
			q.pop_back();
		}
		if(q.back().second + 1) rel.push_back({q.back().second, i});
		q.push_back({a[i], i});
	}
	for(auto it : rel) candi[it.first].push_back(it.second);

	int m; scanf("%d", &m);
	for(int i = 0; i < m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		off[l].push_back({r, i});
	}
	for(int i = n; i > 0; i--) {
		updC(1, 1, n, i, a[i]);
		for(auto it : candi[i]) if(2 * it - i <= n) updAB(1, 1, n, 2 * it - i, a[i] + a[it]);
		for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
	}
	for(int i = 0; i < m; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

jumps.cpp:20:1: error: reference to 'data' is ambiguous
 data merge(data L, data R) {
 ^~~~
jumps.cpp:13:8: note: candidates are: struct data
 struct data{
        ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from jumps.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
jumps.cpp: In function 'void updAB(int, int, int, int, ll)':
jumps.cpp:32:30: error: no matching function for call to 'merge(data&, data&)'
  t[node] = merge(t[lc], t[rc]);
                              ^
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 jumps.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:4918:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)
     merge(_InputIterator1 __first1, _InputIterator1 __last1,
     ^~~~~
/usr/include/c++/7/bits/stl_algo.h:4918:5: note:   template argument deduction/substitution failed:
jumps.cpp:32:30: note:   candidate expects 5 arguments, 2 provided
  t[node] = merge(t[lc], t[rc]);
                              ^
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 jumps.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:4968:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)
     merge(_InputIterator1 __first1, _InputIterator1 __last1,
     ^~~~~
/usr/include/c++/7/bits/stl_algo.h:4968:5: note:   template argument deduction/substitution failed:
jumps.cpp:32:30: note:   candidate expects 6 arguments, 2 provided
  t[node] = merge(t[lc], t[rc]);
                              ^
jumps.cpp: In function 'void updC(int, int, int, int, ll)':
jumps.cpp:43:30: error: no matching function for call to 'merge(data&, data&)'
  t[node] = merge(t[lc], t[rc]);
                              ^
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 jumps.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:4918:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)
     merge(_InputIterator1 __first1, _InputIterator1 __last1,
     ^~~~~
/usr/include/c++/7/bits/stl_algo.h:4918:5: note:   template argument deduction/substitution failed:
jumps.cpp:43:30: note:   candidate expects 5 arguments, 2 provided
  t[node] = merge(t[lc], t[rc]);
                              ^
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 jumps.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:4968:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)
     merge(_InputIterator1 __first1, _InputIterator1 __last1,
     ^~~~~
/usr/include/c++/7/bits/stl_algo.h:4968:5: note:   template argument deduction/substitution failed:
jumps.cpp:43:30: note:   candidate expects 6 arguments, 2 provided
  t[node] = merge(t[lc], t[rc]);
                              ^
jumps.cpp: At global scope:
jumps.cpp:46:1: error: reference to 'data' is ambiguous
 data get(int node, int L, int R, int l, int r) {
 ^~~~
jumps.cpp:13:8: note: candidates are: struct data
 struct data{
        ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from jumps.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
jumps.cpp: In function 'int main()':
jumps.cpp:82:66: error: no matching function for call to 'get(int, int, int&, int&, int&)'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:229:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)
     get(std::pair<_Tp1, _Tp2>& __in) noexcept
     ^~~
/usr/include/c++/7/utility:229:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:234:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(std::pair<_Tp1, _Tp2>&&)
     get(std::pair<_Tp1, _Tp2>&& __in) noexcept
     ^~~
/usr/include/c++/7/utility:234:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:239:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const std::pair<_Tp1, _Tp2>&)
     get(const std::pair<_Tp1, _Tp2>& __in) noexcept
     ^~~
/usr/include/c++/7/utility:239:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'const std::pair<_Tp1, _Tp2>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:248:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_T1, _T2>&)
     get(pair<_Tp, _Up>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:248:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:253:5: note: candidate: template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_T1, _T2>&)
     get(const pair<_Tp, _Up>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:253:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:258:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_T1, _T2>&&)
     get(pair<_Tp, _Up>&& __p) noexcept
     ^~~
/usr/include/c++/7/utility:258:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:263:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_Up, _Tp>&)
     get(pair<_Up, _Tp>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:263:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::pair<_Up, _Tp>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:268:5: note: candidate: template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_Up, _Tp>&)
     get(const pair<_Up, _Tp>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:268:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'const std::pair<_Up, _Tp>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/7/utility:273:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_Up, _Tp>&&)
     get(pair<_Up, _Tp>&& __p) noexcept
     ^~~
/usr/include/c++/7/utility:273:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::pair<_Up, _Tp>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/array:307:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(std::array<_Tp, _Nm>&)
     get(array<_Tp, _Nm>& __arr) noexcept
     ^~~
/usr/include/c++/7/array:307:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::array<_Tp, _Nm>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/array:316:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(std::array<_Tp, _Nm>&&)
     get(array<_Tp, _Nm>&& __arr) noexcept
     ^~~
/usr/include/c++/7/array:316:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::array<_Tp, _Nm>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/array:324:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const std::array<_Tp, _Nm>&)
     get(const array<_Tp, _Nm>& __arr) noexcept
     ^~~
/usr/include/c++/7/array:324:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'const std::array<_Tp, _Nm>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/tuple:1314:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(std::tuple<_Elements ...>&)
     get(tuple<_Elements...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1314:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/tuple:1320:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const std::tuple<_Elements ...>&)
     get(const tuple<_Elements...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1320:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/tuple:1326:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(std::tuple<_Elements ...>&&)
     get(tuple<_Elements...>&& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1326:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/tuple:1349:5: note: candidate: template<class _Tp, class ... _Types> constexpr _Tp& std::get(std::tuple<_Elements ...>&)
     get(tuple<_Types...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1349:5: note:   template argument deduction/substitution failed:
jumps.cpp:82:66: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
                                                                  ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from jumps.cpp:1:
/usr/include/c++/7/tuple:1355:5: note: candidate: template<class _Tp, class ... _Types> constexpr _Tp&& std::get(std::tuple<_Elements ...>&&)
     get(tuple<_Types...>&& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1355:5: note:   template argument deduction/substitution failed:
/var/local/lib/is