Language: C++

#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <list>
#include <stdexcept>
#include <functional>
#include <algorithm>
#include <cstring>



const size_t MOD = 10000;


template<class KeyType, class ValueType>
class MyIterator {
 private:
    size_t pos;
    typename std::list<std::pair<const KeyType, ValueType> >::iterator it;
    std::vector<std::list<std::pair<const KeyType, ValueType> > > *_table;

 public:
    MyIterator() :  pos(0) {
    }

    MyIterator(typename std::list<std::pair<const KeyType, ValueType> >::iterator i,
               std::vector<std::list<std::pair<const KeyType, ValueType> > > *table, size_t p)
            : pos(p), it(i), _table(table) {
    }

    std::pair<const KeyType, ValueType> &operator*() {
        return *it;
    }

    std::pair<const KeyType, ValueType> *operator->() {
        return &*it;
    }

    MyIterator &operator++() {
        ++it;
        while (it == (*_table)[pos].end() && pos < MOD - 1) {
            ++pos;
            it = (*_table)[pos].begin();
        }
        return *this;
    }

    bool operator==(const MyIterator &other) const {
        return pos == other.pos && it == other.it;
    }

    bool operator!=(const MyIterator &other) const {
        return !(*this == other);
    }

    MyIterator operator++(int) {
        MyIterator temp(it, _table, pos);
        ++(*this);
        return temp;
    }
};

template<class KeyType, class ValueType>
class MyConstIterator {
 private:
    size_t pos;
    typename std::list<std::pair<const KeyType, ValueType> >::const_iterator it;
    const std::vector<std::list<std::pair<const KeyType, ValueType> > > *_table;

 public:
    MyConstIterator() : pos(0) {
    }

    MyConstIterator(typename std::list<std::pair<const KeyType, ValueType> >::const_iterator i,
                    const std::vector<std::list<std::pair<const KeyType, ValueType> > > *table,
                    const size_t p) : pos(p), it(i), _table(table) {
    }

    const std::pair<const KeyType, ValueType> &operator*() {
        return *it;
    }

    const std::pair<const KeyType, ValueType> *operator->() {
        return &*it;
    }

    MyConstIterator &operator++() {
        ++it;
        while (it == (*_table)[pos].end() && pos < MOD - 1) {
            ++pos;
            it = (*_table)[pos].begin();
        }
        return *this;
    }

    bool operator==(const MyConstIterator &other) const {
        return pos == other.pos && it == other.it;
    }

    bool operator!=(const MyConstIterator &other) const {
        return !(*this == other);
    }

    MyConstIterator operator++(int) {
        MyConstIterator temp(it, _table, pos);
        ++(*this);
        return temp;
    }
};


template<class KeyType, class ValueType, class Hash = std::hash<KeyType> >
class HashMap {
 private:
    std::vector<std::list<std::pair<const KeyType, ValueType> > > hash_table;
    Hash hash;
    size_t size_of_table;

 public:
    HashMap & operator=(const HashMap & s) {
        HashMap temp(s);
        temp.swap(*this);
        return *this;
    }
    void swap(HashMap& s) throw() {
        std::swap(this->size_of_table, s.size_of_table);
        std::swap(this->hash, s.hash);
        std::vector<std::list<std::pair<const KeyType, ValueType> > > temp;
        temp.resize(MOD);
        for (int i = 0; i < MOD; i++) {
            for (auto x : this->hash_table[i]) {
                temp[i].push_back(x);
            }
        }
        for (int i = 0; i < MOD; i++) {
            this->hash_table[i].clear();
        }
        for (int i = 0; i < MOD; i++) {
            for (auto x : s.hash_table[i]) {
                this->hash_table[i].push_back(x);
            }
        }
        for (int i = 0; i < MOD; i++) {
            s.hash_table[i].clear();
        }
        for (int i = 0; i < MOD; i++) {
            for (auto x : temp[i]) {
                s.hash_table[i].push_back(x);
            }
        }
    }
    typedef MyIterator<const KeyType, ValueType> iterator;
    typedef MyConstIterator<const KeyType, ValueType>
            const_iterator;

    HashMap(Hash h = Hash()) : hash(h), size_of_table(0) {
        hash_table.resize(MOD);
    }

    template<class TIterator>
    HashMap(TIterator begin, TIterator end, Hash h = Hash()) : hash(h), size_of_table(0) {
        hash_table.resize(MOD);
        for (TIterator x = begin; x != end; ++x) {
            insert(*x);
        }
    }

    HashMap(std::initializer_list<std::pair<KeyType, ValueType> > data,
            Hash h = Hash()) : hash(h), size_of_table(0) {
        hash_table.resize(MOD);
        for (typename std::initializer_list<std::pair<KeyType, ValueType> >::const_iterator it
                = data.begin(); it != data.end(); ++it) {
            insert(*it);
        }
    }

    size_t size() const {
        return size_of_table;
    }

    bool empty() const {
        return size_of_table == 0;
    }

    Hash hash_function() const {
        return hash;
    }

    void insert(const std::pair<KeyType, ValueType> &data) {
        bool have = false;
        size_t pos = hash(data.first) % MOD;
        for (auto it = hash_table[pos].begin(); it != hash_table[pos].end(); ++it) {
            if (it->first == data.first) {
                have = true;
            }
        }
        if (!have) {
            hash_table[pos].insert(hash_table[pos].begin(),
                                   std::make_pair(data.first, data.second));
            ++size_of_table;
        }
    }

