제출 #1346742

#제출 시각아이디문제언어결과실행 시간메모리
1346742nguyenkhangninh99Bubble Sort 2 (JOI18_bubblesort2)C++20
컴파일 에러
0 ms0 KiB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 5;
int st[4 * maxn], lazy[4 * maxn];  
void apply(int id, int val){
    st[id] += val, lazy[id] += val;
}
void update(int id, int l, int r, int u, int v, int val){
    if(y < u || r < u || v < l) return;
    if(u <= l && r <= v) apply(id, val);
    else{
        apply(id * 2, lazy[id]);
        apply(id * 2 + 1, lazy[id]);
        lazy[id] = 0;
        int mid = (l + r) / 2;
        update(id * 2, l, mid, u, v, val);
        update(id * 2 + 1, mid + 1, r, u, v, val);
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }
}

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
    vector<pair<int, int>> cmp;
    for(int i = 0; i < a.size(); i++) cmp.push_back({a[i], i});
    for(int i = 0; i < v.size(); i++) cmp.push_back({v[i], x[i]});
    sort(cmp.begin(), cmp.end());
    cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());

    int n = cmp.size();
    for(int i = 0; i < a.size(); i++){
        a[i] = lower_bound(cmp.begin(), cmp.end(), {a[i], i}) - cmp.begin() + 1;
        update(1, 1, n, a[i], a[i], i);
        update(1, 1, n, a[i] + 1, n, -1);
    }

    vector<int> res;
    for(int i = 0; i < v.size(); i++){
        v[i] = lower_bound(cmp.begin(), cmp.end(), {v[i], x[i]}) - cmp.begin() + 1;
        update(1, 1, n, a[x[i]], a[x[i]], -x[i]);
        update(1, 1, n, a[x[i]] + 1, n, 1);
        update(1, 1, n, v[i], v[i], x[i]);
        update(1, 1, n, v[i] + 1, n, -1);
        a[x[i]] = v[i];
        res.push_back(st[1]);
    }
    return res;
}

컴파일 시 표준 에러 (stderr) 메시지

bubblesort2.cpp: In function 'void update(int, int, int, int, int, int)':
bubblesort2.cpp:11:8: error: 'y' was not declared in this scope
   11 |     if(y < u || r < u || v < l) return;
      |        ^
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:33:27: error: no matching function for call to 'lower_bound(std::vector<std::pair<int, int> >::iterator, std::vector<std::pair<int, int> >::iterator, <brace-enclosed initializer list>)'
   33 |         a[i] = lower_bound(cmp.begin(), cmp.end(), {a[i], i}) - cmp.begin() + 1;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:62,
                 from bubblesort2.h:1,
                 from bubblesort2.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:1498:5: note: candidate: 'template<class _ForwardIterator, class _Tp> constexpr _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1498 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:1498:5: note:   template argument deduction/substitution failed:
bubblesort2.cpp:33:27: note:   couldn't deduce template parameter '_Tp'
   33 |         a[i] = lower_bound(cmp.begin(), cmp.end(), {a[i], i}) - cmp.begin() + 1;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from bubblesort2.cpp:2:
/usr/include/c++/13/bits/stl_algo.h:2005:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> constexpr _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2005 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:2005:5: note:   template argument deduction/substitution failed:
bubblesort2.cpp:33:27: note:   candidate expects 4 arguments, 3 provided
   33 |         a[i] = lower_bound(cmp.begin(), cmp.end(), {a[i], i}) - cmp.begin() + 1;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bubblesort2.cpp:40:27: error: no matching function for call to 'lower_bound(std::vector<std::pair<int, int> >::iterator, std::vector<std::pair<int, int> >::iterator, <brace-enclosed initializer list>)'
   40 |         v[i] = lower_bound(cmp.begin(), cmp.end(), {v[i], x[i]}) - cmp.begin() + 1;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:1498:5: note: candidate: 'template<class _ForwardIterator, class _Tp> constexpr _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1498 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:1498:5: note:   template argument deduction/substitution failed:
bubblesort2.cpp:40:27: note:   couldn't deduce template parameter '_Tp'
   40 |         v[i] = lower_bound(cmp.begin(), cmp.end(), {v[i], x[i]}) - cmp.begin() + 1;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:2005:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> constexpr _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2005 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:2005:5: note:   template argument deduction/substitution failed:
bubblesort2.cpp:40:27: note:   candidate expects 4 arguments, 3 provided
   40 |         v[i] = lower_bound(cmp.begin(), cmp.end(), {v[i], x[i]}) - cmp.begin() + 1;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~