QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395213#1375. TripTikmegz112233Compile Error//C++235.4kb2024-04-21 10:55:532024-04-21 10:55:54

Judging History

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

  • [2024-04-21 10:55:54]
  • 评测
  • [2024-04-21 10:55:53]
  • 提交

answer

#include <bits/stdc++.h>

#define sz(x)  (int)x.size()
#define bigint __int128
#define el '\n'
#define ll long long
#define int  long long
//#define int long long
#define ld long double
using namespace std;
const int N = 1e5 + 4, M = 1e5 + 10, mod = 998244353;
int szz = 1;

struct seg_tree {
    vector<vector<pair<int, int>>> tree;
    // weight , idx
    vector<pair<int, int>> neutral = {};
    int k;

    seg_tree(int n, vector<vector<pair<int, int>>> &v, int k) {
        szz = 1;
        while (szz < n)szz <<= 1;
        tree.assign(2 * szz, neutral);
        this->k = k;
        build(v);
    }

    vector<pair<int, int>> merge(vector<pair<int, int>> val1, vector<pair<int, int>> val2) {
        // vector 2*n 3,3
        for (auto x: val2)val1.push_back(x);
        sort(val1.rbegin(), val1.rend());
        while (sz(val1) > k)val1.pop_back();
        return val1;
    }

    void build(vector<vector<pair<int, int>>> &v, int node = 0, int lx = 0, int rx = szz - 1) {
        if (lx == rx) {
            if (lx < sz(v)) {
                tree[node] = v[lx];
            }
            return;
        }
        int mid = lx + rx >> 1;
        build(v, (node << 1) + 1, lx, mid);
        build(v, (node << 1) + 2, mid + 1, rx);
        tree[node] = merge(tree[(node << 1) + 1], tree[(node << 1) + 2]);
    }

    void set(int idx, vector<pair<int, int>> val, int node = 0, int lx = 0, int rx = szz - 1) {
        if (lx == rx) {
            tree[node] = val;
            return;
        }
        int mid = (lx + rx) >> 1;
        if (mid >= idx) {
            set(idx, val, (node << 1) + 1, lx, mid);
        } else {
            set(idx, val, (node << 1) + 2, mid + 1, rx);
        }
        tree[node] = merge(tree[(node << 1) + 1], tree[(node << 1) + 2]);
    }

    vector<pair<int, int>> query(int l, int r, int node = 0, int lx = 0, int rx = szz - 1) {
        if (lx > r or rx < l)return neutral;
        if (lx >= l and rx <= r) {
            return tree[node];
        }
        int mid = lx + rx >> 1;
        vector<pair<int, int>> q1 = query(l, r, (node << 1) + 1, lx, mid);
        vector<pair<int, int>> q2 = query(l, r, (node << 1) + 2, mid + 1, rx);
        return merge(q1, q2);
    }

};

void acc() {
    int n, k;
    cin >> n >> k;
    // 0
    vector<pair<int, int>> points(n);
    // x-axis  , idx
    //  -5 -1 0 1 2 3
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        points[i] = {x, i};
    }
    points.push_back({0, -1});
    sort(points.begin(), points.end());
    n++;
    vector<vector<pair<int, int>>> v(n);
    for (int i = 0; i < n; i++) {
        v[i].push_back({points[i].second, i});
    }
    seg_tree sg(n, v, k);
    int lg = 28;
    vector<int> adj[n + 1][lg];
    vector<int> pw(lg + 1, 1);
    pw[0] = 0;
    for (int i = 2; i < lg; i++)pw[i] = pw[i - 1] * 2;
    for (int bt = 0; bt < lg; bt++) {
//        cout << "with bt = " << bt << el;
//        cout << "---------" << el;
        for (int i = 0; i < n; i++) {
            int l = points[i].first - pw[bt], r = points[i].first + pw[bt];
            auto idxl = std::lower_bound(points.begin(), points.end(), make_pair(l, -1)) - points.begin();
            auto idxr = std::lower_bound(points.begin(), points.end(), make_pair(r, -1)) - points.begin();
            if (idxr == n or points[idxr].first > r)idxr--;
//            cout << points[i].first << " " << idxl << " " << idxr << el;
            vector<pair<int, int>> ret = sg.query(idxl, idxr);
            // weight , idx
            for (auto [val, idx]: ret) {
                adj[i][bt].push_back(idx);
//                cout << idx << " ";
            }
//            cout << "------" << el;
        }
    }
//    for (int i = 0; i < n; i++) {
//        cout << points[i].first << el;
//        for (int j = 0; j < 4; j++) {
//            cout << "with scoop == " << pw[j] << el;
//            for (auto child: adj[i][j]) {
//                cout << child << " ";
//            }
//            cout << el;
//        }
//    }

    int idx_zero = -1;
    for (int i = 0; i < sz(points); i++) {
        if (points[i].first == 0)idx_zero = i;
    }
    priority_queue<array<int, 3>> pq;
    // num_of operation , lst ,  bt
    pq.push({0, idx_zero, 1});
    vector<int> lst(n, 1e9);
    vector<vector<int>> dist(n + 1, vector<int>(lg, 1e9));
    dist[0][1] = 0;
    while (sz(pq)) {
        array<int, 3> arr = pq.top();
        pq.pop();
        int op = -arr[0], node = arr[1], bt = arr[2];
        for (int i = 0; i < lg; i++) {
            int nw_cost = abs(bt - i) + op;
            for (auto child: adj[node][i]) {
                if (dist[child][i] > nw_cost + (child != node)) {
                    dist[child][i] = nw_cost + (child != node);
                    pq.push({-dist[child][i], child, i});
                }
                if (child == node)lst[child] = min(lst[child], nw_cost);
            }
        }
    }
    vector<int> ans(n - 1, 11223344);
    for (int i = 0; i < sz(points); i++) {
        if (points[i].first == 0)continue;
        ans[points[i].second] = lst[i];
    }
    for (int i = 0; i < sz(ans); i++) {
        if (ans[i] >= 1e9)cout << "-1" << el;
        else cout << ans[i] << el;
    }
//    cout << el;
}

signed main() {
    int t = 1;
    cout.tie(0);
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    //  while (t--)acc();
    acc();
}

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 = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Value = const std::pair<long long 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<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Tp = pair<long long 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<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Tp = pair<long long int, int>]’
answer.code:106:41:   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, long long int>’ and ‘const std::pair<long long 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<long long 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<long long 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<long long 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<long long 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 deduct...