    void erase(const KeyType &key) {
        if (size_of_table == 0) {
            return;
        }
        size_t pos = hash(key) % MOD;
        for (auto it = hash_table[pos].begin(); it != hash_table[pos].end(); ++it) {
            if (it->first == key) {
                hash_table[pos].erase(it);
                --size_of_table;
                return;
            }
        }
    }

    iterator begin() {
        if (size_of_table == 0) {
            return (this->end());
        }
        size_t pos = 0;
        while (hash_table[pos].empty() && pos < MOD)
            ++pos;
        if (pos == MOD) {
            return this->end();
        } else {
            iterator ans(hash_table[pos].begin(), &hash_table, pos);
            return ans;
        }
    }

    iterator end() {
        iterator ans((*this).hash_table[MOD - 1].end(), &hash_table, MOD - 1);
        return ans;
    }

    const_iterator begin() const {
        if (size_of_table == 0) {
            return (this->end());
        }
        size_t pos = 0;
        while (hash_table[pos].empty() && pos < MOD)
            ++pos;
        return (pos == MOD ? this->end() :
                const_iterator(this->hash_table[pos].cbegin(), &hash_table, pos));
    }

    const_iterator end() const {
        return const_iterator(this->hash_table[MOD - 1].cend(), &hash_table, MOD - 1);
    }

    iterator find(const KeyType &key) {
        if (size_of_table == 0)
            return this->end();
        size_t pos = hash(key) % MOD;
        for (auto it = hash_table[pos].begin(); it != hash_table[pos].end(); ++it) {
            if (it->first == key) {
                return iterator(it, &hash_table, pos);
            }
        }
        return this->end();
    }

    const_iterator find(const KeyType &key) const {
        if (size_of_table == 0)
            return this->end();
        size_t pos = hash(key) % MOD;
        for (auto it = hash_table[pos].begin(); it != hash_table[pos].end(); ++it) {
            if (it->first == key) {
                return const_iterator(it, &hash_table, pos);
            }
        }
        return this->end();
    }

    ValueType &operator[](const KeyType &k) {
        auto it = this->find(k);
        if (it != this->end()) {
            return it->second;
        } else {
            ValueType p;
            if (strncmp(typeid(p).name(), "i", 1) == 0) {
                insert(std::make_pair(k, static_cast<ValueType>(0)));
            } else {
                insert(std::make_pair(k, p));
            }
            return this->operator[](k);
        }
    }

    const ValueType &at(const KeyType &k) const {
        auto it = this->find(k);
        if (it != this->end()) {
            return it->second;
        } else {
            throw std::out_of_range("");
        }
    }

    void clear() {
        if (size_of_table == 0) {
            return;
        }
        for (int i = 0; i < MOD; ++i) {
            hash_table[i].clear();
        }
        size_of_table = 0;
    }
};
 
 
using namespace std;

 
const int INF = (int) 1e9;

struct point {
	int x;
    int y;
	point() : x(0), y(0) {}
};
 
struct fenwick_tree {
	int n;
  HashMap<int, int> F;
 
    fenwick_tree() : n(INF) {
        
    }
	void upd(int i, int x) {
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	} 
	int get(int i) {
		int res = 0;
		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);
		return res;
	}
};
 
 
bool cmp(point a, point b) {
    return make_pair(a.x, a.y) < make_pair(b.x, b.y); 
}
 
 
int main() {
#ifdef NICK
	freopen("input.txt", "r", stdin);
#else

#endif
    point start, finish;
    int n;
    cin >> start.x >> start.y;
    cin >> finish.x >> finish.y;
    cin >> n;
    point p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    if (start.x > finish.x)
        swap(start, finish);
    if (start.y > finish.y) {
        finish.y = 2 * start.y - finish.y;
        for (int i = 0; i < n; i++) {
            p[i].y = 2 * start.y - p[i].y;
        }
    }
    vector<point> a;
    for (int i = 0; i < n; i++) {
        if (start.x <= p[i].x && p[i].x <= finish.x && start.y <= p[i].y && p[i].y <= finish.y)
            a.emplace_back(p[i]);
    }
    fenwick_tree dp;
    sort(a.begin(), a.end(), cmp);
    for (int i = 0; i < (int)a.size(); ++i)
        dp.upd(a[i].y, dp.get(a[i].y) + 1);
    int cur = dp.get(INF);
    long double ans = 0;
    if (cur != min(finish.y - start.y, finish.x - start.x) + 1)
        ans = 100.0 * (finish.y + finish.x - start.y - start.x) - 20.0 * cur + 5 * M_PI * cur;
    else
        ans = 100.0 * (finish.y + finish.x - start.x - start.y) - 20.0 * cur + 5 * M_PI * (cur - 1) + 10 * M_PI;
    cout << fixed << setprecision(13) << ans << "\n";
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:385:84: error: 'M_PI' was not declared in this scope
  385 |         ans = 100.0 * (finish.y + finish.x - start.y - start.x) - 20.0 * cur + 5 * M_PI * cur;
      |                                                                                    ^~~~
a.cc:387:84: error: 'M_PI' was not declared in this scope
  387 |         ans = 100.0 * (finish.y + finish.x - start.x - start.y) - 20.0 * cur + 5 * M_PI * (cur - 1) + 10 * M_PI;
      |                                                                                    ^~~~
a.cc:388:22: error: 'setprecision' was not declared in this scope
  388 |     cout << fixed << setprecision(13) << ans << "\n";
      |                      ^~~~~~~~~~~~
a.cc:10:1: note: 'std::setprecision' is defined in header '<iomanip>'; this is probably fixable by adding '#include <iomanip>'
    9 | #include <cstring>
  +++ |+#include <iomanip>
   10 |