Language: C++

#include<cstdio>
#include<algorithm>
#define pi 3.14159265358979343846
using namespace std;
struct N{
	int x,y;
}s,t,f[200005];
int n,start,end,opt[100001],k,opt_n,flag;
double ans;
bool comp(N a,N b){return a.x<a.y;}
int search(int h){
    int l=1,mid,r=opt_n;
    while(l<=r){
        mid=(l+r)/2;
        if(opt[mid]>=h)
            if(mid+1<=r&&opt[mid+1]>=h) l=mid+1;
            else return(mid);
        else r=mid-1; 
    }
    return r;
}
int main(){
	scanf("%d%d%d%d",&s.x,&s.y,&t.x,&t.y);
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d%d",&f[i].x,&f[i].y);
	sort(f+1,f+n+1,comp);
	//for(int i=1;i<=n;++i) printf("%d %d\n",f[i].x,f[i].y);
	if(s.x>t.x){
		int temp=s.x;
		s.x=t.x;
		t.x=temp;
	}
	if(t.y>s.y) flag=-1;
	else flag=1;
	for(int i=1;i<=n;++i){
		if(f[i].x>s.x&&(f[i-1].x<=s.x||i-1<1)&&flag*s.y>=flag*f[i].y&&flag*t.y<=flag*f[i].y) start=i;
		if(f[i].x<t.x&&(f[i+1].x>=t.x||i+1>n)&&flag*s.y>=flag*f[i].y&&flag*t.y<=flag*f[i].y) end=i;
	}
	if(start==0&&end==0&&s.x!=t.x){
		printf("%.15lf",(double)100*(t.x-s.x)+100*(-flag*(t.y-s.y)));
		return 0;
	}
	opt[1]=flag*f[start].y; opt_n=1;
	//printf("%d\n",flag);
    for(int i=start+1;i<=end;++i){
        int h=flag*f[i].y;
        if(flag*t.y-h>0) continue;
        if(h<opt[opt_n]) k=++opt_n;
        else k=search(h)+1;
        //printf("%d\n",k);
        opt[k]=h;
    }
	if(s.x==t.x){
		int cnt=0;
		for(int i=1;i<=n;++i)
			if(f[i].x==s.x)
				cnt++;
		printf("%.15lf",100*(-flag*t.y-s.y)-20*cnt+10*pi*cnt);
		return 0;
	}
	if(s.y==t.y){
		int cnt=0;
		for(int i=1;i<=n;++i)
			if(f[i].x>s.x&&f[i].x<t.x&&f[i].y==s.y)
				cnt++;
		printf("%.15lf",100*(t.x-s.x)-20*cnt+10*pi*cnt);
		return 0;
	}
    //printf("%d %d %d\n",start,end,opt_n);
    printf("%.15lf",100*(t.x-s.x)+100*(-flag*(t.y-s.y))-opt_n*20+opt_n*pi*5);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:102: error: reference to 'end' is ambiguous
   37 |                 if(f[i].x<t.x&&(f[i+1].x>=t.x||i+1>n)&&flag*s.y>=flag*f[i].y&&flag*t.y<=flag*f[i].y) end=i;
      |                                                                                                      ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:13: note:                 'int end'
    8 | int n,start,end,opt[100001],k,opt_n,flag;
      |             ^~~
a.cc:39:22: error: reference to 'end' is ambiguous
   39 |         if(start==0&&end==0&&s.x!=t.x){
      |                      ^~~
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:13: note:                 'int end'
    8 | int n,start,end,opt[100001],k,opt_n,flag;
      |             ^~~
a.cc:45:26: error: reference to 'end' is ambiguous
   45 |     for(int i=start+1;i<=end;++i){
      |                          ^~~
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:13: note:                 'int end'
    8 | int n,start,end,opt[100001],k,opt_n,flag;
      |             ^~~