Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef int T_CC;
const int CC_MAX = 200010;

class CC{
	T_CC unzip[CC_MAX];
	map<T_CC , int> zip;
	int size;
	
public:
	
	void dft(){
		size = 0;
		zip.clear();
	}
	
	int insert(T_CC a){
		if(size == CC_MAX) return -1;
		zip[a] = size;
		unzip[size] = a;
		return ++size;
	}
	
	int arrange(){
		int a = 0;
		for(map<T_CC , int>::iterator it = zip.begin() ; it != zip.end() ; ++it){
			(*it).second = a;
			unzip[a] = (*it).first;
			++a;
		}
		size = a;
		return size;
	}
	
	int get_size(){
		return size;
	}
	
	int code(T_CC a){
		map<T_CC , int>::iterator it = zip.find(a);
		return it != zip.end() ? (*it).second : -1;
	}
	
	T_CC decode(int a){
		if(a >= size) return 0;
		return unzip[a];
	}
} cc;

const int ST_MAX = (1 << 18);

template <class T> class ST{
	T x[ST_MAX * 2];
	
	T eval(T a , T b){
		return max(a,b);
	}
	
	void ren(int a){
		x[a] = eval(x[2 * a] , x[2 * a + 1]);
		if(a > 0) ren(a / 2);
	}
	
	T read_ST(int a , int b , int e , int s , int f){
		if(e <= s || f <= b) return 0;
		if(s <= b && e <= f) return x[a];
		return eval(read_ST(2 * a , b , (b + e) / 2 , s , f) , read_ST(2 * a + 1 , (b + e) / 2 , e , s , f));
	}
	
public:
	
	void dft(){
		fill(x,x+ST_MAX*2,0);
	}
	
	void put(int a , T b){
		if(x[a + ST_MAX] >= b) return;
		x[a + ST_MAX] = b;
		ren((a + ST_MAX) / 2);
	}
	
	T get(int s , int f){
		return read_ST(1 , 0 , ST_MAX , s , f);
	}
};

ST<int> st;
const int MC = 200010;
const int H = 1e8 - 1;
int x1,y1,x2,y2;
int N;
int X[MC] , Y[MC];
int s[MC];
const double PI = 3.141592653589793;

int main(){
	scanf("%d%d%d%d" , &x1 , &y1 , &x2 , &y2);
	if(x1 > x2){
		swap(x1,x2);
		swap(y1,y2);
	}
	scanf("%d" , &N);
	repp(i,0,N){
		scanf("%d%d" , X + i , Y + i);
		if(y1 > y2) Y[i] = H - Y[i];
		if(y1 == y2) swap(X[i] , Y[i]);
		s[i] = i;
		cc.insert(Y[i]);
	}
	if(y1 > y2){
		y1 = H - y1;
		y2 = H - y2;
	}
	if(y1 == y2){
		swap(x1,y1);
		swap(x2,y2);
	}
	if(x1 == x2){
		bool b = 0;
		repp(i,0,N) b = (b || (X[i] == x1 && y1 < Y[i] && Y[i] < y2));
		printf("%.12f\n" , b ? (y2-y1)*100.0 - 20.0 + PI * 10 : ((x2-x1) * 100.0));
		return 0;
	}
	sort(s,s+N,[&](const int p , const int q){return X[p] < X[q];});
	int ans0 = 0 , ans1 = 0;
	cc.insert(y1);
	cc.insert(y2);
	cc.arrange();
	bool b1 = 0 , b2 = 0;
	for(int i = 0 ; i < N && X[i] < x2 ; ++i){
		if(X[s[i]] < x1 || Y[s[i]] < y1 || Y[s[i]] > y2) continue;
		int co = cc.code(Y[s[i]]);
		int z = st.get(0,co);
		if(Y[s[i]] == y2){
			ans1 = max(ans1,z);
			b1 = 1;
		} else if(X[s[i]] == x2){
			ans1 = max(ans1,z);
			b2 = 1;
		} else {
			st.put(co,z+1);
		}
	}
	ans0 = st.get(0,cc.code(y2));
	double ans = (x2-x1+y2-y1) * 100;
	double cq = 5 * PI;
	printf("%.12f\n" , min(ans-ans0*(20.0-cq) , ans-ans1*(20.0-cq)-20.0+2*cq));
	return 0;
}


