Problem p03428 (C++)

Buggy submission (status: Runtime Error):
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;
typedef pair<int, pll> pip;
typedef pair<pll, int> ppi;
typedef pair<lld, pll> plp;
typedef pair<pll, lld> ppl;
typedef pair<pll, pll> ppp;
template <typename T> using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using minHeap = priority_queue<T, vector<T>, greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define jizz                                                                   \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios::sync_with_stdio(0);
inline void input(int &_x) {
  _x = 0;
  int _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-')
    _tc = getchar();
  if (_tc == '-')
    _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9')
    _x = _x * 10 + (_tc - 48), _tc = getchar();
  _x *= _tmp;
}
inline void output(int _x) {
  char _buff[20];
  int _f = 0;
  if (_x == 0)
    putchar('0');
  while (_x > 0) {
    _buff[_f++] = _x % 10 + '0';
    _x /= 10;
  }
  for (_f -= 1; _f >= 0; _f--)
    putchar(_buff[_f]);
  putchar('\n');
}
template <typename Iter> ostream &_out(ostream &s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++)
    s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) {
  return _out(s, c.begin(), c.end());
}
#ifdef erd1
#define pprint(x)                                                              \
  cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << " - " << (#x) << "="       \
       << (x) << endl
#else
#define pprint(x)
#endif

// code starts here
vector<ppi> v;
vector<int> top, bot;
vector<long double> ans;
const long double PI = 3.141592653589793238462643383279502884L;
inline pii operator-(pii p1, pii p2) { return {p1.ff - p2.ff, p1.ss - p2.ss}; }
inline lld operator+(pii p1, pii p2) {
  return (lld)p1.ff * p2.ss - (lld)p1.ss * p2.ff;
}
inline lld operator*(pii p1, pii p2) {
  return (lld)p1.ff * p2.ff + (lld)p1.ss * p2.ss;
}
inline long double sz(pii p) {
  return sqrt((lld)p.ff * p.ff + (lld)p.ss * p.ss);
}
inline long double angle(pii p1, pii p2) {
  long double l = sz(p1) * sz(p2), c = p1 * p2 / l, s = (p1 + p2) / l,
              t1 = acos(c), t2 = asin(s);
  if (c < 0)
    t2 = PI - t2;
  assert(abs(t1 - t2) < 0.0000001);
  return (t1 + t2) / 2;
}
signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v.pb({{a, b}, i});
  }
  if (n == 1)
    return cout << 1 << endl, 0;
  sort(all(v));
  for (int i = 0; i < n; i++) {
    // cout << top << bot << endl;
    while (top.size() > 1 && (v[top.back()].ff - v[top[top.size() - 2]].ff) +
                                     (v[i].ff - v[top[top.size() - 2]].ff) >=
                                 0)
      top.pop_back();
    while (bot.size() > 1 && (v[bot.back()].ff - v[bot[bot.size() - 2]].ff) +
                                     (v[i].ff - v[bot[bot.size() - 2]].ff) <=
                                 0)
      bot.pop_back();
    top.pb(i);
    bot.pb(i);
  }
  top.pop_back();
  reverse(all(top));
  for (auto i : top)
    bot.pb(i);
  bot.pb(bot[1]);
  // cout << bot << endl;
  ans.resize(n);
  for (int i = 1; i < bot.size() - 1; i++) {
    ans[v[bot[i]].ss] = angle(v[bot[i]].ff - v[bot[i - 1]].ff,
                              v[bot[i + 1]].ff - v[bot[i]].ff) /
                        2 / PI;
  }
  cout << setprecision(20) << fixed;
  for (auto i : ans)
    cout << i << endl;
}


Fixed submission:
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;
typedef pair<int, pll> pip;
typedef pair<pll, int> ppi;
typedef pair<lld, pll> plp;
typedef pair<pll, lld> ppl;
typedef pair<pll, pll> ppp;
template <typename T> using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using minHeap = priority_queue<T, vector<T>, greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define jizz                                                                   \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios::sync_with_stdio(0);
inline void input(int &_x) {
  _x = 0;
  int _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-')
    _tc = getchar();
  if (_tc == '-')
    _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9')
    _x = _x * 10 + (_tc - 48), _tc = getchar();
  _x *= _tmp;
}
inline void output(int _x) {
  char _buff[20];
  int _f = 0;
  if (_x == 0)
    putchar('0');
  while (_x > 0) {
    _buff[_f++] = _x % 10 + '0';
    _x /= 10;
  }
  for (_f -= 1; _f >= 0; _f--)
    putchar(_buff[_f]);
  putchar('\n');
}
template <typename Iter> ostream &_out(ostream &s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++)
    s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) {
  return _out(s, c.begin(), c.end());
}
#ifdef erd1
#define pprint(x)                                                              \
  cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << " - " << (#x) << "="       \
       << (x) << endl
#else
#define pprint(x)
#endif

// code starts here
vector<ppi> v;
vector<int> top, bot;
vector<long double> ans;
const long double PI = 3.141592653589793238462643383279502884L;
inline pii operator-(pii p1, pii p2) { return {p1.ff - p2.ff, p1.ss - p2.ss}; }
inline lld operator+(pii p1, pii p2) {
  return (lld)p1.ff * p2.ss - (lld)p1.ss * p2.ff;
}
inline lld operator*(pii p1, pii p2) {
  return (lld)p1.ff * p2.ff + (lld)p1.ss * p2.ss;
}
inline long double sz(pii p) {
  return sqrt((lld)p.ff * p.ff + (lld)p.ss * p.ss);
}
inline long double angle(pii p1, pii p2) {
  long double l = sz(p1) * sz(p2), c = p1 * p2 / l, s = (p1 + p2) / l,
              t1 = acos(c), t2 = asin(s);
  if (c < 0)
    t2 = PI - t2;
  // assert(abs(t1-t2)<0.0000001);
  return s < 0.5 ? t2 : t1;
}
signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v.pb({{a, b}, i});
  }
  if (n == 1)
    return cout << 1 << endl, 0;
  sort(all(v));
  for (int i = 0; i < n; i++) {
    // cout << top << bot << endl;
    while (top.size() > 1 && (v[top.back()].ff - v[top[top.size() - 2]].ff) +
                                     (v[i].ff - v[top[top.size() - 2]].ff) >=
                                 0)
      top.pop_back();
    while (bot.size() > 1 && (v[bot.back()].ff - v[bot[bot.size() - 2]].ff) +
                                     (v[i].ff - v[bot[bot.size() - 2]].ff) <=
                                 0)
      bot.pop_back();
    top.pb(i);
    bot.pb(i);
  }
  top.pop_back();
  reverse(all(top));
  for (auto i : top)
    bot.pb(i);
  bot.pb(bot[1]);
  // cout << bot << endl;
  ans.resize(n);
  for (int i = 1; i < bot.size() - 1; i++) {
    ans[v[bot[i]].ss] = angle(v[bot[i]].ff - v[bot[i - 1]].ff,
                              v[bot[i + 1]].ff - v[bot[i]].ff) /
                        2 / PI;
  }
  cout << setprecision(20) << fixed;
  for (auto i : ans)
    cout << i << endl;
}