QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572965#9222. Price ComboYansuan_HClCompile Error//C++203.4kb2024-09-18 16:56:492024-09-18 16:56:54

Judging History

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

  • [2024-09-18 16:56:54]
  • 评测
  • [2024-09-18 16:56:49]
  • 提交

answer

#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
using ll = long long;

#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { x = 0; char GC; bool f = 0;
	for (; !IC; GC) f |= c == '-';
	for (; IC; GC) x = x * 10 + c - 48;
	if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define meow(...) fprintf(stderr, __VA_ARGS__)
#define Assert(e, v) if (!(e)) exit(v);

const int N = 200005;
int n;

const ll inf = 1e18;
using info = array<ll, 4>; using tag = array<array<ll, 4>, 4>;
void clear(tag &l) {
	U (x, 0, 3) l[x].fill(inf);
}
void init(tag &l) {
	clear(l);
	U (x, 0, 3) l[x][x] = 0;
}
void mul(info &f, info l, const tag &r) {
	f.fill(inf);
	U (x, 0, 3) U (y, 0, 3) f[y] = min(f[y], l[x] + r[x][y]);
}
void mul(tag &f, tag l, const tag &r) {
	clear(f);
	U (i, 0, 3) U (j, 0, 3) if (l[i][j] != inf) U (k, 0, 3) if (r[j][k] != inf)
		f[i][k] = min(f[i][k], l[i][j] + r[j][k]);
}
void check(info &f, const info &l, const info &r) {
	U (i, 0, 3) f[i] = min(l[i], r[i]);
}

#define mid ((l + r) >> 1)
#define ls (p << 1)
#define rs (ls | 1)
#define arg int p = 1, int l = 0, int r = n
struct { info v; tag t; bool f; } tr[N * 4];
void app(int p, const tag &t) {
	mul(tr[p].v, tr[p].v, t);
	if (!tr[p].f) {
		tr[p].t = t; tr[p].f = 1;
	} else {
		mul(tr[p].t, tr[p].t, t);
	}
}
void down(int p) {
	if (!tr[p].f) return;
	const tag &t = tr[p].t;
	app(ls, t); app(rs, t);
	tr[p].f = 0;
}
void up(int p) {
	check(tr[p].v, tr[ls].v, tr[rs].v);
}
void mod(int x, const info &v, arg) {
	if (l == r) { tr[p].v = v; return; }
	down(p);
	(x <= mid) ? mod(x, v, ls, l, mid) : mod(x, v, rs, mid + 1, r);
	up(p);
}
void op(int b, int e, const tag &v, arg) {
	if (b <= l && e >= r) { app(p, v); return; }
	down(p);
	if (b <= mid) op(b, e, v, ls, l, mid);
	if (e > mid) op(b, e, v, rs, mid + 1, r);
	up(p);
}
info query(int b, int e, arg) {
	if (b <= l && e >= r) return tr[p].v;
	down(p);
	info f; f.fill(inf);
	if (b <= mid) f = query(b, e, ls, l, mid);
	if (e > mid) check(f, f, query(b, e, rs, mid + 1, r));
	return f;
}
void build(arg) {
	init(tr[p].t); tr[p].v.fill(inf); tr[p].v[0] = 0;
	if (l == r) return;
	build(ls, l, mid); build(rs, mid + 1, r);
}
void add_a(int b, int e, ll v) {
	tag f; clear(f);
	U (i, 0, 3) f[i ^ 2][i] = (i & 2 ? v : 0);
	op(b, e, f);
}
void add_b(int b, int e, ll v) {
	tag f; clear(f);
	U (i, 0, 3) f[i ^ 1][i] = (i & 1 ? v : 0);
	op(b, e, f);
}

ll a[N], b[N];
pair<ll, int> la[N], lb[N];
int refa[N], refb[N];
signed main() {
//	freopen("ava.in", "r", stdin);
	
	rd(n);
	U (i, 1, n) rd(a[i]), la[i] = {a[i], b[i]};
	U (i, 1, n) rd(b[i]), lb[i] = {b[i], a[i]};
	sort(la + 1, la + n + 1); sort(lb + 1, lb + n + 1);
	U (i, 1, n) {
		int oa = a[i], ob = b[i];
		a[i] = lower_bound(la + 1, la + n + 1, make_pair(oa, ob)) - la;
		b[i] = lower_bound(lb + 1, lb + n + 1, make_pair(ob, oa)) - lb;
		refa[a[i]] = i; refb[b[i]] = i;
	}
	
	build();
	D (x, n, 1) {
		int i = refa[x];
		info t = query(b[i] - 1, n);
		mod(b[i] - 1, t);
		add_a(0, b[i] - 1, la[a[i]].first);
		add_b(b[i], n, lb[b[i]].first);
		assert(a[i] == x);
	}
	ll ans = inf;
	U (i, 0, 3) ans = min(ans, tr[1].v[i]);
	printf("%lld\n", ans);
}

Details

In file included from /usr/include/c++/13/bits/stl_algobase.h:71,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = std::pair<long long int, int>*; _Value = const std::pair<int, int>]’:
/usr/include/c++/13/bits/stl_algobase.h:1472:14:   required from ‘constexpr _ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = pair<long long int, int>*; _Tp = pair<int, int>; _Compare = __gnu_cxx::__ops::_Iter_less_val]’
/usr/include/c++/13/bits/stl_algobase.h:1507:32:   required from ‘constexpr _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = pair<long long int, int>*; _Tp = pair<int, int>]’
answer.code:116:21:   required from here
/usr/include/c++/13/bits/predefined_ops.h:69:22: error: no match for ‘operator<’ (operand types are ‘std::pair<long long int, int>’ and ‘const std::pair<int, int>’)
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/bits/stl_algobase.h:67:
/usr/include/c++/13/bits/stl_iterator.h:1189:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> __gnu_cxx::operator<=>(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)’ (reversed)
 1189 |     operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1189:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:181:
/usr/include/c++/13/bits/regex.h:1288:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Alloc> auto std::__cxx11::operator<=>(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)’ (reversed)
 1288 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1288:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, int>’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/regex.h:1456:5: note: candidate: ‘template<class _Bi_iter> auto std::__cxx11::operator<=>(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)’ (reversed)
 1456 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1456:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, int>’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/regex.h:1629:5: note: candidate: ‘template<class _Bi_iter> auto std::__cxx11::operator<=>(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)’ (reversed)
 1629 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1629:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, int>’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:583:5: note: candidate: ‘template<class _IteratorL, class _IteratorR>  requires  three_way_comparable_with<_IteratorR, _IteratorL, std::partial_ordering> constexpr std::compare_three_way_result_t<_IteratorL, _IteratorR> std::operator<=>(const reverse_iterator<_IteratorL>&, const reverse_iterator<_IteratorR>&)’ (reversed)
  583 |     operator<=>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:583:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:69:22: note:   ‘const std::pair<int, int>’ is not derived from ‘const std::reverse_iterator<_IteratorL>’
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1690:5: note: candidate: ‘template<class _IteratorL, class _IteratorR...