QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#665615#5540. City Hallkai824#Compile Error//C++203.2kb2024-10-22 14:26:112024-10-22 14:26:23

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 14:26:23]
  • 评测
  • [2024-10-22 14:26:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define eb emplace_back
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
#define f first
#define s second
#define rep(i,a,b) for(int i=a;i<(b);i++)

const int mxn=1e5+5;

vector<int> adjl[mxn];
int alt[mxn];
int distS[mxn];
int distT[mxn];

vector<pair<long double, pii> > cht;//x-intersect with prev pt, (m,c)
long double intersect(pii a,pii b){
  long double x=a.s-b.s;
  long double y=b.f-a.f;
  return x/y;
}
void make_lines(vector<pii> &lines){
  cht.clear();
  for(pii line:lines){
    //cerr<<line.f<<' '<<line.s<<" to add \n";
    if(cht.size()==0){
      cht.eb(-1e15,line);
      //cerr<<"Line 30 case\n";
      continue;
    }
    //remove unnecessary lines
    while(lines.size()>=2 && intersect(line,cht[cht.size()-2].s)<cht.back().f){
      //cerr<<"Line 35\n";
      lines.pop_back();
    }
    cht.eb(intersect(cht.back().s,line),line);
    //cerr<<"Line 39 "<<cht.back().f<<'\n';
  }
}
int query(int x){
  int it = upper_bound(cht.begin(),cht.end(),mp(x,mp(-1e17,-1e17)))-cht.begin()-1;
  pii line=cht[it].s;
  return line.f*x + line.s;
}

int check(int x){
  // //naive
  // int ans=1e17;
  // for(int nd:adjl[x]){
  //   for(int nd2:adjl[x]){
  //     ans=min(ans,2*(distS[nd]+distT[nd2])+((alt[nd]-alt[nd2])*(alt[nd]-alt[nd2])));
  //   }
  // }
  // return ans;

  //cht:
  int ans=1e17;
  vector<pii> lines;
  for(int nd:adjl[x]){
    lines.eb(-2*alt[nd],alt[nd]*alt[nd]+2*distS[nd]);
  }
  sort(lines.begin(),lines.end(),greater<pii>());
  make_lines(lines);
  for(int nd:adjl[x]){
    ans=min(ans,alt[nd]*alt[nd]+2*distT[nd]+query(alt[nd]));
  }
  return ans;
}

int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int n,m,s,t;
  cin>>n>>m>>s>>t;
  for(int i=1;i<=n;i++){
    cin>>alt[i];
    distS[i]=distT[i]=1e17;
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    adjl[a].pb(b);
    adjl[b].pb(a);
  }
  priority_queue<pii,vector<pii>,greater<pii> > dijk;
  //dijk from s
  dijk.emplace(0,s);
  distS[s]=0;
  while(!dijk.empty()){
    int nd=dijk.top().s,dd=dijk.top().f;
    dijk.pop();
    if(distS[nd]<dd)continue;
    for(int x:adjl[nd]){
      if(distS[x]>distS[nd]+((alt[x]-alt[nd])*(alt[x]-alt[nd]))){
        distS[x]=distS[nd]+((alt[x]-alt[nd])*(alt[x]-alt[nd]));
        dijk.emplace(distS[x],x);
      }
    }
  }
  //dijk from t
  dijk.emplace(0,t);
  distT[t]=0;
  while(!dijk.empty()){
    int nd=dijk.top().s,dd=dijk.top().f;
    dijk.pop();
    if(distT[nd]<dd)continue;
    for(int x:adjl[nd]){
      if(distT[x]>distT[nd]+((alt[x]-alt[nd])*(alt[x]-alt[nd]))){
        distT[x]=distT[nd]+((alt[x]-alt[nd])*(alt[x]-alt[nd]));
        dijk.emplace(distT[x],x);
      }
    }
  }

  int ans=distS[t];
  for(int i=1;i<=n;i++){
    ans=min(ans,check(i));
  }
  for(int i:adjl[s]){
    ans=min(ans,distT[i]);
  }
  for(int i:adjl[t]){
    ans=min(ans,distS[i]);
  }
  cout<<fixed<<setprecision(6);
  cout<<ans/2.0;
}
/*
5 6 1 3
5 100 8 2 10
1 2
2 3
2 5
1 4
4 5
3 5

5 5 1 5
1 2 10 10 4
1 2
2 3
2 4
3 5
4 5

5 4 1 5
8 8 8 8 100
1 2
2 3
3 4
4 5
*/

详细

In file included from /usr/include/c++/13/bits/stl_algobase.h:71,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = const std::pair<long long int, std::pair<double, double> >; _Iterator = __gnu_cxx::__normal_iterator<std::pair<long double, std::pair<long long int, long long int> >*, std::vector<std::pair<long double, std::pair<long long int, long long int> > > >]’:
/usr/include/c++/13/bits/stl_algo.h:2035:14:   required from ‘constexpr _ForwardIterator std::__upper_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<pair<long double, pair<long long int, long long int> >*, vector<pair<long double, pair<long long int, long long int> > > >; _Tp = pair<long long int, pair<double, double> >; _Compare = __gnu_cxx::__ops::_Val_less_iter]’
/usr/include/c++/13/bits/stl_algo.h:2070:32:   required from ‘constexpr _FIter std::upper_bound(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<pair<long double, pair<long long int, long long int> >*, vector<pair<long double, pair<long long int, long long int> > > >; _Tp = pair<long long int, pair<double, double> >]’
answer.code:44:23:   required from here
/usr/include/c++/13/bits/predefined_ops.h:98:22: error: no match for ‘operator<’ (operand types are ‘const std::pair<long long int, std::pair<double, double> >’ and ‘std::pair<long double, std::pair<long long int, long long int> >’)
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/bits/stl_algobase.h:67:
/usr/include/c++/13/bits/stl_iterator.h:1189:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> __gnu_cxx::operator<=>(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)’ (reversed)
 1189 |     operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1189:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   ‘std::pair<long double, std::pair<long long int, long long int> >’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:181:
/usr/include/c++/13/bits/regex.h:1288:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Alloc> auto std::__cxx11::operator<=>(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)’ (reversed)
 1288 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1288:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   ‘std::pair<long double, std::pair<long long int, long long int> >’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/regex.h:1456:5: note: candidate: ‘template<class _Bi_iter> auto std::__cxx11::operator<=>(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)’ (reversed)
 1456 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1456:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   ‘std::pair<long double, std::pair<long long int, long long int> >’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/regex.h:1629:5: note: candidate: ‘template<class _Bi_iter> auto std::__cxx11::operator<=>(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)’ (reversed)
 1629 |     operator<=>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1629:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   ‘std::pair<long double, std::pair<long long int, long long int> >’ is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:583:5: note: candidate: ‘template<class _IteratorL, class _IteratorR>  requires  three_way_comparable_with<_IteratorR, _IteratorL, std::partial_ordering> constexpr std::compare_three_w...