제출 #92219

#제출 시각아이디문제언어결과실행 시간메모리
92219moonrabbit2Fireworks (APIO16_fireworks)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; const ll N=3e5+5; int n,m,p[N],c[N]; struct data { ll a,b; priority_queue<ll> *pq; data operator +(data k){ data res; tie(res.a,res.b)=P(a+k.a,b+k.b); if(pq->size()>=k.pq->size()){ res.pq=pq; while(k.pq->size()){ res.pq->push(k.pq->top()); k.pq->pop(); } } else{ res.pq=k.pq; while(pq->size()){ res.pq->push(pq->top()); pq->pop(); } } return res; } }; data a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; for(int i=2;i<=n+m;i++) cin>>p[i]>>c[i]; for(int i=n+m;i>=1;i--){ a[i].a=a[i].b=0; a[i].pq=new priority_queue<ll>; } for(int i=n+m;i>n;i--){ a[i].a=1; a[i].b=-c[i]; a[i].pq->push(c[i]); a[i].pq->push(c[i]); a[p[i]]=a[p[i]]+a[i]; } for(int i=n;i>=2;i--){ while(a[i].a>1){ a[i].a--; a[i].b+=a[i].pq->top(); a[i].pq->pop(); } ll t1=a[i].pq->top(); a[i].pq->pop(); ll t2=a[i].pq->top(); a[i].pq->pop(); a[i].pq->push(t1+c[i]); a[i].pq->push(t2+c[i]); a[i].b-=c[i]; a[p[i]]=a[p[i]]+a[i]; } while(a[1].a>0){ a[1].a--; a[1].b+=a[1].pq->top(); a[1].pq->pop(); } cout<<a[1].b; return 0; }

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

fireworks.cpp:31:1: error: reference to 'data' is ambiguous
 data a[N];
 ^~~~
fireworks.cpp:7:8: note: candidates are: struct data
 struct data
        ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from fireworks.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:39:9: error: 'a' was not declared in this scope
         a[i].a=a[i].b=0;
         ^
fireworks.cpp:43:9: error: 'a' was not declared in this scope
         a[i].a=1; a[i].b=-c[i];
         ^
fireworks.cpp:48:15: error: 'a' was not declared in this scope
         while(a[i].a>1){
               ^
fireworks.cpp:53:15: error: 'a' was not declared in this scope
         ll t1=a[i].pq->top();
               ^
fireworks.cpp:61:11: error: 'a' was not declared in this scope
     while(a[1].a>0){
           ^
fireworks.cpp:66:11: error: 'a' was not declared in this scope
     cout<<a[1].b;
           ^