제출 #1274961

#제출 시각아이디문제언어결과실행 시간메모리
1274961Faisal_SaqibConstruction Project 2 (JOI24_ho_t2)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long const ll N=2e5+100; ll dist[N],tmp=0; vector<pair<ll,ll>> ma[N]; ll n,m; void compute(ll s) { for(ll i=0;i<=n;i++) { dist[i]=1e18; } dist[s]=0; priority_queue<pair<ll,ll>> pq; pq.push({0,s}); while(pq.size()) { auto it=pq.top(); pq.pop(); ll x=it.second,dt=it.first; if(dist[x]!=dt)continue; for(auto y:ma[it.second]) { if(dist[y.first]>(dt+y.second)) { dist[y.first]=dt+y.second; pq.push({dt+y.second,y.first}); } } } } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> void solve() { tmp=0; cin>>n>>m; ll s,t,l,k; cin>>s>>t>>l>>k; for(ll i=0;i<m;i++) { ll a,b,c; cin>>a>>b>>c; ma[a].pb({b,c}); ma[b].pb({a,c}); } compute(s); vector<ll> cur,dist1(n+2); for(ll i=1;i<=n;i++) { cur.pb(dist[i]); dist1[i]=dist[i]; } sort(begin(cur),end(cur)); compute(t); ll ans=0,c0=0,c1=0;; vector<pair<ll,ll>> val; for(ll i=1;i<=n;i++) { // dist(s,i) + dist(j,t) + l <= k // OR // dist(s,i)+dist(i,t) <=k // OR // dist(s,j)+dist(j,t)<=k if(dist1[i]+dist[i] <=k ) { ans+=c0+c1; c1++; } else { ans+=c1; c0++; val.pb({dist1[i],i}); } // We did dist(s,i)+dist(i,t) <=k or dist(s,j)+dist(j,t) <=k unordered (i,j)=(j,i) // We need to add dist(s,i)+dist(i,t) > k and dist(s,j)+dist(j,t)>k and dist(s,i)+dist(j,t)+l<=k // p } sort(begin(val),end(val)); ordered_set tp; for(auto [kp,i]:val) { //try i to be with s // dist(j,t) <= k-l-kp ans+=tp.order_of_key(k-l-kp); // i with t // dist(s,j) <=k-l - dist(i,t) ans+=upper_bound(begin(val),end(val),{k-l-dist[i],n+1})-begin(val); tp.insert(dist[i]); } // ans/=2; cout<<ans<<endl; // sort(dist); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t=1; // cin>>t; while(t--) { solve(); } }

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

Main.cpp: In function 'void solve()':
Main.cpp:94:25: error: no matching function for call to 'upper_bound(std::vector<std::pair<long long int, long long int> >::iterator, std::vector<std::pair<long long int, long long int> >::iterator, <brace-enclosed initializer list>)'
   94 |         ans+=upper_bound(begin(val),end(val),{k-l-dist[i],n+1})-begin(val);
      |              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from Main.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:2061:5: note: candidate: 'template<class _FIter, class _Tp> constexpr _FIter std::upper_bound(_FIter, _FIter, const _Tp&)'
 2061 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:2061:5: note:   template argument deduction/substitution failed:
Main.cpp:94:25: note:   couldn't deduce template parameter '_Tp'
   94 |         ans+=upper_bound(begin(val),end(val),{k-l-dist[i],n+1})-begin(val);
      |              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:2092:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> constexpr _FIter std::upper_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2092 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:2092:5: note:   template argument deduction/substitution failed:
Main.cpp:94:25: note:   candidate expects 4 arguments, 3 provided
   94 |         ans+=upper_bound(begin(val),end(val),{k-l-dist[i],n+1})-begin(val);
      |              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~