Submission #884130

# Submission time Handle Problem Language Result Execution time Memory
884130 2023-12-06T16:03:59 Z vjudge1 Bubble Sort 2 (JOI18_bubblesort2) C++17
Compilation error
0 ms 0 KB
#include "./bubblesort2.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <climits>
using namespace std;

namespace pbds = __gnu_pbds;

template<typename T>
using ordered_tree = pbds::tree<T, pbds::null_type, less<T>, pbds::rb_tree_tag, pbds::tree_order_statistics_node_update>;

using ipair = array<int, 2>;

constexpr int log2_ceil(int n) {
    int i = 0;
    while ((1 << i) < n) i++;
    return i;
}

const int NMAX = 5e5;

class segment_tree { // poz = valoare, val.min = prima poz, val.max = ultima pozitie

    struct interval {
        int min = INT_MAX;
        int max = INT_MIN;
    };

    int n;
    vector<interval> aint;

    int query_min(int b, int e, int i, int l, int r) {
        if (l <= b && e <= r) return aint[i].min;
        int m = (b + e) / 2;
        if (r <= m) return query_min(b, m, i * 2 + 1, l, r);
        if (l >= m + 1) return query_min(m + 1, e, i * 2 + 2, l, r);
        return min(query_min(b, m, i * 2 + 1, l, r), query_min(m + 1, e, i * 2 + 2, l, r));
    }

    int query_max(int b, int e, int i, int l, int r) {
        if (l <= b && e <= r) return aint[i].max;
        int m = (b + e) / 2;
        if (r <= m) return query_max(b, m, i * 2 + 1, l, r);
        if (l >= m + 1) return query_max(m + 1, e, i * 2 + 2, l, r);
        return max(query_max(b, m, i * 2 + 1, l, r), query_max(m + 1, e, i * 2 + 2, l, r));
    }

    void update(int b, int e, int i, int j, int v) {
        if (b == e) {
            aint[i].min = min(aint[i].min, v);
            aint[i].max = max(aint[i].max, v);
            return;
        }
        int m = (b + e) / 2;
        if (j <= m) update(b, m, i * 2 + 1, j, v);
        else update(m + 1, e, i * 2 + 2, j, v);
        aint[i].min = min(aint[i * 2 + 1].min, aint[i * 2 + 1].min);
        aint[i].max = max(aint[i * 2 + 1].max, aint[i * 2 + 1].max);
    }

    public:

    int query_min(int l, int r) {
        return query_min(0, n-1, 0, l, r);
    }

    int query_max(int l, int r) {
        return query_max(0, n-1, 0, l, r);
    }

    void update(int j, int v) {
        return update(0, n-1, 0, j, v);
    }

    int maxdiff(int j, int v) {
        int ans1 = (j == 0 ? -1 : query_min(0, j-1) - query_max(j, j));
        int ans2 = (j == n-1 ? -1 : query_max)
    }

    segment_tree(int _n) {
        n = _n;
        aint = vector<interval>(2 << log2_ceil(n));
    }
};

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){

    int n = (int)a.size();
	int q = (int)x.size();

    vector<int> answer(q);

    int diff_values = 0;

    {
    vector<int> s(n + q);
    copy(a.begin(), a.end(), s.begin());
    copy(v.begin(), v.end(), s.begin() + n);
    sort(s.begin(), s.end());
    s.resize(unique(s.begin(), s.end()) - s.begin());
    for (int& k : a) k = lower_bound(s.begin(), s.end(), k) - s.begin();
    for (int& k : v) k = lower_bound(s.begin(), s.end(), k) - s.begin();
    diff_values = (int)s.size();
    }

    segment_tree aint(diff_values);

    for (int i = 0; i < n; i++) {
        aint.update(a[i], i);
    }

    multiset<int> maxes;

    for (int i = 0; i < n; i++) {
        maxes.insert(max())
    }

    for (int j = 0; j < q; j++) {
        

    }

	return answer;
}

Compilation message

bubblesort2.cpp: In member function 'int segment_tree::maxdiff(int, int)':
bubblesort2.cpp:80:37: error: invalid use of member function 'int segment_tree::query_max(int, int)' (did you forget the '()' ?)
   80 |         int ans2 = (j == n-1 ? -1 : query_max)
      |                                     ^~~~~~~~~
bubblesort2.cpp:79:13: warning: unused variable 'ans1' [-Wunused-variable]
   79 |         int ans1 = (j == 0 ? -1 : query_min(0, j-1) - query_max(j, j));
      |             ^~~~
bubblesort2.cpp:80:13: warning: unused variable 'ans2' [-Wunused-variable]
   80 |         int ans2 = (j == n-1 ? -1 : query_max)
      |             ^~~~
bubblesort2.cpp:81:5: warning: no return statement in function returning non-void [-Wreturn-type]
   81 |     }
      |     ^
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:118:26: error: no matching function for call to 'max()'
  118 |         maxes.insert(max())
      |                          ^
In file included from /usr/include/c++/10/vector:60,
                 from ./bubblesort2.h:1,
                 from bubblesort2.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:
bubblesort2.cpp:118:26: note:   candidate expects 2 arguments, 0 provided
  118 |         maxes.insert(max())
      |                          ^
In file included from /usr/include/c++/10/vector:60,
                 from ./bubblesort2.h:1,
                 from bubblesort2.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:
bubblesort2.cpp:118:26: note:   candidate expects 3 arguments, 0 provided
  118 |         maxes.insert(max())
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from bubblesort2.cpp:4:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
bubblesort2.cpp:118:26: note:   candidate expects 1 argument, 0 provided
  118 |         maxes.insert(max())
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from bubblesort2.cpp:4:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
bubblesort2.cpp:118:26: note:   candidate expects 2 arguments, 0 provided
  118 |         maxes.insert(max())
      |                          ^