Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Input Output
- #include<iostream>
- #include<iomanip>
- #include<fstream>
- #include<sstream>
- #include<streambuf>
- //C lib
- #include<cstdlib>
- #include<cstring>
- #include<cmath>
- #include<climits>
- #include<cctype>
- //Container
- #include<array>
- #include<vector>
- #include<stack>
- #include<queue>
- #include<deque>
- #include<list>
- #include<bitset>
- #include<set>
- #include<map>
- #include<unordered_set>
- #include<unordered_map>
- //Others
- #include<tuple>
- #include<algorithm>
- #include<functional>
- #include<numeric>
- #include<iterator>
- #include<limits>
- #include<utility>
- #include<complex>
- #include<type_traits>
- #include<initializer_list>
- #include<random>
- using namespace std;
- #if __cplusplus > 201703L
- #include<concepts>
- #include<ranges>
- #include<bit>
- #include<numbers>
- using namespace numbers;
- #include<span>
- #endif
- void _debug() {cerr << '\n';}
- template <typename A, typename... B>
- void _debug(A a, B... b) {cerr << a << ' ', _debug(b...);}
- #define debug(...) cerr << '(' << (#__VA_ARGS__) << ") : ", _debug(__VA_ARGS__)
- namespace abb {
- using ll = long long;
- using uint = unsigned int;
- using ull = unsigned long long;
- template<typename T> using V = vector<T>;
- template<typename T> using Q = queue<T>;
- template<typename T> using DQ = deque<T>;
- template<typename T> using V2d = vector<vector<T>>;
- template<typename T> using US = unordered_set<T>;
- template<typename T, size_t s> using A = array<T, s>;
- template<typename T1, typename T2> using UM = unordered_map<T1, T2>;
- template<typename T1, typename T2 = T1> using P = pair<T1, T2>;
- template<typename T, typename Cmp = less<T>> using S = set<T, Cmp>;
- template<typename T, typename Cmp = less<T>> using PQ = priority_queue<T, V<T>, Cmp>;
- template<typename T1, typename T2, typename Cmp = less<T1>> using M = map<T1, T2, Cmp>;
- template<typename T> using F = function<T>;
- }
- namespace output {
- template<typename T1, typename T2>
- inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
- return os << '(' << p.first << ", " << p.second << ')';
- }
- #define unfold1(Container) \
- template<typename T> \
- inline ostream& operator<<(ostream& os, const Container<T>& x) { \
- for (const auto& i : x) \
- os << i << ' '; \
- return os; \
- }
- #define unfold2(Container) \
- template<typename T1,typename T2> \
- inline ostream& operator<<(ostream& os,const Container<T1,T2>& x){ \
- for (const auto& i : x) \
- os << i << ' '; \
- return os; \
- }
- unfold1(vector); unfold1(set); unfold1(deque); unfold2(map)
- #undef unfold1
- #undef unfold2
- };
- namespace rit {
- struct fast_istream {
- operator bool() const {return bool(cin);}
- fast_istream() {cin.tie(nullptr);}
- } fin;
- #if __cplusplus > 201703L
- template<typename T>
- fast_istream& operator>>(fast_istream& is, T& n) requires integral<T> {
- #else
- template<typename T, class = typename enable_if<is_integral<T>::value>::type>
- fast_istream & operator>>(fast_istream& is, T& n) {
- #endif
- while (isspace(cin.rdbuf()->sgetc()))
- cin.rdbuf()->snextc();
- bool sign = false;
- if (cin.rdbuf()->sgetc() == '-')
- sign = true, cin.rdbuf()->snextc();
- for (n = 0; isdigit(cin.rdbuf()->sgetc());)
- n *= 10, n += cin.rdbuf()->sbumpc() - '0';
- n = sign ? -n : n;
- return is;
- }
- fast_istream& operator>>(fast_istream& is, char& n) {
- while (isspace(cin.rdbuf()->sgetc()))
- cin.rdbuf()->snextc();
- n = cin.rdbuf()->sbumpc();
- return is;
- }
- }
- #define endl '\n'
- namespace wit {
- struct fast_ostream {
- operator bool() const {return bool(cout);}
- fast_ostream() {cout.tie(nullptr);}
- } fout;
- constexpr int buffer_size = 30;
- #if __cplusplus > 201703L
- template<typename T>
- fast_ostream& operator<<(fast_ostream& os, T n) requires integral<T> {
- #else
- template<typename T, class = typename enable_if<is_integral<T>::value>::type>
- fast_ostream & operator<<(fast_ostream& os, T n) {
- #endif
- if (!n) {cout.rdbuf()->sputc('0'); return os;}
- if (n < 0) cout.rdbuf()->sputc('-'), n = -n;
- static char buffer[buffer_size];
- int cnt = buffer_size;
- for (; n; n /= 10)
- buffer[--cnt] = n % 10 + '0';
- cout.rdbuf()->sputn(buffer + cnt, buffer_size - cnt);
- return os;
- }
- fast_ostream& operator<< (fast_ostream& os, const char& n) {
- cout.rdbuf()->sputc(n); return os;
- }
- }
- namespace algo {
- template<typename T, typename _ = decltype(std::begin(std::declval<T>())), typename Val = typename T::value_type>
- inline void sort(T& v, function<bool(Val, Val)> cmp = less<Val>()) {sort(v.begin(), v.end(), cmp);}
- template<typename T, typename _ = decltype(std::begin(std::declval<T>())), typename Val_a, typename Val_b>
- inline void replace(T& v, const Val_a& a, const Val_b& b) {replace(v.begin(), v.end(), static_cast<int>(a), static_cast<int>(b));}
- template<typename T, typename _ = decltype(std::begin(std::declval<T>())), typename Val = typename T::value_type >
- inline _ unique(T& v, function<bool(Val, Val)> cmp = equal_to<Val>()) {return unique(v.begin(), v.end(), cmp);}
- template<typename T, typename _ = decltype(std::begin(std::declval<T>())), typename Val = typename T::value_type>
- inline _ lower_bound(T& v, const Val& x, function<bool(Val, Val)> cmp = less<Val>()) {return lower_bound(v.begin(), v.end(), x, cmp);}
- template<typename T, typename _ = decltype(std::begin(std::declval<T>())), typename Val = typename T::value_type>
- inline _ upper_bound(T& v, const Val& x, function<bool(Val, Val)> cmp = less<Val>()) {return upper_bound(v.begin(), v.end(), x, cmp);}
- template<typename T, typename _ = decltype(std::begin(std::declval<T>())), typename Val = typename T::value_type>
- inline void iota(T& v, const Val& x) {iota(v.begin(), v.end(), x);}
- }
- //sublime autofill keywords:
- /*STL: push_back emplace_back pop_back push pop push_front pop_front size assign resize empty*/
- /*algorithm: lower_bound upper_bound equal_range next_permutation prev_permutation binary_search*/
- /*copy replace for_each fill find unique remove is_sorted min max min_element max_element*/
- /*ios: fixed setprecision setw stringstream / numeric: iota accumulate adjacent_difference partial_sum*/
- /*utility: move / limits: numeric_limits / iterator: begin end back_inserter front_inserter distance next prev*/
- #define MULTI_TASKCASE
- using namespace abb;
- using namespace output;
- using namespace rit;
- using namespace wit;
- using namespace algo;
- inline void init() {
- }
- inline ll det(P<ll> a, P<ll> b, P<ll> c) {
- return a.first * b.second + b.first * c.second + c.first * a.second -
- a.second * b.first - b.second * c.first - c.second * a.first;
- }
- inline ll cross(P<ll> p1, P<ll> p2, P<ll> p3) {
- return (p2.first - p1.first) * (p3.second - p1.second)
- - (p2.second - p1.second) * (p3.first - p1.first);
- }
- inline void solve() {
- int n; cin >> n;
- V<P<ll>> v(n);
- for (auto& i : v)
- cin >> i.first >> i.second;
- sort(v.begin(), v.end());
- V<P<ll>> s{v[0], v[1]};
- for (int i = 2; i < n; i++) {
- while (s.size() >= 2 && cross(s.rbegin()[1], s.rbegin()[0], v[i]) <= 0)
- s.pop_back();
- s.push_back(v[i]);
- }
- for (int i = n - 2, t = s.size() + 1; i >= 0; i--) {
- while (int(s.size()) >= t && cross(s.rbegin()[1], s.rbegin()[0], v[i]) <= 0)
- s.pop_back();
- s.push_back(v[i]);
- }
- s.pop_back();
- debug(s);
- ll ans = 0;
- for (int i = 0, m = s.size(); i < m; i++) {
- for (int j = 1, k = 2, l = 3; k < m; k++) {
- while (j < k - 1 && det(v[i], v[(i + j) % m], v[(i + k) % m]) < det(v[i], v[(i + j + 1) % m], v[(i + k) % m])) j++;
- while (l < m - 1 && det(v[i], v[(i + l) % m], v[(i + k) % m]) < det(v[i], v[(i + l + 1) % m], v[(i + k) % m])) l++;
- ll cur = det(v[i], v[(i + j) % m], v[(i + k) % m]) + det(v[i], v[(i + l) % m], v[(i + k) % m]);
- if (cur > ans)
- ans = cur, debug(i, j, k, l);
- }
- }
- cout << ans / 2.0 << endl;
- }
- /*
- 3
- 5
- 0 0
- 1 0
- 3 1
- 1 2
- 0 1
- 4
- 0 0
- 4 0
- 0 4
- 1 1
- 4
- 0 0
- 1 1
- 2 2
- 1 1
- */
- //#define FILEIO
- #ifdef FILEIO
- main(int, char* argv[]) {
- ios::sync_with_stdio(false);
- fstream filein(argv[1], ios::in);
- fstream fileout(argv[2], ios::out);
- cin.rdbuf(filein.rdbuf());
- cout.rdbuf(fileout.rdbuf());
- init();
- int t = 1;
- #ifdef MULTI_TASKCASE
- cin >> t; cin.ignore();
- #endif
- while (t--) solve();
- return 0;
- }
- #else
- main() {
- ios::sync_with_stdio(false);
- init();
- int t = 1;
- #ifdef MULTI_TASKCASE
- cin >> t; cin.ignore();
- #endif
- while (t--) solve();
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement