답안 #1109895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109895 2024-11-08T02:57:58 Z Trisanu_Das 나일강 (IOI24_nile) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int MAXN = 1e5 + 5;

int max_val[MAXN] = {0};
int size[MAXN] = {0};
int parent[MAXN] = {0};
int value[MAXN][2] = {0};

int find(int r) {
    return parent[r] == r ? r : parent[r] = find(parent[r]);
}

int calculate(int u) {
    if (size[u] % 2 == 0) return 0;
    return max(value[u][u & 1], max_val[u]);
}

vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    int n = W.size();
    int m = E.size();
    vector<pair<int, pii>> v;

    for (int i = 0; i < n; i++) {
        v.push_back({W[i], {A[i], B[i]}});
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < n; i++) {
        W[i] = v[i].first;
        A[i] = v[i].second.first;
        B[i] = v[i].second.second;
    }

    vector<pii> q1, q2;
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        size[i] = 1;
        value[i][i & 1] = B[i] - A[i];
        max_val[i] = -2e9;
        value[i][(i + 1) & 1] = -2e9;
    }

    for (int i = 0; i < n - 1; i++) {
        q1.push_back({W[i + 1] - W[i], i});
    }
    for (int i = 1; i < n - 1; i++) {
        q2.push_back({W[i + 1] - W[i - 1], i});
    }
    sort(q1.begin(), q1.end());
    sort(q2.begin(), q2.end());

    ll result_sum = 0;
    for (int i = 0; i < n; i++) {
        result_sum += A[i];
    }

    vector<pii> queries;
    for (int i = 0; i < m; i++) {
        queries.push_back({E[i], i});
    }
    sort(queries.begin(), queries.end());
    int id1 = 0, id2 = 0;
    vector<ll> res(m, 0);
    for (auto [d, i] : queries) {
        while (id1 < q1.size() && q1[id1].first <= d) {
            int u = find(q1[id1].second), v = find(q1[id1].second + 1);
            result_sum += calculate(u) + calculate(v);
            parent[u] = v;
            size[v] += size[u];
            value[v][0] = max(value[v][0], value[u][0]);
            value[v][1] = max(value[v][1], value[u][1]);
            max_val[v] = max(max_val[v], max_val[u]);
            result_sum -= calculate(v);
            id1++;
        }
        while (id2 < q2.size() && q2[id2].first <= d) {
            int u = find(q2[id2].second);
            result_sum += calculate(u);
            max_val[u] = max(max_val[u], B[q2[id2].second] - A[q2[id2].second]);
            result_sum -= calculate(u);
            id2++;
        }
        res[i] = result_sum;
    }
    return res;
}

Compilation message

nile.cpp: In function 'int calculate(int)':
nile.cpp:19:9: error: reference to 'size' is ambiguous
   19 |     if (size[u] % 2 == 0) return 0;
      |         ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from nile.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
nile.cpp:10:5: note:                 'int size [100005]'
   10 | int size[MAXN] = {0};
      |     ^~~~
nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:42:9: error: reference to 'size' is ambiguous
   42 |         size[i] = 1;
      |         ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from nile.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
nile.cpp:10:5: note:                 'int size [100005]'
   10 | int size[MAXN] = {0};
      |     ^~~~
nile.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         while (id1 < q1.size() && q1[id1].first <= d) {
      |                ~~~~^~~~~~~~~~~
nile.cpp:74:13: error: reference to 'size' is ambiguous
   74 |             size[v] += size[u];
      |             ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from nile.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
nile.cpp:10:5: note:                 'int size [100005]'
   10 | int size[MAXN] = {0};
      |     ^~~~
nile.cpp:74:24: error: reference to 'size' is ambiguous
   74 |             size[v] += size[u];
      |                        ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from nile.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
nile.cpp:10:5: note:                 'int size [100005]'
   10 | int size[MAXN] = {0};
      |     ^~~~
nile.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         while (id2 < q2.size() && q2[id2].first <= d) {
      |                ~~~~^~~~~~~~~~~