Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;
typedef pair<int,int> pii;

const int MAXN=2e5+2+5;
const int MAXX=1e8+1+8;
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899L;
const long double GAIN=20-2*PI*10/4;
const long double LOSS=2*PI*10/2-20;

int x1,y1,x2,y2;
int N;
int X[MAXN], Y[MAXN];

map<int,int> rank;
int st[2*MAXN];
void update(int i, int v) {
        i = rank[i];
        //cout << "Update " << i << " " << v << "\n";
        for (st[i += N+2] = v; i>1; i>>=1)
                st[i>>1] = max(st[i],st[i^1]);
}

int query(int a, int b) {
        if (a > b) swap(a,b);
        a = rank[a];
        b = rank[b];
        b++;
        //cout << "Query " << a << " " << b << "\n";
        int res=0;
        for (a+=N+2, b+=N+2; a < b; a>>=1, b>>=1) {
                if (a&1) res = max(res,st[a++]);
                if (b&1) res = max(res,st[--b]);
        }
        return res;
}

void set_rank() {
        vector<int> yf;
        for (int i=0; i<N; ++i)
                yf.push_back(Y[i]);
        yf.push_back(y1);
        yf.push_back(y2);
        sort(yf.begin(),yf.end());
        for (int i=0; i<yf.size(); ++i)
                rank[yf[i]] = i;
}

int mxtrn() {
        if (x1 > x2) {
                swap(x1,x2);
                swap(y1,y2);
        }

        set_rank();

        vector<pii> xf;
        for (int i=0; i<N; i++)
                xf.push_back(pii(X[i],i));

        sort(xf.begin(), xf.end());

        int i=0;
        while (i < N && xf[i].first < x1)
                ++i;

        //cout << "y1 y2 " << rank[y1] << " " << rank[y2] << "\n";
        for (; i < N && xf[i].first < x2; ++i) {
                int cur = xf[i].second;
                //cout << "Processing fountain " << cur << " at " << X[cur] << ", " << Y[cur] << "\n";
                //cout << "\tRank is " << rank[Y[cur]] << "\n";
                int k = 1+query(y1,Y[cur]);
                //cout << "\tGets value " << k << "\n";
                update(Y[cur],k);
        }

        return query(y1,y2);
}

int main()
{
        cin >> x1 >> y1 >> x2 >> y2;
        cin >> N;
        for (int i=0; i<N; ++i)
                cin >> X[i] >> Y[i];

        cout << setprecision(20) << fixed;
        if (x1 == x2) {
                for (int i=0; i<N; ++i) {
                        if (X[i] == x1 && Y[i] > min(y1,y2) && Y[i] < max(y1,y2)) {
                                cout << 100*abs(y1-y2) + LOSS << "\n";
                                return 0;
                        }
                }
                cout << 100*abs(y1-y2) << "\n";
        } else if (y1 == y2) {
                for (int i=0; i<N; ++i) {
                        if (Y[i] == y1 && X[i] > min(x1,x2) && X[i] < max(x1,x2)) {
                                cout << 100*abs(x1-x2) + LOSS << "\n";
                                return 0;
                        }
                }
                cout << 100*abs(x1-x2) << "\n";
        } else {
                cout << 100*abs(x1-x2) + 100*abs(y1-y2) - mxtrn()*GAIN << "\n";
        }
}

Compiler output:
a.cc:16:8: warning: built-in function 'y1' declared as non-function [-Wbuiltin-declaration-mismatch]
   16 | int x1,y1,x2,y2;
      |        ^~
a.cc: In function 'void update(int, int)':
a.cc:23:13: error: reference to 'rank' is ambiguous
   23 |         i = rank[i];
      |             ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:14: note:                 'std::map<int, int> rank'
   20 | map<int,int> rank;
      |              ^~~~
a.cc: In function 'int query(int, int)':
a.cc:31:13: error: reference to 'rank' is ambiguous
   31 |         a = rank[a];
      |             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:14: note:                 'std::map<int, int> rank'
   20 | map<int,int> rank;
      |              ^~~~
a.cc:32:13: error: reference to 'rank' is ambiguous
   32 |         b = rank[b];
      |             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:14: note:                 'std::map<int, int> rank'
   20 | map<int,int> rank;
      |              ^~~~
a.cc: In function 'void set_rank()':
a.cc:51:17: error: reference to 'rank' is ambiguous
   51 |                 rank[yf[i]] = i;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:14: note:                 'std::map<int, int> rank'
   20 | map<int,int> rank;
      |              ^~~~