답안 #323862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
323862 2020-11-15T05:42:40 Z wind_reaper Pilot (NOI19_pilot) C++17
컴파일 오류
0 ms 0 KB
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;
using namespace __gnu_pbds;
using namespace chrono;

#define pb push_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

// const int INF = 1e9;
const ll INF = 1e18;
const ll mod = 1000000007;
// const ll mod = 998244353;
struct DSU{
    vl e;
    vector<bool> active;
    ll ans; 
    void init(int n){
        e = vi(n, -1); 
        ans = 0;
        active = vector<bool>(n, 0);
    }

    int get(int x){
        return (e[x] < 0 ? x : e[x] = get(e[x])); 
    }

    bool same_set(int x, int y){
        return get(x) == get(y);
    }

    ll sz(int x){
        return -e[get(x)];
    }

    ll fx(int x){
        return 1LL*sz(x)*(sz(x) + 1)/2;
    }
    bool unite(int x, int y){
        x = get(x), y = get(y);
        if(!active[x]){
            active[x] = 1;
            ans += fx(x);
        }
        if(!active[y] || x == y) return false;

        if(e[x] > e[y])
            swap(x, y);

        ans -= fx(x) + fx(y);
        e[x] += e[y];
        e[y] = x;
        ans += fx(x); 

        return true;
    }

};  
void solve(int tc){
    int n, q;
    cin >> n >> q;

    vpi a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i].f;
        a[i].s = i; 
    }

    sort(all(a)); 

    vpi query(q);
    for(int i = 0; i < q; i++){
        cin >> query[i].f;
        query[i].s = i;
    }

    sort(all(query)); 

    vl ans(q); 

    DSU s;
    s.init(n);
    int j = 0;
    for(const auto&[plane, idx] : query){
        while(j < n && a[j].first <= plane){
            int cur = a[j].second;
            int prev = cur - 1; 
            int next = cur + 1;
            if(prev >= 0) s.unite(cur, prev);
            if(next < n) s.unite(cur, next);
            j++;
        }

        ans[idx] = s.ans; 
    }

    for(auto& x : ans)
        cout << x << ' ';
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    #ifdef LOCAL
        auto begin = high_resolution_clock::now();
    #endif

    int tc = 1;
    // cin >> tc; 
    for (int t = 0; t < tc; t++) solve(t);
    
    #ifdef LOCAL 
        auto end = high_resolution_clock::now();
        cout << fixed << setprecision(4) << "Execution Time: " << duration_cast<duration<double>>(end - begin).count() << "seconds" << endl;
    #endif
    return 0;
}

Compilation message

pilot.cpp: In member function 'void DSU::init(int)':
pilot.cpp:46:21: error: no match for 'operator=' (operand types are 'vl' {aka 'std::vector<long long int>'} and 'vi' {aka 'std::vector<int>'})
   46 |         e = vi(n, -1);
      |                     ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pilot.cpp:3:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'vi' {aka 'std::vector<int>'} to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pilot.cpp:3:
/usr/include/c++/9/bits/stl_vector.h:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from 'vi' {aka 'std::vector<int>'} to 'std::vector<long long int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from 'vi' {aka 'std::vector<int>'} to 'std::initializer_list<long long int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~