Compiler output:
a.cc:104:8: error: 'int y1' redeclared as different kind of entity
  104 | int x1,y1,x2,y2;
      |        ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:114:21: error: no matching function for call to 'swap(double (&)(double) noexcept, int&)'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:77:
/usr/include/c++/14/any:430:15: note: candidate: 'void std::swap(any&, any&)' (near match)
  430 |   inline void swap(any& __x, any& __y) noexcept { __x.swap(__y); }
      |               ^~~~
/usr/include/c++/14/any:430:15: note:   conversion of argument 2 would be ill-formed:
a.cc:114:25: error: cannot bind non-const lvalue reference of type 'std::any&' to an rvalue of type 'std::any'
  114 |                 swap(y1,y2);
      |                         ^~
/usr/include/c++/14/any:191:7: note:   after user-defined conversion: 'std::any::any(_Tp&&) [with _Tp = int&; _VTp = int; _Mgr = _Manager_internal<int>; typename std::enable_if<(is_copy_constructible_v<_VTp> && (! __is_in_place_type_v<_VTp>)), bool>::type <anonymous> = true]'
  191 |       any(_Tp&& __value)
      |       ^~~
In file included from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/stdexcept:38,
                 from /usr/include/c++/14/system_error:43,
                 from /usr/include/c++/14/bits/ios_base.h:46,
                 from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'double(double) noexcept' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/future:51,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:176:
/usr/include/c++/14/bits/std_thread.h:328:3: note: candidate: 'void std::swap(thread&, thread&)'
  328 |   swap(thread& __x, thread& __y) noexcept
      |   ^~~~
/usr/include/c++/14/bits/std_thread.h:328:16: note:   no known conversion for argument 1 from 'double(double) noexcept' to 'std::thread&'
  328 |   swap(thread& __x, thread& __y) noexcept
      |        ~~~~~~~~^~~
In file included from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/sstream:1204:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringbuf<_CharT, _Traits, _Alloc>&, basic_stringbuf<_CharT, _Traits, _Alloc>&)'
 1204 |     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1204:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/sstream:1212:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_istringstream<_CharT, _Traits, _Allocator>&, basic_istringstream<_CharT, _Traits, _Allocator>&)'
 1212 |     swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1212:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/sstream:1219:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_ostringstream<_CharT, _Traits, _Allocator>&, basic_ostringstream<_CharT, _Traits, _Allocator>&)'
 1219 |     swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1219:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/sstream:1226:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringstream<_CharT, _Traits, _Allocator>&, basic_stringstream<_CharT, _Traits, _Allocator>&)'
 1226 |     swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1226:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:896:5: note: candidate: 'template<class _Ch_type, class _Rx_traits> void std::__cxx11::swap(basic_regex<_Ch_type, _Rx_traits>&, basic_regex<_Ch_type, _Rx_traits>&)'
  896 |     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/regex.h:896:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx11::basic_regex<_Ch_type, _Rx_traits>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/bits/regex.h:2230:5: note: candidate: 'template<class _Bi_iter, class _Alloc> void std::__cxx11::swap(match_results<_BiIter, _Alloc>&, match_results<_BiIter, _Alloc>&)'
 2230 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/regex.h:2230:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx11::match_results<_BiIter, _Alloc>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   deduced conflicting types for parameter '_Tp' ('double(double) noexcept' and 'int')
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types '_Tp [_Nm]' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::pair<_T1, _T2>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::pair<_T1, _T2>' and 'double(double) noexcept'
  114 |                 swap(y1,y2);
      |                 ~~~~^~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:4039:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(__cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4039 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/basic_string.h:4039:5: note:   template argument deduction/substitution failed:
a.cc:114:21: note:   mismatched types 'std::__cxx1