제출 #1276229

#제출 시각아이디문제언어결과실행 시간메모리
1276229nanaseyuzukiMountains (NOI20_mountains)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
// Author: Kazuki_Will_Win_VOI_8703
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;

const int mn = 3e5 + 5, inf = 1e9;

int n, a[mn];

int st[4 * mn];
vector <int> pos[mn];

void update(int id, int l, int r, int pos){
    if(l > pos || r < pos) return;
    if(l == r){
        st[id] ++;
        return;
    }
    int mid = (l + r) >> 1;
    update(2 * id, l, mid, pos);
    update(2 * id + 1, mid + 1, r, pos);
    st[id] = st[2 * id] + st[2 * id + 1];
}

int get(int id, int l, int r, int u, int v){
    if(l > v || r < u) return 0;
    if(l >= u && r <= v) return st[id];
    int mid = (l + r) >> 1;
    return get(2 * id, l, mid, u, v) + get(2 * id + 1, mid + 1, r, u, v);
}

void solve(){
    cin >> n;
    int res = 0;
    vector <int> reina;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        reina.push_back(a[i]);
    }
    all(reina); unique(reina);
    for(int i = 1; i <= n; i++){
        a[i] = lower_bound(reina.begin(), reina.end(), a[i]) - reina.begin() + 1;
        pos[a[i]].push_back(i);
    }
    for(int p = 1; p <= reina.size(); p++){
        for(auto i : pos[p]) res += get(1, 1, n, 1, i) * get(1, 1, n, i, n);
        for(auto i : pos[p]) update(1, 1, n, i);
    }
    cout << res << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

Mountains.cpp: In function 'void solve()':
Mountains.cpp:7:23: warning: ignoring return value of 'constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::begin() [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator]', declared with attribute 'nodiscard' [-Wunused-result]
    7 | #define all(a) a.begin(), a.end()
      |                       ^
Mountains.cpp:44:5: note: in expansion of macro 'all'
   44 |     all(reina); unique(reina);
      |     ^~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from Mountains.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:873:7: note: declared here
  873 |       begin() _GLIBCXX_NOEXCEPT
      |       ^~~~~
Mountains.cpp:44:23: error: no matching function for call to 'unique(std::vector<long long int>&)'
   44 |     all(reina); unique(reina);
      |                 ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51:
/usr/include/c++/13/bits/stl_algo.h:939:5: note: candidate: 'template<class _FIter> constexpr _FIter std::unique(_FIter, _FIter)'
  939 |     unique(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~
/usr/include/c++/13/bits/stl_algo.h:939:5: note:   template argument deduction/substitution failed:
Mountains.cpp:44:23: note:   candidate expects 2 arguments, 1 provided
   44 |     all(reina); unique(reina);
      |                 ~~~~~~^~~~~~~
/usr/include/c++/13/bits/stl_algo.h:970:5: note: candidate: 'template<class _FIter, class _BinaryPredicate> constexpr _FIter std::unique(_FIter, _FIter, _BinaryPredicate)'
  970 |     unique(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/13/bits/stl_algo.h:970:5: note:   template argument deduction/substitution failed:
Mountains.cpp:44:23: note:   candidate expects 3 arguments, 1 provided
   44 |     all(reina); unique(reina);
      |                 ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/algorithm:73:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:230:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::unique(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _BinaryPredicate)'
  230 | unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
      | ^~~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:230:1: note:   template argument deduction/substitution failed:
Mountains.cpp:44:23: note:   candidate expects 4 arguments, 1 provided
   44 |     all(reina); unique(reina);
      |                 ~~~~~~^~~~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:234:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::unique(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator)'
  234 | unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:234:1: note:   template argument deduction/substitution failed:
Mountains.cpp:44:23: note:   candidate expects 3 arguments, 1 provided
   44 |     all(reina); unique(reina);
      |                 ~~~~~~^~~~~~~