Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 400010;
const int INF = 2147483600;

int N;
const double Pi = acos(-1);
const double Ti = 20.0-5.0*Pi;
const double Ci = 10.0*Pi-20.0;

int x1,y1,x2,y2;
int dx[MAXN+1],dy[MAXN+1];
struct data{
	int x,y,opr;
}p[MAXN+1],to[MAXN+1];
bool cmp(data a,data b){
	if(a.x!=b.x) return a.x<b.x;
	return a.y<b.y;
} double ret=-INF; int f[MAXN+1];
int c[MAXN+1],cx,cy; int d[MAXN+1];

inline int lowbit(int x){return x&(-x);}
inline void Add(int k,int x){
	for(;k<=cy;k+=lowbit(k)) c[k]=max(c[k],x);
} inline int Query(int k){
	int ret=0; for(;k;k-=lowbit(k)) ret=max(ret,c[k]); return ret;
} int topx; double zei=INF;

inline void solve(){
	sort(p+1,p+N+1,cmp); memset(c,0,sizeof(c));
	int tmp=0; double num=0,rg=0;
	if(y1<y2){
		topx=0; data ng;
		for(int i=1;i<=N;i++){
			if(p[i].x>=x1&&p[i].x<=x2&&p[i].y==y2) ng=p[i],num=Ci,rg+=Ci;
			if(p[i].y>=y1&&p[i].y<=y2&&p[i].x==x1) rg+=Ci; 
			if(p[i].x>=x1&&p[i].x<=x2&&p[i].y<=y2&&p[i].y>=y1) to[++topx]=p[i]; 
		} int j=1,l=0;
		for(int i=x1;i<=x2;i++){
			int now=j; if(i==ng.x) num=0;
			while(j<=topx&&to[j].x==i) {
				f[j]=max(Query(to[j].y)+1,1);
				ret=max(ret,1.0*f[j]*Ti-num);++j;
			} for(int k=now;k<j;k++) Add(to[k].y,f[k]);
		}
	} else{
		topx=0; data ng;
		for(int i=1;i<=N;i++){
			if(p[i].x>=x1&&p[i].x<=x2&&p[i].y==y1) ng=p[i],num=Ci,rg+=Ci;
			if(p[i].y>=y2&&p[i].y<=y1&&p[i].x==x1) rg+=Ci; 
			if(p[i].x>=x1&&p[i].x<=x2&&p[i].y<=y1&&p[i].y>=y2) to[++topx]=p[i];
		} int j=1,l=0;
		for(int i=x1;i<=x2;i++){
			int now=j; if(i==ng.x) num=0;
			while(j<=topx&&to[j].x==i) {
				f[j]=max(Query(to[j].y)+1,1);
				ret=max(ret,f[j]*Ti-num);++j;
			} for(int k=now;k<j;k++) Add(cy-to[k].y+1,f[k]);
		}
	} zei=min(zei,rg);
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	x1=read(),y1=read(),x2=read(),y2=read();
	N=read(); for(int i=1;i<=N;i++){
		p[i].x=read(),p[i].y=read(); p[i].opr=1;
		c[++cx]=p[i].x,d[++cy]=p[i].y;
	} c[++cx]=x1; c[++cx]=x2; d[++cy]=y1; d[++cy]=y2;
	if(x1==x2||y1==y2){
		if(x1>x2) swap(x1,x2); if(y1>y2) swap(y1,y2); zei=0;
		for(int i=1;i<=N;i++){
			if(p[i].x>=x1&&p[i].x<=x2&&p[i].y>=y1&&p[i].y<=y2) zei+=Ci;
		} printf("%.11lf\n",abs(x1-x2)*100+abs(y1-y2)*100+zei);
		return 0;
	}
	sort(c+1,c+cx+1); sort(d+1,d+cy+1);
	cx=unique(c+1,c+cx+1)-c-1,cy=unique(d+1,d+cy+1)-d-1;
	for(int i=1;i<=N;i++){
		p[i].x=lower_bound(c+1,c+cx+1,p[i].x)-c;
		p[i].y=lower_bound(d+1,d+cy+1,p[i].y)-d;
	}
	x1=lower_bound(c+1,c+cx+1,x1)-c; y1=lower_bound(d+1,d+cy+1,y1)-d;
	x2=lower_bound(c+1,c+cx+1,x2)-c; y2=lower_bound(d+1,d+cy+1,y2)-d;
	double ans=abs(d[y1]-d[y2])*100+abs(c[x1]-c[x2])*100;
	if(x1>x2) swap(x1,x2),swap(y1,y2); solve();
	swap(x1,y1); swap(x2,y2); if(x1>x2) swap(x1,x2); 
	for(int i=1;i<=N;i++) swap(p[i].x,p[i].y); swap(cy,cx);
	solve(); printf("%.11lf\n",min(ans-ret,zei+ans));
}




Compiler output:
a.cc:20:19: error: 'acos' was not declared in this scope
   20 | const double Pi = acos(-1);
      |                   ^~~~
a.cc:24:8: warning: built-in function 'y1' declared as non-function [-Wbuiltin-declaration-mismatch]
   24 | int x1,y1,x2,y2;
      |        ^~
a.cc:29:10: error: reference to 'data' is ambiguous
   29 | bool cmp(data a,data b){
      |          ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:26:8: note:                 'struct data'
   26 | struct data{
      |        ^~~~
a.cc:29:17: error: reference to 'data' is ambiguous
   29 | bool cmp(data a,data b){
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:26:8: note:                 'struct data'
   26 | struct data{
      |        ^~~~
a.cc:29:23: error: expression list treated as compound expression in initializer [-fpermissive]
   29 | bool cmp(data a,data b){
      |                       ^
a.cc: In function 'void solve()':
a.cc:46:25: error: reference to 'data' is ambiguous
   46 |                 topx=0; data ng;
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:26:8: note:                 'struct data'
   26 | struct data{
      |        ^~~~
a.cc:48:64: error: 'ng' was not declared in this scope; did you mean 'rg'?
   48 |                         if(p[i].x>=x1&&p[i].x<=x2&&p[i].y==y2) ng=p[i],num=Ci,rg+=Ci;
      |                                                                ^~
      |                                                                rg
a.cc:53:42: error: 'ng' was not declared in this scope; did you mean 'rg'?
   53 |                         int now=j; if(i==ng.x) num=0;
      |                                          ^~
      |                                          rg
a.cc:60:25: error: reference to 'data' is ambiguous
   60 |                 topx=0; data ng;
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:26:8: note:                 'struct data'
   26 | struct data{
      |        ^~~~
a.cc:62:64: error: 'ng' was not declared in this scope; did you mean 'rg'?
   62 |                         if(p[i].x>=x1&&p[i].x<=x2&&p[i].y==y1) ng=p[i],num=Ci,rg+=Ci;
      |                                                                ^~
      |                                                                rg
a.cc:67:42: error: 'ng' was not declared in this scope; did you mean 'rg'?
   67 |                         int now=j; if(i==ng.x) num=0;
      |                                          ^~
      |                                          rg
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = data*; _Iterator2 = data*; _Compare = bool]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = data*; _Compare = bool]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:43:6:   required from here
   43 |         sort(p+1,p+N+1,cmp); memset(c,0,sizeof(c));
      |         ~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: expression cannot be used as a function
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = data; _Iterator = data*; _Compare = bool]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool>]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare =