답안 #591648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591648 2022-07-07T17:29:31 Z blue Election (BOI18_election) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;
 
using vi = vector<int>;
 
const int inf = 1'000'000'000;

vi p, s;

struct sdata
{
	int pmx = -inf;
	int smx = -inf;
	int ans = -inf;
};

sdata combine(sdata a, sdata b)
{
	return {max(a.pmx, b.pmx), max(a.smx, b.smx), max({a.ans, b.ans, a.pmx + b.smx})};
}

struct segtree
{
	int l;
	int r;
	sdata v;

	segtree* left = NULL;
	segtree* right = NULL;

	segtree()
	{	
		;
	}

	segtree(int L, int R)
	{
		l = L;
		r = R;
		if(l == r)
			v = sdata{p[l], s[l], p[l]+s[l]};
		else
		{
			int m = (l+r)/2;
			left = new segtree(l, m);
			right = new segtree(m+1, r);
			v = combine(left->v, right->v);
		}
	}

	sdata getrange(int L, int R)
	{
		if(L <= l && r <= R)
			return v;
		else if(R <= (l+r)/2)
			return left->getrange(L, R);
		else if(L >= (l+r)/2+1)
			return right->getrange(L, R);
		else
			return combine(left->getrange(L, R), right->getrange(L, R));
	}
};
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	int N;
	cin >> N;
 
	vi A(1+N);
	for(int i = 1; i <= N; i++)
	{
		char c;
		cin >> c;
 
		if(c == 'T')
			A[i] = +1;
		else
			A[i] = -1;
	}
 
	p = vi(1+N);
	p[0] = 0;
	for(int i = 1; i <= N; i++)
		p[i] = p[i-1] + A[i];
 
	s = vi(1+N);
	s[N] = 0;
	for(int i = N-1; i >= 0; i--)
		s[i] = s[i+1] + A[i+1];

	segtree ST(0, N);
 
 
 
	int Q;
	cin >> Q;
 
	for(int q = 1; q <= Q; q++)
	{
		int l, r;
		cin >> l >> r;

		sdata d = ST.getrange(l-1, r);
 
		int pmx = d.pmx;
 
		int c1 = pmx - p[l-1];
 
		// cerr << "c1 = " << c1 << '\n';
		// cerr << "pmx = " << pmx << '\n';
 
 
		// int c2 = 0;
		int res = +s[r] + p[l-1];

		res = max(res, d.ans);
 
 
		res -= s[r] + p[l-1];

		res = max(res, c1);
 
		cout << res << '\n';
 
 
	}
}

Compilation message

election.cpp: In function 'sdata combine(sdata, sdata)':
election.cpp:20:81: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   20 |  return {max(a.pmx, b.pmx), max(a.smx, b.smx), max({a.ans, b.ans, a.pmx + b.smx})};
      |                                                                                 ^
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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from election.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:
election.cpp:20:81: note:   candidate expects 2 arguments, 1 provided
   20 |  return {max(a.pmx, b.pmx), max(a.smx, b.smx), max({a.ans, b.ans, a.pmx + b.smx})};
      |                                                                                 ^
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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from election.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:
election.cpp:20:81: note:   candidate expects 3 arguments, 1 provided
   20 |  return {max(a.pmx, b.pmx), max(a.smx, b.smx), max({a.ans, b.ans, a.pmx + b.smx})};
      |                                                                                 ^
election.cpp:20:82: error: could not convert '{std::max<int>(a.sdata::pmx, b.sdata::pmx), std::max<int>(a.sdata::smx, b.sdata::smx), <expression error>}' from '<brace-enclosed initializer list>' to 'sdata'
   20 |  return {max(a.pmx, b.pmx), max(a.smx, b.smx), max({a.ans, b.ans, a.pmx + b.smx})};
      |                                                                                  ^
      |                                                                                  |
      |                                                                                  <brace-enclosed initializer list>