Submission #1092890

# Submission time Handle Problem Language Result Execution time Memory
1092890 2024-09-25T09:50:06 Z MrDogMeat Mountains (NOI20_mountains) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;

using i64 = long long;

const int MAXN = 3e5 + 5;

struct BIT {
    int N, a[MAXN];
    
    void init(int _N) {
        N = _N;
        memset(a, 0, sizeof a);
    }
    
    void update(int p, int v) {
        for(; p <= N; p += p&-p) a[p] += v;
    }
    
    int get_sum(int p) {
        int s = 0;
        for(; p > 0; p -= p&-p) s += a[p];
        return s;
    }
    
    int get_sum(int l, int r) {
        return (get_sum(r) - get_sum(l - 1));
    }
};

///input
int N;
i64 H[MAXN];

///solution
int L[MAXN], R[MAXN];
BIT tree;

void solution() {
    cin >> N;
    vector<i64> zip;
    for(int i = 1; i <= N; i++)
    {
        cin >> H[i];
        zip.push_back(H[i]);
    }
    
    sort(zip.begin(), zip.end());
    zip.erase(unique(zip.begin(), zip.end()), zip.end());
    for(int i = 1; i <= N; i++)
    {
        H[i] = lower_bound(zip.begin(), zip.end()) - zip.begin() + 1;
    }
    
    tree.init(N);
    for(int i = 1; i <= N; i++)
    {
        L[i] = tree.get_sum(1, H[i] - 1);
        tree.update(H[i], 1);
    }
    tree.init(N);
    for(int i = N; i > 0; i--)
    {
        R[i] = tree.get_sum(1, H[i] - 1);
        tree.update(H[i], 1);
    }
    
    i64 Ans = 0;
    for(int i = 1; i <= N; i++)
    {
        Ans += 1LL*L[i]*R[i];
    }
    
    cout << Ans;
}

int main() {
    if(fopen(FILE".inp","r")) {
        freopen(FILE".inp","r",stdin);
        freopen(FILE".out","w",stdout);
    }
    cin.tie(nullptr) -> ios_base::sync_with_stdio(false);
    
    solution();
    
    return 0;
}

Compilation message

Mountains.cpp: In function 'void solution()':
Mountains.cpp:53:50: error: no matching function for call to 'lower_bound(std::vector<long long int>::iterator, std::vector<long long int>::iterator)'
   53 |         H[i] = lower_bound(zip.begin(), zip.end()) - zip.begin() + 1;
      |                                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Mountains.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:1350:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1350 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_algobase.h:1350:5: note:   template argument deduction/substitution failed:
Mountains.cpp:53:50: note:   candidate expects 3 arguments, 2 provided
   53 |         H[i] = lower_bound(zip.begin(), zip.end()) - zip.begin() + 1;
      |                                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Mountains.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:2031:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2031 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:2031:5: note:   template argument deduction/substitution failed:
Mountains.cpp:53:50: note:   candidate expects 4 arguments, 2 provided
   53 |         H[i] = lower_bound(zip.begin(), zip.end()) - zip.begin() + 1;
      |                                                  ^
Mountains.cpp: In function 'int main()':
Mountains.cpp:79:18: error: expected primary-expression before string constant
   79 |     if(fopen(FILE".inp","r")) {
      |                  ^~~~~~
Mountains.cpp:80:21: error: expected primary-expression before string constant
   80 |         freopen(FILE".inp","r",stdin);
      |                     ^~~~~~
Mountains.cpp:81:21: error: expected primary-expression before string constant
   81 |         freopen(FILE".out","w",stdout);
      |                     ^~~~~~