제출 #1124064

#제출 시각아이디문제언어결과실행 시간메모리
1124064math_rabbit_1028트리 (IOI24_tree)C++20
컴파일 에러
0 ms0 KiB
#include "tree.h" #include <queue> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; int n; int par[202020]; vector<int> child[202020]; ll w[202020]; void init(vector<int> P, vector<int> W) { n = (int)P.size(); for (int i = 0; i < n; i++) { par[i] = P[i]; child[par[i]].push_back(i); } for (int i = 0; i < n; i++) w[i] = W[i]; } ll dp[202020], sum[202020]; typedef priority_queue<pll, vector<pll>, greater<pll>> pq; pq solve(int v, ll L, ll R) { pq plus; if (child[v].size() == 0) { dp[v] += L * w[v]; sum[v] = L; return plus; } for (int u : child[v]) { pq t = solve(u, L, R); if (plus.size() < t.size()) swap(plus, t); while (!t.empty()) { plus.push(t.top()); t.pop(); } dp[v] += dp[u]; sum[v] += sum[u]; } while (!t.empty() && sum[v] > R) { pll t = plus.top(); plus.pop(); if (sum[v] - R < t.second) { dp[v] += (sum[v] - R) * t.first; sum[v] -= (sum[v] - R); plus.push({t.first, t.second - (sum[v] - R)}); } else { dp[v] += t.second * t.first; sum[v] -= t.second; } } if (sum[v] > R) { dp[v] += (sum[v] - R) * w[v]; sum[v] -= (sum[v] - R); } plus.push({w[v], sum[v]-L}); return plus; } long long query(int L, int R) { for (int i = 0; i < n; i++) sum[i] = dp[i] = 0; solve(0, L, R); return dp[0]; }

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

tree.cpp: In function 'pq solve(int, ll, ll)':
tree.cpp:42:13: error: 't' was not declared in this scope
   42 |     while (!t.empty() && sum[v] > R) {
      |             ^
tree.cpp:48:22: error: no matching function for call to 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::push(<brace-enclosed initializer list>)'
   48 |             plus.push({t.first, t.second - (sum[v] - R)});
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/queue:64,
                 from tree.cpp:2:
/usr/include/c++/11/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int> >; _Compare = std::greater<std::pair<long long int, long long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long long int, long long int>]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int> >; _Compare = std::greater<std::pair<long long int, long long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long long int, long long int>]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~