結果

問題 No.2012 Largest Triangle
ユーザー shotoyooshotoyoo
提出日時 2022-07-15 23:34:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,472 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 210,496 KB
実行使用メモリ 9,460 KB
最終ジャッジ日時 2024-06-27 21:05:49
合計ジャッジ時間 7,033 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 79 ms
7,536 KB
testcase_17 AC 83 ms
7,540 KB
testcase_18 AC 78 ms
7,532 KB
testcase_19 AC 77 ms
8,048 KB
testcase_20 AC 74 ms
7,920 KB
testcase_21 AC 77 ms
7,916 KB
testcase_22 AC 79 ms
7,792 KB
testcase_23 AC 78 ms
9,456 KB
testcase_24 AC 77 ms
7,664 KB
testcase_25 AC 78 ms
8,176 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 248 ms
7,568 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 212 ms
8,184 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 215 ms
7,928 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 3 ms
6,940 KB
testcase_41 AC 64 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

 bool TEST = false;

using namespace std;
#include<bits/stdc++.h>
#include<fstream>

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);i++)
#define rrep(i,n) for(ll (i)=(ll)(n)-1;(i)>=0;i--)
#define range(i,start,end,step) for(ll (i)=start;(i)<(ll)(end);(i)+=(step))
#define rrange(i,start,end,step) for(ll (i)=start;(i)>(ll)(end);(i)+=(step))

