답안 #502176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502176 2022-01-05T12:13:29 Z keta_tsimakuridze Peru (RMI20_peru) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "peru.h"
#define f first
#define s second
#define ll long long
#define pii pair<ll,ll>
#define int long long
using namespace std;
const int N = 2000 + 5, mod = 1e9 + 7;
ll lazy[4 * N], tree[4 * N], k, n, p[N], dp[N];
void push(int u,int l,int r) {
	if(!lazy[u]) return;
	tree[u] += lazy[u];
	if(l != r) {
		lazy[2 * u] += lazy[u];
		lazy[2 * u + 1] += lazy[u];
	}
	lazy[u] = 0;
}
void upd(int u,int st,int en,int l,int r,int val) {
	push(u, l, r);
	if(l > en || r < st) return;
	if(st <= l && r <= en) {
		lazy[u] = val;
		push(u, l, r);
		return;
	}
	int mid = (l + r) / 2;
	upd(2 * u, st, en, l, mid, val); upd(2 * u + 1, st, en, mid + 1, r, val);
	tree[u] = min(tree[2 * u], tree[2 * u + 1]);
}
ll get(int u,int st,int en, int l,int r) {
	push(u, l, r);
	if(l > en || r < st) return 1e18;
	if(st <= l && r <= en) return tree[u];
	int mid = (l + r) / 2;
	return min(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
}
int solve(int n, int k, int* v){
    stack<pair<int, pii> > st;
    vector<int> s(n + 5);
    p[0] = 1;
    for(int i = 1; i < n; i++) p[i] = p[i - 1] * 23 % mod;
    ll ans = 0, mn = 0;
    for(int i = 1; i <= n; i++) {
    	s[i] = v[i - 1]; mn = max(mn, (ll)s[i]);
    	int l = i;
    	while(st.size() && st.top().f <= s[i]) {
    		l = st.top().s.f;
    		upd(1, st.top().s.f, st.top().s.s, 1, n, - st.top().f + s[i]);
    		st.pop();
		}
		upd(1, i, i, 0, n, dp[i - 1] + s[i]);
		dp[i] = get(1, max(1, i - k + 1), i - 1, 1, n);
		if(i - k + 1 <= 0) dp[i] = min(dp[i], mn);
		st.push({s[i], {l, i}});
		ans += p[n- i] * (dp[i] % mod); ans %= mod;

	}
	return ans;
}

Compilation message

peru.cpp: In function 'long long int solve(long long int, long long int, long long int*)':
peru.cpp:54:34: error: no matching function for call to 'max(int, long long int)'
   54 |   dp[i] = get(1, max(1, i - k + 1), i - 1, 1, n);
      |                                  ^
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: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:
peru.cpp:54:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   54 |   dp[i] = get(1, max(1, i - k + 1), i - 1, 1, n);
      |                                  ^
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: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:
peru.cpp:54:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   54 |   dp[i] = get(1, max(1, i - k + 1), i - 1, 1, n);
      |                                  ^
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: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:
peru.cpp:54:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   54 |   dp[i] = get(1, max(1, i - k + 1), i - 1, 1, n);
      |                                  ^
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: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:
peru.cpp:54:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   54 |   dp[i] = get(1, max(1, i - k + 1), i - 1, 1, n);
      |                                  ^