제출 #316101

#제출 시각아이디문제언어결과실행 시간메모리
316101moonrabbit2Roller Coaster Railroad (IOI16_railroad)C++17
컴파일 에러
0 ms0 KiB
#include "railroad.h" #include <bits/stdc++.h> #define N 500005 #define x first #define y second using namespace std; typedef long long ll; typedef pair<int,int> P; struct edge{ll c;int u,v;}; int n,c,group[N],c_g,p[N],en,x; ll ans,sum[N],from[N]; vector<int> vec; vector<int> g1[N]; edge g2[N]; int fi(int x) { if(p[x]==x) return x; return p[x]=fi(p[x]); } void un(int x,int y) { x=fi(x),y=fi(y); if(x==y) return; p[y]=x; } void dfs(int curr) { group[curr]=c_g; for(auto &it : g1[curr]){ if(!group[it]) dfs(it); } } bool sortf(edge e1,edge e2){return e1.c<e2.c;} ll plan_roller_coaster(vector<int> s,vector<int> t) { n=s.size(); for(int i=0;i<n;i++){ vec.emplace_back(s[i]); vec.emplace_back(t[i]); } vec.emplace_back(1); sort(vec.begin(),vec.end()); vec.erase(unique(vec.begin(),vec.end(),vec.end())); c=vec.size(); for(int i=1;i<=n;i++) from[i]=vec[i-1]; for(int i=0;i<n;i++){ s[i]=lower_bound(vec.begin(),vec.end(),s[i])-vec.begin()+1; t[i]=lower_bound(vec.begin(),vec.end(),t[i])-vec.begin()+1; } sum[2]--; g1[c].push_back(1); for(int i=0;i<n;i++){ sum[s[i]+1]++; sum[t[i]+1]--; g1[s[i]].emplace_back(t[i]); } for(int i=2;i<=c;i++){ sum[i]+=sum[i-1]; if(sum[i]<0) g1[i-1].push_back(i); if(sum[i]>0){ g1[i].push_back(i-1); ans+=sum[i]*(from[i]-from[i-1]); } } for(int i=1;i<=c;i++){ if(group[i]) continue; c_g++; p[c_g]=c_g; dfs(i); } for(int i=2;i<=c;i++){ if(group[i-1]!=group[i]){ g2[++en]={from[i]-from[i-1],group[i-1],group[i]}; } } sort(g2+1,g2+1+en,sortf); for(int i=1;i<=en;i++){ int u=g2[i].u,v=g2[i].v; if(fi(u)==fi(v)) continue; ans+=g2[i].c; un(u,v); } return ans; }

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

In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/vector:60,
                 from railroad.h:3,
                 from railroad.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Iterator2 = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Compare = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]':
/usr/include/c++/9/bits/stl_algo.h:974:20:   required from '_ForwardIterator std::__unique(_ForwardIterator, _ForwardIterator, _BinaryPredicate) [with _ForwardIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _BinaryPredicate = __gnu_cxx::__ops::_Iter_comp_iter<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >]'
/usr/include/c++/9/bits/stl_algo.h:1036:27:   required from '_FIter std::unique(_FIter, _FIter, _BinaryPredicate) [with _FIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _BinaryPredicate = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
railroad.cpp:45:79:   required from here
/usr/include/c++/9/bits/predefined_ops.h:143:18: error: no match for call to '(__gnu_cxx::__normal_iterator<int*, std::vector<int> >) (int&, int&)'
  143 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~