#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define all(a)  (a).begin(),(a).end()
#define allr(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
 
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T>>;
template<typename T, typename T2> using P = pair<T, T2>;
template<typename T, typename T2> using M = map<T, T2>;
template<typename T> using S = set<T>;
template<typename T, typename T2> using UM = unordered_map<T, T2>;
template<typename T> using PQ = priority_queue<T, V<T>, greater<T>>;
template<typename T> using rPQ = priority_queue<T, V<T>, less<T>>;
template<class T>vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}
template<class SS, class T> ostream& operator << (ostream& os, const pair<SS, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
 
template <class T> void UNIQUE(vector<T> &x) {sort(all(x));x.erase(unique(all(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v){for(ll i=0;i<v.size();i++)
{cerr<<v[i][0];for(ll j=1;j<v[i].size();j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v){if(v.size()!=0)cerr<<v[0];
for(ll i=1;i<v.size();i++)cerr spa v[i];
cerr<<"\n";};
template<typename T> void debug(priority_queue<T>&v){V<T> vals; while(!v.empty()) {cerr << v.top() << " "; vals.push_back(v.top()); v.pop();} cerr<<"\n"; for(auto val: vals) v.push(val);}
template<typename T, typename T2> void debug(map<T,T2>&v){for(auto [k,v]: v) cerr << k spa v << "\n"; cerr<<"\n";}
template<typename T, typename T2> void debug(unordered_map<T,T2>&v){for(auto [k,v]: v) cerr << k spa v << "\n";cerr<<"\n";}
V<int> listrange(int n) {V<int> res(n); rep(i,n) res[i]=i; return res;}

template<typename T> P<T,T> divmod(T a, T b) {return make_pair(a/b, a%b);}

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// double
/**
 * @brief Dynamic-Li-Chao-Tree
 * @docs docs/dynamic-li-chao-tree.md
*/
template< typename T, ll _x_low, ll _x_high, ll id >
struct DynamicLiChaoTree {
  
  T x_low, x_high;
 
  struct Line {
    T a, b;
 
    Line(T a, T b) : a(a), b(b) {}
 
    inline T get(T x) const { return a * x + b; }
  };
 
  struct Node {
    Line x;
    Node *l, *r;
 
    Node(const Line &x) : x{x}, l{nullptr}, r{nullptr} {}
  };
 
  Node *root;
 
  DynamicLiChaoTree() : root{nullptr} {
      x_low = _x_low;
      x_high = _x_high;
  }
 
  Node *add_line(Node *t, Line &x, const T &l, const T &r, const T &x_l, const T &x_r) {
    if(!t) return new Node(x);
 
    T t_l = t->x.get(l), t_r = t->x.get(r);
 
    if(t_l <= x_l && t_r <= x_r) {
      return t;
    } else if(t_l >= x_l && t_r >= x_r) {
      t->x = x;
      return t;
    } else {
      T m = (l + r) / 2;
      if(m == r) --m;
      T t_m = t->x.get(m), x_m = x.get(m);
      if(t_m > x_m) {
        swap(t->x, x);
        if(x_l >= t_l) t->l = add_line(t->l, x, l, m, t_l, t_m);
        else t->r = add_line(t->r, x, m + 1, r, t_m + x.a, t_r);
      } else {
        if(t_l >= x_l) t->l = add_line(t->l, x, l, m, x_l, x_m);
        else t->r = add_line(t->r, x, m + 1, r, x_m + x.a, x_r);
      }
      return t;
    }
  }
 
  void add_line(const T &a, const T &b) {
    Line x(a, b);
    root = add_line(root, x, x_low, x_high, x.get(x_low), x.get(x_high));
  }
 
  Node *add_segment(Node *t, Line &x, const T &a, const T &b, const T &l, const T &r, const T &x_l, const T &x_r) {
    if(r < a || b < l) return t;
    if(a <= l && r <= b) {
      Line y{x};
      return add_line(t, y, l, r, x_l, x_r);
    }
    if(t) {
      T t_l = t->x.get(l), t_r = t->x.get(r);
      if(t_l <= x_l && t_r <= x_r) return t;
    } else {
      t = new Node(Line(0, id));
    }
    T m = (l + r) / 2;
    if(m == r) --m;
    T x_m = x.get(m);
    t->l = add_segment(t->l, x, a, b, l, m, x_l, x_m);
    t->r = add_segment(t->r, x, a, b, m + 1, r, x_m + x.a, x_r);
    return t;
  }
 
  void add_segment(const T &l, const T &r, const T &a, const T &b) {
    Line x(a, b);
    root = add_segment(root, x, l, r - 1, x_low, x_high, x.get(x_low), x.get(x_high));
  }
 
  T query(const Node *t, const T &l, const T &r, const T &x) const {
    if(!t) return id;
    if(l == r) return t->x.get(x);
    T m = (l + r) / 2;
    if(m == r) --m;
    if(x <= m) return min(t->x.get(x), query(t->l, l, m, x));
    else return min(t->x.get(x), query(t->r, m + 1, r, x));
  }
 
  T query(const T &x) const {
    return query(root, x_low, x_high, x);
  }
};
 
// // cannot overflow query_x*xlow, query_x*xhigh
// DynamicLiChaoTree<ll, 0, ll(1e12+10), INF> t; // <type, xlow, xhigh, id>
// t.add_line(a,b);
// t.query(x);

// // cannot overflow query_x*xlow, query_x*xhigh
// t.add_line(a,b);
// t.query(x);

void Main(){
    ll n;
    cin >> n;
    DynamicLiChaoTree<double, ll(-1e12-10), ll(1e12+10), INF> t; // <type, xlow, xhigh, id>
    DynamicLiChaoTree<double, ll(-1e12-10), ll(1e12+10), INF> t2; // <type, xlow, xhigh, id>
    ll x,y;
    ll ans = 0;
    ll my = 0;
    ll mx = 0;
    ll zx = 0;
    ll zy = 0;
    V<P<ll,ll>> xy;
    rep(i,n) {
        cin >> x >> y;
        xy.emplace_back(x,y);
        if (x==0) chmax(zy, abs(y));
        if (y==0) chmax(zx, abs(x));
        chmax(mx, abs(x));
        chmax(my, abs(y));
        t.add_line(-x, y);
        t.add_line(x, -y);
        t2.add_line(-y,x);
        t2.add_line(y,-x);
    }
    for (auto [x,y] : xy) {
        if (x!=0) {
            ll val = round(-double(abs(x))*(t.query(double(y)/double(x))));
            chmax(ans, (val));
        } else {
            ;
            // ll val = round(double(abs(y))*abs(t2.query(double(x)/double(y))));
            // chmax(ans, val);
        }
    }
    chmax(ans, mx*zy);
    chmax(ans, my*zx);
    cout << ans << "\n";
}

int main(void){
    std::ifstream in("tmp_in");
    if (TEST) {
        std::cin.rdbuf(in.rdbuf());
        std::cout << std::fixed << std::setprecision(15);
    } else {
        std::cin.tie(nullptr);
        std::ios_base::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(15);
    }
    Main();
}
0