답안 #204720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204720 2020-02-26T18:46:04 Z Kastanda Bubble Sort 2 (JOI18_bubblesort2) C++11
컴파일 오류
0 ms 0 KB
// In The Name Of The Queen
#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
const int N = 500005, MXS = N * 2 * 4;
int n, q, MX[MXS], LZ[MXS];
vector < pair < int , int > > U;
void Add(int le, int ri, int val, int id = 1, int l = 0, int r = (int)U.size())
{
    if (ri <= l || r <= le)
        return ;
    if (le <= l && r <= ri)
    {
        MX[id] += val;
        LZ[id] += val;
        return ;
    }
    Add(le, ri, val, lc, l, md);
    Add(le, ri, val, rc, md, r);
    MX[id] = max(MX[lc], MX[rc]) + LZ[id];
}
vector < int > countScans(vector < int > A, vector < int > X, vector < int > V)
{
    n = (int)A.size();
    q = (int)X.size();
    for (int i = 0; i < n; i ++)
        U.push_back({A[i], i});
    for (int i = 0; i < q; i ++)
        U.push_back({V[i], X[i]});
    sort(U.begin(), U.end());
    U.resize(unique(U.begin(), U.end()));

    auto GetId = [&] (pair < int , int > val) {
        return (int)(lower_bound(U.begin(), U.end(), val) - U.begin());
    };

    auto Apply = [&] (int i, int val) {
        int p = GetId({A[i], i});
        Add(p, p + 1, i * val);
        int l = GetId({A[i], -1});
        Add(l, (int)U.size(), val);
    }

    for (int i = 0; i < n; i ++)
        Apply(i, 1);
    vector < int > R;
    for (int i = 0; i < q; i ++)
    {
        Apply(X[i], -1);
        A[X[i]] = V[i];
        Apply(X[i], 1);
        R.push_back(MX[1]);
    }
    return (R);
}

Compilation message

bubblesort2.cpp: In function 'void Add(int, int, int, int, int, int)':
bubblesort2.cpp:18:22: error: 'lc' was not declared in this scope
     Add(le, ri, val, lc, l, md);
                      ^~
bubblesort2.cpp:18:22: note: suggested alternative: 'le'
     Add(le, ri, val, lc, l, md);
                      ^~
                      le
bubblesort2.cpp:18:29: error: 'md' was not declared in this scope
     Add(le, ri, val, lc, l, md);
                             ^~
bubblesort2.cpp:18:29: note: suggested alternative: 'id'
     Add(le, ri, val, lc, l, md);
                             ^~
                             id
bubblesort2.cpp:19:22: error: 'rc' was not declared in this scope
     Add(le, ri, val, rc, md, r);
                      ^~
bubblesort2.cpp:19:22: note: suggested alternative: 'ri'
     Add(le, ri, val, rc, md, r);
                      ^~
                      ri
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:31:40: error: no matching function for call to 'std::vector<std::pair<int, int> >::resize(__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >)'
     U.resize(unique(U.begin(), U.end()));
                                        ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from bubblesort2.cpp:2:
/usr/include/c++/7/bits/stl_vector.h:689:7: note: candidate: void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]
       resize(size_type __new_size)
       ^~~~~~
/usr/include/c++/7/bits/stl_vector.h:689:7: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >' to 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}'
/usr/include/c++/7/bits/stl_vector.h:709:7: note: candidate: void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       resize(size_type __new_size, const value_type& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_vector.h:709:7: note:   candidate expects 2 arguments, 1 provided
bubblesort2.cpp:44:5: error: expected ',' or ';' before 'for'
     for (int i = 0; i < n; i ++)
     ^~~
bubblesort2.cpp:44:21: error: 'i' was not declared in this scope
     for (int i = 0; i < n; i ++)
                     ^