QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#173741#5433. Absolute DifferenceaestheticCompile Error//C++202.8kb2023-09-10 01:35:312023-09-10 01:35:32

Judging History

你现在查看的是最新测评结果

  • [2023-09-10 01:35:32]
  • 评测
  • [2023-09-10 01:35:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
int n, m;

vector<pair<int, int>> split(const vector<pair<int, int>> &v, const vector<int> &pos)
{
	vector<pair<int, int>> ret;
	for(auto[l, r] : v)
	{
		if(l == r)
		{
			ret.emplace_back(l, r);
			continue;
		}
		int last = l;
		auto it = upper_bound(pos.begin(), pos.end(), l);
		while(it != pos.end() && (*it) <= r)
		{
			ret.emplace_back(last, *it);
			last = *it;
			it++;
		}
	}
	return ret;
}

void build_pref(vector<pair<int, int>> &b, int totb, vector<__int128> &pref_exp, vector<__int128> &pref_prob)
{
	int m = b.size();
	for(int i = 0; i < m; ++i)
	{
		auto [l, r] = b[i];
		__int128 E = (r + l);
		__int128 prob = 1;
		if(totb)
			prob = r - l;
		
		pref_prob.push_back((pref_prob.empty() ? 0 : pref_prob.back()) + prob);
		pref_exp.push_back((pref_exp.empty() ? 0 : pref_exp.back()) + prob * E);
	}
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	cin >> n >> m;
	vector<pair<int, int>> a(n), b(m);
	int tota = 0, totb = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i].first >> a[i].second;
		tota += (a[i].second - a[i].first);
	}
	for(int i = 0; i < m; ++i)
	{
		cin >> b[i].first >> b[i].second;
		totb += (b[i].second - b[i].first);
	}
	vector<int> pos;
	for(auto[l, r] : a)
		pos.push_back(l), pos.push_back(r);
	for(auto[l, r] : b)
		pos.push_back(l), pos.push_back(r);
	sort(pos.begin(), pos.end());
	pos.erase(unique(pos.begin(), pos.end()), pos.end());

	a = split(a, pos);
	b = split(b, pos);
	n = a.size();
	m = b.size();
	
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	vector<__int128> pref_exp, pref_prob, suf_exp, suf_prob;
	build_pref(b, totb, pref_exp, pref_prob);
	reverse(b.begin(), b.end());
	build_pref(b, totb, suf_exp, suf_prob);
	reverse(b.begin(), b.end());

	reverse(suf_exp.begin(), suf_exp.end());
	reverse(suf_prob.begin(), suf_prob.end());
	
	__int128 ans = 0;

	for(int i = 0; i < n; ++i)
	{
		auto [l, r] = a[i];
		__int128 E = (r + l);
		__int128 prob = 1;
		if(tota)
			prob = (r - l);

		int j = lower_bound(b.begin(), b.end(), make_pair(r, -1e9)) - b.begin();
		
	
		if(j < m)
			ans += 3 * prob * (suf_exp[j] - suf_prob[j] * E);


		if(j > 0)
		{
			__int128 prob2 = 1;
			__int128 E2 = b[j - 1].first + b[j - 1].second;
			if(totb)
				prob2 = (b[j - 1].second - b[j - 1].first);
			if(b[j - 1] == a[i])
			{
				ans += 2 * prob * prob2 * (r - l);
			}
			else
			{
				ans += 3 * prob * prob2 * (E - E2);
			}

			if(j - 2 >= 0)
				ans += 3 * prob * (pref_prob[j - 2] * E - pref_exp[j - 2]);
		}
	}
	__int128 den = 1;

	if(tota)
		den *= tota;
	else
		den *= n;
	if(totb)
		den *= totb;
	else
		den *= m;
	den *= 6;

	cout << setprecision(20) << fixed << (long double)ans / den << endl;
}

详细

In file included from /usr/include/c++/11/bits/stl_algobase.h:71,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Value = const std::pair<int, double>]’:
/usr/include/c++/11/bits/stl_algobase.h:1464:14:   required from ‘constexpr _ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Tp = std::pair<int, double>; _Compare = __gnu_cxx::__ops::_Iter_less_val]’
/usr/include/c++/11/bits/stl_algobase.h:1499:32:   required from ‘constexpr _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Tp = std::pair<int, double>]’
answer.code:95:22:   required from here
/usr/include/c++/11/bits/predefined_ops.h:69:22: error: no match for ‘operator<’ (operand types are ‘std::pair<int, int>’ and ‘const std::pair<int, double>’)
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/11/bits/stl_algobase.h:67,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_iterator.h:1129:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> __gnu_cxx::operator<=>(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)’ (reversed)
 1129 |     operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/11/bits/stl_iterator.h:1129:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/11/bits/stl_algobase.h:71,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, double>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:110,
                 from answer.code:1:
/usr/include/c++/11/bits/regex.h:1244:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Alloc> auto std::__cxx11::operator<=>(const std::__cxx11::sub_match<_BiIter>&, std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)’ (reversed)
 1244 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/11/bits/regex.h:1244:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/11/bits/stl_algobase.h:71,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, double>’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:110,
                 from answer.code:1:
/usr/include/c++/11/bits/regex.h:1412:5: note: candidate: ‘template<class _Bi_iter> auto std::__cxx11::operator<=>(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)’ (reversed)
 1412 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/11/bits/regex.h:1412:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/11/bits/stl_algobase.h:71,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, doubl...