QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#814743#9877. Segment Treeucup-team4435#Compile Error//C++234.1kb2024-12-14 20:14:312024-12-14 20:14:32

Judging History

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

  • [2024-12-14 20:14:32]
  • 评测
  • [2024-12-14 20:14:31]
  • 提交

answer

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ar array

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

const int INFi = 2e9;
const ll INF = 2e18;


void solve() {
    int n; cin >> n;
    n = 1 << n;
    vl c(n * 2);
    for(int i = 1; i < c.size(); ++i) cin >> c[i];
    auto d = c;
    for(int i = n - 1; i >= 1; --i) {
        d[i] = min(c[i], d[i * 2] + d[i * 2 + 1]);
    }
    auto Change = [&] (int i, ll x) {
        c[i] = x;
        for(; i >= 1; i /= 2) {
            d[i] = min(c[i], d[i * 2] + d[i * 2 + 1]);
        }
    };
    auto Find = [&] (int i) {
        vector<pair<int, ll>> res;
        i += n;
        res.emplace_back(i, 0);
        ar<ll, 2> result = {0, 0};
        int l = i;
        int r = i;
        if (!i) {
            res.emplace_back(i + 1, d[i]);
            res.emplace_back(i + 2, d[i / 2]);
            r = i + 2;
            result[1] = d[i / 2];
        } else if (i % 2 == 0) {
            res.emplace_back(i - 1, d[i - 1]);
            res.emplace_back(i - 2, d[(i - 2) / 2]);
            l = i - 2;
            result[0] = d[(i - 2) / 2];
        } else {
            res.emplace_back(i - 1, d[i - 1]);
            res.emplace_back(i + 1, d[i]);
            l = i - 1;
            r = i + 1;
            result[0] = d[i - 1];
            result[1] = d[i];
        }

        int shift = 1;
        while ((1 << shift) < n) {
            ckmin(result[0], result[1] + d[l >> shift]);
            ckmin(result[1], result[0] + d[l >> shift]);
            res.emplace_back(l, result[0]);
            res.emplace_back(r, result[1]);
            int step = (1 << shift);
            if (l & step) {
                l -= step;
                result[0] += d[l >> shift];
            } else {
                result[1] += d[r >> shift];
                r += step;
            }
            shift++;
        }
        ckmin(result[0], result[1] + d[l >> shift]);
        ckmin(result[1], result[0] + d[l >> shift]);
        res.emplace_back(l, result[0]);
        res.emplace_back(r, result[1]);
        sort(all(res));
        return res;
    };

    int q; cin >> q;
    rep(_, q) {
        int tp; cin >> tp;
        if (tp == 1) {
            int j; ll x; cin >> j >> x;
            Change(j, x);
            continue;
        }
        int s, t; cin >> s >> t;
        auto val1 = Find(s);
        auto val2 = Find(t);
        ll ans = INF;
        for(auto &[v, dv] : val2) {
            int it = std::lower_bound(val1.begin(), val1.end(), make_pair(v, -1)) - val1.begin();
            if (it == val1.size() || val1[it].first != v) continue;
            ckmin(ans, val1[it].second + dv);
        }
        cout << ans << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(8) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

/*
 * 3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
1
2 4 8

 */

详细

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:3:
/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 = __gnu_cxx::__normal_iterator<std::pair<int, long long int>*, std::vector<std::pair<int, long long 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 = __gnu_cxx::__normal_iterator<pair<int, long long int>*, vector<pair<int, long long 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 = __gnu_cxx::__normal_iterator<pair<int, long long int>*, vector<pair<int, long long int> > >; _Tp = pair<int, int>]’
answer.code:147:38:   required from here
/usr/include/c++/13/bits/predefined_ops.h:69:22: error: no match for ‘operator<’ (operand types are ‘std::pair<int, long long 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_...