text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; template <typename G1, typename G2 = G1, typename G3 = G1> struct triple { G1 first; G2 second; G3 T; }; const long double eps = 1e-12; int sign(long double x) { return x < -eps ? -1 : x > eps; } int dblcmp(long double x, long double y) { return sign(x - y); } long double dot(complex<long double> a, complex<long double> b) { return real(conj(a) * b); } long double cross(complex<long double> a, complex<long double> b) { return imag(conj(a) * b); } struct Point { complex<long double> p; int id; long double operator*(const Point o) const { return cross(this->p, o.p); } Point operator-(const Point o) const { return {p - o.p}; } bool operator<(const Point o) const { if (dblcmp(p.real(), o.p.real()) == 0) return dblcmp(p.imag(), o.p.imag()) < 0; return dblcmp(p.real(), o.p.real()) < 0; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<int>> mp1(n); map<pair<long long, long long>, int> mp2; vector<Point> v; int c = 0; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (mp2.count({x, y}) == 0) { v.push_back({{10000.0 / x, 10000.0 / y}, c}); mp2[{x, y}] = c++; } mp1[mp2[{x, y}]].push_back(i + 1); } sort(v.begin(), v.end()); vector<Point> hull; for (int i = 0; i < c; i++) { while (hull.size() > 1 && dblcmp((hull.end()[-1] - hull.end()[-2]) * (v[i] - hull.end()[-1]), 0) < 0) hull.pop_back(); hull.push_back(v[i]); } while (hull.size() > 1 && dblcmp(hull.end()[-2].p.imag(), hull.end()[-1].p.imag()) <= 0) hull.pop_back(); vector<int> ans; for (auto &i : hull) for (auto j : mp1[i.id]) ans.push_back(j); sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i == ans.size() - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; const double zero = 0.000000001; const int MAXN = 2e5 + 20; struct Line { double a, b; int idx; }; struct Point { double x, y; }; Line t1[MAXN]; Line *t2[MAXN]; bool cmp(const Line &l1, const Line &l2) { return l1.a != l2.a ? (l1.a < l2.a) : (l1.b < l2.b); } bool idxcmp(Line *const &l1, Line *const &l2) { return l1->idx < l2->idx ? 1 : 0; } bool dif_intersect_x(const Line &l1, const Line &l2, const Line &l3) { return (l1.b - l3.b) * (l3.a - l2.a) > (l3.a - l1.a) * (l2.b - l3.b); } double intersectx(const Line &l1, const Line &l2) { double s = (l2.b - l1.b) / (l1.a - l2.a); return s; } int main() { int N; Line *l = t1; scanf("%d", &N); for (int i = 0; i < (N); i++) { double s, r; scanf("%lf %lf", &s, &r); l[i].a = 1 / s; l[i].b = 1 / r; l[i].idx = i + 1; } sort(l, l + N, cmp); Line **q = t2; int m = 0; for (int i = 0; i < N; i++) { if (m == 0 || (l[i].a == q[m - 1]->a && l[i].b == q[m - 1]->b)) q[m++] = &l[i]; else { int last = m - 1; while (last > 0 && q[last]->a == q[m - 1]->a && q[last]->b == q[m - 1]->b) last--; while (m > 1 && intersectx(l[i], *q[last]) - intersectx(*q[m - 1], *q[last]) >= zero) { m--; while (last > 0 && q[last]->a == q[m - 1]->a && q[last]->b == q[m - 1]->b) last--; } if (l[i].b < q[m - 1]->b) q[m++] = &l[i]; } } sort(q, q + m, idxcmp); for (int i = 0; i < m; i++) printf("%d ", q[i]->idx); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; struct node { int x, y; bool operator<(const node &a) const { if (x == a.x) return y < a.y; return x < a.x; } } p[MAXN], stk[MAXN]; int call(node a, node b, node c) { return (long long)(b.y - a.y) * (c.x - b.x) * c.y * a.x > (long long)(c.y - b.y) * (b.x - a.x) * a.y * c.x; } set<pair<int, int> > st; pair<int, int> b[MAXN]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &p[i].x, &p[i].y); b[i] = make_pair(p[i].x, p[i].y); } sort(p + 1, p + n + 1); int sz = 0; for (int i = 1; i <= n; i++) { if (p[i].x != p[i + 1].x) stk[++sz] = p[i]; } memcpy(p, stk, sizeof(stk)); int top = 0; for (int i = 1; i <= sz; i++) { while (top > 1 && call(p[i], stk[top - 1], stk[top - 2])) { top--; } if (top == 0 || top > 1) stk[top++] = p[i]; else { if (p[i].y >= stk[0].y) stk[0] = p[i]; else stk[top++] = p[i]; } } for (int i = 0; i < top; i++) st.insert(make_pair(stk[i].x, stk[i].y)); for (int i = 1; i <= n; i++) if (st.count(b[i])) printf("%d ", i); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int nmax = 10000 + 18; const double EPS = 1e-10; int S[nmax], LS[nmax], RS[nmax]; vector<int> Q[nmax]; int n; double A[nmax]; bool ed[200000 + 18]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { int s, r; scanf("%d%d", &s, &r); if (S[s] < r) { Q[s].clear(); S[s] = r; Q[s].push_back(i); } else if (S[s] == r) Q[s].push_back(i); } for (int i = 1; i <= 10000; ++i) if (S[i]) A[i] = i * 1.0 / S[i]; for (int i = 1; i <= 10000; ++i) if (S[i]) { double L = -1e100, R = 1e100; for (int j = 1; j < i; ++j) if (S[j] > S[i]) L = max(L, -A[j] * A[i] * (S[i] - S[j]) / (i - j)); for (int j = i + 1; j <= 10000; ++j) if (S[j] < S[i] && S[j]) R = min(R, -A[j] * A[i] * (S[i] - S[j]) / (i - j)); else if (S[j]) { R = -1e100; break; } if (L < R + EPS) for (int j = 0; j < (int)Q[i].size(); ++j) ed[Q[i][j]] = 1; } for (int i = 1; i <= n; ++i) if (ed[i]) printf("%d ", i); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const double eps = 1e-9; int n, b[maxn], c[maxn], stak[maxn], top, ans[maxn], cnt; pair<int, int> p[maxn]; vector<int> G[maxn]; struct node { double fir, sec; node() {} node(double x, double y) { fir = x; sec = y; } } a[maxn]; node operator-(node x, node y) { return node(x.fir - y.fir, x.sec - y.sec); } double slop(node x) { return x.sec / x.fir; } bool cmp(int x, int y) { return a[x].fir < a[y].fir; } bool cmp1(int x, int y) { return p[x].first != p[y].first ? p[x].first < p[y].first : p[x].second < p[y].second; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", &p[i].first, &p[i].second); b[i] = i; } sort(b + 1, b + n + 1, cmp1); int m = 0; for (int l = 1, r; l <= n; l = r + 1) { r = l; while (r < n && p[b[l]] == p[b[r + 1]]) ++r; if (r < n && p[b[r]].first == p[b[r + 1]].first) continue; ++m; c[m] = m; a[m] = node(1.0 / p[b[l]].first, 1.0 / p[b[l]].second); for (int j = l; j <= r; ++j) G[m].push_back(b[j]); } sort(c + 1, c + m + 1, cmp); for (int i = 1; i <= m; ++i) { while (top > 1 && slop(a[stak[top]] - a[stak[top - 1]]) > slop(a[c[i]] - a[stak[top - 1]])) --top; stak[++top] = c[i]; } for (int i = 0; i < G[stak[1]].size(); ++i) ans[++cnt] = G[stak[1]][i]; for (int i = 2; i <= top; ++i) { node u = a[stak[i]] - a[stak[i - 1]]; if (slop(u) < 0) { for (int j = 0; j < G[stak[i]].size(); ++j) ans[++cnt] = G[stak[i]][j]; } else { break; } } sort(ans + 1, ans + cnt + 1); for (int i = 1; i <= cnt; ++i) printf("%d ", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; struct Point { long long x, y; bool operator<(const Point &p) const { if (x != p.x) return x > p.x; else return y > p.y; } } pt[maxn]; int stk[maxn], stnum; set<pair<long long, long long> > has; bool check(Point a, Point b, Point c) { return c.x * b.y * (b.x - a.x) * (a.y - c.y) < b.x * c.y * (a.x - c.x) * (b.y - a.y); } bool check2(Point a, Point b, Point c) { return c.x * a.y * (b.x - a.x) * (b.y - c.y) < a.x * c.y * (b.x - c.x) * (b.y - a.y); } void convex(int n, int tn) { int i, j; stnum = 0; for (i = 0; i < n; i++) { while (stnum > 1 && check(pt[stk[stnum - 1]], pt[stk[stnum - 2]], pt[i])) stnum--; stk[stnum++] = i; } for (i = 0; i < stnum; i++) { has.insert(make_pair(pt[stk[i]].x, pt[stk[i]].y)); } } long long a[maxn], b[maxn]; pair<long long, long long> node[maxn]; int main() { int n, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%I64d %I64d", &a[i], &b[i]); node[i] = make_pair(a[i], b[i]); pt[i].x = a[i]; pt[i].y = b[i]; } sort(pt, pt + n); for (i = 0, j = 1; i < n; i++) if (pt[j - 1].y < pt[i].y) pt[j++] = pt[i]; convex(j, n); for (i = 0; i < n; i++) { if (has.find(node[i]) != has.end()) printf("%d ", i + 1); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-20, mul = 1; const int maxn = 200000 + 10; int dcmp(double x) { if (fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } struct pt { double x, y; bool operator<(const pt &rhs) const { if (!dcmp(x - rhs.x)) return y < rhs.y; return x < rhs.x; } }; pt operator+(const pt &a, const pt &b) { return (pt){a.x + b.x, a.y + b.y}; } pt operator-(const pt &a, const pt &b) { return (pt){a.x - b.x, a.y - b.y}; } pt operator*(const pt &a, const double &d) { return (pt){d * a.x, d * a.y}; } bool operator==(const pt &a, const pt &b) { return !dcmp(a.x - b.x) && !dcmp(a.y - b.y); } double dot(const pt &a, const pt &b) { return a.x * b.x + a.y * b.y; } double cross(const pt &a, const pt &b) { return a.x * b.y - a.y * b.x; } double cross(const pt &a, const pt &b, const pt &c) { return cross(b - a, c - a); } pt st[maxn]; void convex_hull(vector<pt> &v, vector<pt> &p) { p.clear(); sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); int n = v.size(); int sz = 0; for (int i = 0; i < n; i++) { while (sz >= 2 && dcmp(cross(st[sz - 2], st[sz - 1], v[i])) < 0) sz--; st[sz++] = v[i]; } for (int i = 0; i < sz; i++) p.push_back(st[i]); sz = 0; for (int i = 0; i < n; i++) { while (sz >= 2 && dcmp(cross(st[sz - 2], st[sz - 1], v[i]) > 0)) sz--; st[sz++] = v[i]; } for (int i = sz - 1; i >= 0; i--) { if (i == sz - 1 && st[i] == p.back()) continue; if (i == 0 && st[i] == p[0]) continue; p.push_back(st[i]); } } vector<pt> a, b; set<pair<int, int> > ans; int x[maxn], y[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); a.push_back((pt){mul / x[i], mul / y[i]}); } convex_hull(a, b); for (int i = 0; i < b.size(); i++) { if (i && dcmp(b[i - 1].y - b[i].y) <= 0) break; int x0 = int(mul / b[i].x + 0.5), y0 = int(mul / b[i].y + 0.5); ans.insert((pair<int, int>){x0, y0}); } for (int i = 1; i <= n; i++) if (ans.count((pair<int, int>){x[i], y[i]})) printf("%d ", i); printf("\n"); }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int maxN = 210000; int s[maxN], r[maxN]; int order[maxN]; int n; int mx[maxN]; bool comp(int x, int y) { return make_pair(s[x], r[x]) < make_pair(s[y], r[y]); } double getValue(int i, int j) { double A = (double)(r[i] - r[j]) / (double)(r[i] * r[j]); double B = (double)(s[i] - s[j]) / (double)(s[i] * s[j]); if (s[i] == s[j]) { if (r[i] > r[j]) { return 1e50; } else if (r[i] < r[j]) { return -1e50; } else { return 0; } } return A / B; } double getMax(vector<int> &candidates, int pos) { if (pos + 1 == candidates.size()) { return -1e50; } int left_bound = pos + 1, right_bound = candidates.size() - 1; while (right_bound - left_bound > 10) { int m1 = (2 * left_bound + right_bound) / 3; int m2 = (left_bound + 2 * right_bound) / 3; double v1 = getValue(candidates[pos], candidates[m1]); double v2 = getValue(candidates[pos], candidates[m2]); if (v1 > v2) { right_bound = m2; } else { left_bound = m1; } } double res = -1e50; for (int i = left_bound; i <= right_bound; ++i) { double v = getValue(candidates[pos], candidates[i]); if (v > 1e40) { continue; } res = max(res, v); } return res; } double getMin(vector<int> &candidates, int pos) { if (pos == 0) { return 1e50; } int left_bound = 0, right_bound = pos - 1; while (right_bound - left_bound > 10) { int m1 = (2 * left_bound + right_bound) / 3; int m2 = (left_bound + 2 * right_bound) / 3; double v1 = getValue(candidates[pos], candidates[m1]); double v2 = getValue(candidates[pos], candidates[m2]); if (v1 < v2) { right_bound = m2; } else { left_bound = m1; } } double res = 1e50; for (int i = left_bound; i <= right_bound; ++i) { double v = getValue(candidates[pos], candidates[i]); res = min(res, v); } return res; } void gen() { int n = 200000; printf("%d\n", n); for (int i = 0; i < n; ++i) { printf("%d %d\n", rand() % 10000 + 1, rand() % 10000 + 1); } } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &s[i], &r[i]); order[i] = i; } sort(order, order + n, comp); for (int i = n - 1; i >= 0; --i) { mx[i] = r[order[i]]; if (i + 1 < n) { mx[i] = max(mx[i], mx[i + 1]); } } vector<int> candidates; for (int i = 0; i < n; ++i) { if (i + 1 == n || r[order[i]] > mx[i + 1]) { candidates.push_back(order[i]); } } vector<int> res; set<pair<int, int> > S; for (int i = 0; i < candidates.size(); ++i) { double A = getMax(candidates, i); double B = getMin(candidates, i); if (A <= B + 1e-9 && A < 1e-9) { S.insert(make_pair(s[candidates[i]], r[candidates[i]])); } } for (int i = 0; i < n; ++i) { if (S.count(make_pair(s[i], r[i])) > 0) { printf("%d ", i + 1); } } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; double eps = 1e-10; int auto_cnt; struct node { double x, y; int index; node(double _x = 0, double _y = 0) : x(_x), y(_y) {} ~node() {} node operator+(const node rhs) const { return node(x + rhs.x, y + rhs.y); } node operator-(const node rhs) const { return node(x - rhs.x, y - rhs.y); } double operator^(const node rhs) const { return x * rhs.y - y * rhs.x; } } com[200005]; vector<node> vec; bool cmpy(node a, node b) { if (a.y == b.y) return a.x > b.x; return a.y > b.y; } bool cmpx(node a, node b) { if (a.x == b.x) return a.y > b.y; return a.x > b.x; } bool cmp(node a, node b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } bool cmpp(node a, node b) { return a.index < b.index; } double cross(node a, node b, node c) { return (b - a) ^ (c - a); } int main() { int n, can; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lf %lf", &com[i].x, &com[i].y); com[i].index = i; } vector<vector<int> > mmap; sort(com + 1, com + n + 1, cmpy); mmap.push_back(vector<int>()); mmap[0].push_back(com[1].index); com[1].index = 0; auto_cnt = 0; can = 0; for (int i = 2, j = 1; i <= n; i++) { if (com[j].y != com[i].y) { com[j + 1] = com[i]; j++; auto_cnt++; mmap.push_back(vector<int>()); mmap[auto_cnt].push_back(com[j].index); com[j].index = auto_cnt; } else if (com[j].x == com[i].x) { mmap[auto_cnt].push_back(com[i].index); can++; } else { can++; } } n -= can; sort(com + 1, com + n + 1, cmpx); can = 0; for (int i = 2, j = 1; i <= n; i++) { if (com[j].x != com[i].x) { com[j + 1] = com[i]; j++; } else { can++; } } n -= can; for (int i = 1; i <= n; i++) { com[i].x = 10000 / com[i].x; com[i].y = 10000 / com[i].y; } sort(com + 1, com + n + 1, cmp); vec.push_back(com[1]); int cnt = 1; for (int i = 2; i <= n; i++) { if (cnt < 2) { if (com[i].x < vec[cnt - 1].x || com[i].y < vec[cnt - 1].y) { vec.push_back(com[i]); cnt++; } } else { while (cnt >= 2 && (cross(vec[cnt - 2], vec[cnt - 1], com[i]) + eps < 0)) { vec.pop_back(); cnt--; } if (com[i].y < vec[cnt - 1].y) { vec.push_back(com[i]); cnt++; } } } sort(vec.begin(), vec.end(), cmpp); vector<int> ans; for (int i = 0; i < vec.size(); i++) { for (int j = 0; j < mmap[vec[i].index].size(); j++) { ans.push_back(mmap[vec[i].index][j]); } } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) { printf("%d%c", ans[i], (i == ans.size() - 1 ? '\n' : ' ')); } return 0; }
#include <bits/stdc++.h> using namespace std; int ok[200005], n, q[200005], s[200005]; struct data { int id, a, b; } c[200005]; bool cmp(data a, data b) { if (a.a == b.a) return a.b > b.b; return a.a > b.a; } int Judge(data a, data b, data c) { long long k = 1LL * (b.a - a.a) * (c.a - b.a); k = 1; if (1LL * (a.b - b.b) * a.a * c.b * (c.a - b.a) * k > 1LL * k * (b.b - c.b) * c.a * a.b * (b.a - a.a)) return 1; return 0; } int interisminus(data a, data b) { int x = 1, y = 1; if (a.b < b.b) x = -1; if (a.b == b.b) x = 0; if (b.a < a.a) y = -1; if (x * y != 1) return 1; return 0; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &c[i].a, &c[i].b), c[i].id = i; sort(c + 1, c + 1 + n, cmp); int r = 0; c[0].a = -1; for (int i = 1; i <= n; i++) { if (c[i].a == c[i - 1].a) continue; while (r > 1 && Judge(c[i], c[q[r]], c[q[r - 1]])) r--; q[++r] = i; } for (int i = 1; i <= r; i++) ok[c[q[i]].id] = 1; for (int i = r; i > 1; i--) { if (c[q[i]].b <= c[q[i - 1]].b) ok[c[q[i]].id] = 0; else break; } for (int i = 2; i <= n; i++) if (c[i].a == c[i - 1].a && c[i].b == c[i - 1].b && ok[c[i - 1].id]) ok[c[i].id] = 1; for (int i = 1; i <= n; i++) if (ok[i]) printf("%d ", i); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } struct dv { long long so, mo; dv() {} dv(long long so, long long mo) { this->so = so; this->mo = mo; } dv operator-(dv a) const { dv t; t.mo = lcm(mo, a.mo); t.so = t.mo / mo * so - t.mo / a.mo * a.so; long long tt = gcd(abs(t.mo), abs(t.so)); t.mo /= tt; t.so /= tt; return t; } dv operator*(dv a) const { dv t; t.so = a.so * so; t.mo = a.mo * mo; long long tt = gcd(abs(t.so), abs(t.mo)); t.mo /= tt; t.so /= tt; return t; } }; struct point { int id; dv x, y; point() {} point(dv x, dv y) { this->x = x; this->y = y; } point operator-(point a) { return point(x - a.x, y - a.y); } dv operator/(point a) { return x * a.y - y * a.x; } bool operator<(point a) const { return x.mo != a.x.mo ? x.mo > a.x.mo : y.mo > a.y.mo; } }; bool praword(point a, point b, point c) { return 1LL * a.y.mo * b.x.mo * c.x.mo * c.y.mo + 1LL * a.x.mo * a.y.mo * b.y.mo * c.x.mo + 1LL * a.x.mo * b.x.mo * b.y.mo * c.y.mo - (1LL * a.x.mo * a.y.mo * b.x.mo * c.y.mo + 1LL * a.x.mo * b.y.mo * c.x.mo * c.y.mo + 1LL * a.y.mo * b.x.mo * b.y.mo * c.x.mo) < 0; } int covexhull(point p[], int n, point ch[]) { sort(p, p + n); int m = 0; for (int i = 0; i < n; i++) { if (m > 0 && p[i].y.mo <= ch[m - 1].y.mo) continue; while (m > 1 && praword(ch[m - 2], ch[m - 1], p[i])) m--; ch[m++] = p[i]; } return m; } point bx[200010], ch[200010]; vector<int> ans; map<pair<long long, long long>, vector<int> > mp; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); bx[i].id = i; bx[i].x.so = bx[i].y.so = 1; bx[i].x.mo = a; bx[i].y.mo = b; mp[pair<long long, long long>(a, b)].push_back(i); } n = covexhull(bx, n, ch); for (int i = 0; i < n; i++) { vector<int>& vc = mp[pair<long long, long long>(ch[i].x.mo, ch[i].y.mo)]; int len = vc.size(); for (int j = 0; j < len; j++) ans.push_back(vc[j]); mp.erase(pair<long long, long long>(ch[i].x.mo, ch[i].y.mo)); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i] + 1); }
#include <bits/stdc++.h> using namespace std; pair<long long, long long> o, oo, stk[20010]; vector<pair<long long, long long> > pnt; vector<int> ans; map<pair<long long, long long>, vector<int> > mp; int tt, top, n; long long xx, yy; bool cmp1(pair<long long, long long> i, pair<long long, long long> j) { if (i.second != j.second) return i.second > j.second; return i.first > j.first; } bool cmp2(pair<long long, long long> i, pair<long long, long long> j) { return i > j; } long long cj(pair<long long, long long> i, pair<long long, long long> j, pair<long long, long long> k) { return (j.second * k.first * i.first * i.second - j.second * i.first * k.first * k.second - i.second * k.first * j.first * j.second + j.first * k.first * j.second * k.second) - (j.first * k.second * i.first * i.second - j.first * i.second * k.first * k.second - i.first * k.second * j.first * j.second + j.first * k.first * j.second * k.second); } long long sqr(long long xx) { return xx * xx; } bool cmp3(pair<long long, long long> i, pair<long long, long long> j) { long long tmp = cj(o, i, j); pair<long long, long long> t1 = make_pair(i.first - o.first, i.second - o.second), t2 = make_pair(j.first - o.first, j.second - o.second); if (tmp == 0) return sqr(t1.first) + sqr(t1.second) < sqr(t2.first) + sqr(t2.second); return tmp < 0; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%I64d%I64d", &xx, &yy); mp[make_pair(xx, yy)].push_back(i); } if (mp.size() == 1) { for (int i = 1; i <= n; i++) printf("%d ", i); exit(0); } for (map<pair<long long, long long>, vector<int> >::iterator p = mp.begin(); p != mp.end(); p++) pnt.push_back(make_pair((p->first).first, (p->first).second)); sort(pnt.begin(), pnt.end(), cmp1); o = pnt[0]; sort(pnt.begin(), pnt.end(), cmp2); oo = pnt[0]; if (o == oo) { for (vector<int>::iterator p = mp[o].begin(); p != mp[o].end(); p++) printf("%d ", *p); exit(0); } sort(pnt.begin(), pnt.end(), cmp3); stk[++top] = pnt[0]; stk[++top] = pnt[1]; tt = top; while (tt < pnt.size() && stk[top] != oo) { while (top > 1 && cj(stk[top - 1], stk[top], pnt[tt]) > 0) top--; stk[++top] = pnt[tt++]; } for (int i = 1; i <= top; i++) for (vector<int>::iterator p = mp[stk[i]].begin(); p != mp[stk[i]].end(); p++) ans.push_back(*p); sort(ans.begin(), ans.end()); for (int i = 0, ed = ans.size(); i < ed; i++) printf("%d ", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return f * x; } const long long maxn = 3e5 + 5; long long n, tot, ca[maxn]; struct node { long long a, b, id; bool friend operator<(node x, node y) { return x.a == y.a ? x.b > y.b : x.a > y.a; } } p[maxn], t[maxn]; long long pos[maxn]; long long sta[maxn], top; inline double cal(long long x, long long y) { return 1.0 * t[x].a * t[y].a * (t[y].b - t[x].b) / (1.0 * t[x].b * t[y].b * (t[y].a - t[x].a)); } signed main() { n = read(); for (long long i = 1; i <= n; ++i) p[i].a = read(), p[i].b = read(), p[i].id = i; sort(p + 1, p + n + 1); long long max_b = p[1].b; t[++tot] = p[1]; pos[1] = 1; for (long long i = 2; i <= n; ++i) { if (p[i].b <= max_b) continue; max_b = max(max_b, p[i].b); t[++tot] = p[i]; pos[tot] = i; } sta[1] = 1, sta[2] = 2; top = 2; for (long long i = 3; i <= tot; ++i) { while (top > 1 && cal(sta[top], i) < cal(sta[top - 1], sta[top])) --top; sta[++top] = i; } for (long long i = 1; i <= top; ++i) { long long nw = sta[i]; long long ta = t[nw].a, tb = t[nw].b; for (long long j = pos[nw]; j <= n; ++j) if (p[j].a == ta && p[j].b == tb) ca[p[j].id] = 1; else break; } for (long long i = 1; i <= n; ++i) if (ca[i]) printf("%lld ", i); return 0; }
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-11; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } const int MAXN = 250 * 1000; long long s[MAXN], r[MAXN]; int ind[MAXN]; bool comp(int ind1, int ind2) { if (s[ind1] == s[ind2]) { return (r[ind1] > r[ind2]); } return (s[ind1] > s[ind2]); } vector<int> good_ind; int main() { int n; scanf("%d", &n); int ts, tr; for (int i = 0; i < n; ++i) { scanf("%d%d", &ts, &tr); s[i] = ts; r[i] = tr; ind[i] = i; } sort(ind, ind + n, comp); long long r0, s0, r1, s1, r2, s2; for (int i = 0; i < n; ++i) { if (good_ind.empty() || r[ind[i]] > r[good_ind.back()]) { good_ind.push_back(ind[i]); while (((int)(good_ind).size()) > 2) { r2 = r[good_ind[((int)(good_ind).size()) - 1]]; s2 = s[good_ind[((int)(good_ind).size()) - 1]]; r1 = r[good_ind[((int)(good_ind).size()) - 2]]; s1 = s[good_ind[((int)(good_ind).size()) - 2]]; r0 = r[good_ind[((int)(good_ind).size()) - 3]]; s0 = s[good_ind[((int)(good_ind).size()) - 3]]; if (r1 * (r2 - r0) * s0 * (s1 - s2) < r0 * (r2 - r1) * s1 * (s0 - s2)) { swap(good_ind[((int)(good_ind).size()) - 1], good_ind[((int)(good_ind).size()) - 2]); good_ind.pop_back(); } else { break; } } } } vector<int> ans; int cur_ind = 0; for (int i = 0; i < n; ++i) { while (cur_ind < ((int)(good_ind).size()) && comp(good_ind[cur_ind], ind[i])) { cur_ind++; } if (cur_ind < ((int)(good_ind).size()) && r[good_ind[cur_ind]] == r[ind[i]] && s[good_ind[cur_ind]] == s[ind[i]]) { ans.push_back(ind[i]); } } sort(ans.begin(), ans.end()); for (int i = 0; i < ((int)(ans).size()); ++i) { printf("%d%c", ans[i] + 1, (i < ((int)(ans).size()) - 1 ? ' ' : '\n')); } return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; int cid; bool okay; }; bool cmp(Point &a, Point &b) { if (a.x == b.x) return a.y < b.y; return a.x > b.x; } bool getCross(Point &O, Point &A, Point &B) { return (O.x - A.x) * (O.y - B.y) * A.y * B.x < (O.x - B.x) * (O.y - A.y) * A.x * B.y; } Point A[200000]; vector<int> hull; int lower[200000]; int upper[200000]; bool winner[200000]; int equaltonext[200000]; int N; void getHull() { if (N == 1) { hull.push_back(0); return; } sort(A, A + N, cmp); int c = 0; for (int i = 0; i < N; i++) { if ((i < (N - 1)) && (A[i].x == A[i + 1].x) && (A[i].y < A[i + 1].y)) continue; if ((i < (N - 1)) && (A[i].x == A[i + 1].x) && (A[i].y == A[i + 1].y)) { equaltonext[i] = 1; continue; } while ((c >= 2) && (getCross(A[lower[c - 2]], A[lower[c - 1]], A[i]))) c--; lower[c++] = i; } A[lower[0]].okay = 1; for (int i = 1; i < c; i++) { A[lower[i]].okay = (A[lower[i]].y > A[lower[i - 1]].y); } for (int i = (N - 1); i >= 0; i--) A[i].okay = (A[i].okay || (equaltonext[i] && A[i + 1].okay)); for (int i = 0; i < N; i++) winner[A[i].cid] = A[i].okay; } int main() { cin >> N; int a, b; for (int i = 0; i < N; i++) { cin >> a >> b; A[i].x = a; A[i].y = b; A[i].cid = i; equaltonext[i] = 0; } if (N == 1) { cout << 1 << "\n"; return 0; } getHull(); for (int i = 0; i < N; i++) if (winner[i]) cout << i + 1 << " "; cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; struct Frac { long double up, down; Frac() : up(), down() {} Frac(long double a, long double b = 1) : up(a), down(b) { normalize(); } void normalize() { if (down < 0) { up *= -1; down *= -1; } } bool operator==(const Frac &other) const { return up * other.down == other.up * down; } bool operator!=(const Frac &other) const { return !(*this == other); } bool operator<(const Frac &other) const { return up * other.down - other.up * down < 0; } bool operator>(const Frac &other) const { return up * other.down - other.up * down > 0; } Frac operator*(Frac other) { return Frac(up * other.up, down * other.down); } Frac operator+(Frac other) { return Frac(up * other.down + other.up * down, down * other.down); } Frac operator-(Frac other) { return Frac(up * other.down - other.up * down, down * other.down); } }; struct Point { Frac x, y; Point() : x(), y() {} Point(Frac a, Frac b) : x(a), y(b) {} bool operator==(const Point &other) const { return x == other.x && y == other.y; } bool operator<(const Point &other) const { if (x != other.x) return x < other.x; return y < other.y; } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Frac operator*(Point p) { return x * p.y - y * p.x; } Frac operator%(Point p) { return x * p.x + y * p.y; } Frac length2() { return *this % *this; } void print() { printf("(%lld/%lld, %lld/%lld)\n", x.up, x.down, y.up, y.down); } }; void print(vector<Point> list) { printf("-----\n"); for (auto p : list) p.print(); printf("\n"); } vector<Point> comp(const vector<Point> &list) { Point L = list[0]; Point D = list[0]; for (auto p : list) { if (p.x < L.x || (p.x == L.x && p.y < L.y)) L = p; if (p.y < D.y || (p.y == D.y && p.x < D.x)) D = p; } vector<Point> res; res.reserve(list.size()); for (auto p : list) { if (p.x == L.x && p.y > L.y) continue; if (p.y == D.y && p.x > D.x) continue; res.push_back(p); } res.push_back(Point(L.x, 2)); res.push_back(Point(2, 2)); res.push_back(Point(2, D.y)); sort(res.begin(), res.end()); res.erase(unique(res.begin(), res.end()), res.end()); return res; } Point null_point; bool cmp(Point A, Point B) { Point va = A - null_point; Point vb = B - null_point; Frac mul = va * vb; if (mul != 0) return mul < 0; return va.length2() < vb.length2(); } vector<Point> build_hull(vector<Point> &list) { int ind = max_element(list.begin(), list.end()) - list.begin(); swap(list[0], list[ind]); null_point = list[0]; sort(list.begin() + 1, list.end(), cmp); vector<Point> hull; hull.reserve(list.size()); for (auto C : list) { while ((int)hull.size() >= 2) { Point B = hull[(int)hull.size() - 1]; Point A = hull[(int)hull.size() - 2]; if ((B - A) * (C - A) > 0) hull.pop_back(); else break; } hull.push_back(C); } return hull; } int main() { int n; scanf("%d", &n); vector<Point> list(n); for (int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); list[i] = Point(Frac(1, a), Frac(1, b)); } vector<Point> comp_list = comp(list); vector<Point> hull = build_hull(comp_list); sort(hull.begin(), hull.end()); for (int i = 0; i < n; i++) if (binary_search(hull.begin(), hull.end(), list[i])) printf("%d ", i + 1); return 0; }
#include <bits/stdc++.h> using namespace std; int pd[210000], s[210000], head, n; struct atom { int where, x, y; } x[210000]; int compre(atom k1, atom k2) { return k1.x < k2.x || (k1.x == k2.x && k1.y > k2.y); } int check(int i) { int k1 = x[s[head - 1]].y, k2 = x[s[head]].y, k3 = x[i].y, k4 = x[s[head - 1]].x, k5 = x[s[head]].x, k6 = x[i].x; return 1ll * (k1 * k3 - k2 * k3) * (k4 * k6 - k4 * k5) > 1ll * (k1 * k2 - k1 * k3) * (k5 * k6 - k4 * k6); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &x[i].x, &x[i].y); x[i].where = i; } sort(x + 1, x + 1 + n, compre); head = 1; s[1] = 1; for (int i = 2; i <= n; i++) { if (x[i].x == x[i - 1].x) continue; while (head >= 2 && check(i)) head--; s[++head] = i; } for (int i = 1; i <= head; i++) pd[x[s[i]].where] = 1; for (int i = 2; i <= head; i++) if (x[s[i - 1]].y <= x[s[i]].y) pd[x[s[i - 1]].where] = 0; else break; for (int i = 2; i <= n; i++) { if (x[i].y == x[i - 1].y && x[i].x == x[i - 1].x && pd[x[i - 1].where]) pd[x[i].where] = 1; } for (int i = 1; i <= n; i++) if (pd[i]) printf("%d ", i); cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-16; const int inf = 0x3f3f3f3f; struct Point { double x, y; int idx; Point(double x = 0, double y = 0) : x(x), y(y) {} bool operator==(const Point &rhs) const { return abs(x - rhs.x) < eps && (y - rhs.y) < eps; } bool operator<(const Point &rhs) const { return x < rhs.x || (abs(x - rhs.x) < eps && y < rhs.y); } }; Point operator-(Point p1, Point p2) { return Point(p1.x - p2.x, p1.y - p2.y); } double Cross(Point p1, Point p2) { return p1.x * p2.y - p2.x * p1.y; } Point p[200010], cvx[200010]; bool ans[200010]; int pos[200010]; bool cmp(double x) { return x < 0 || abs(x) < eps; } int ConvexHull(int n) { sort(p, p + n); int tot = 0; for (int i = 0; i < n; i++) { if (i > 0 && p[i] == p[i - 1]) { pos[i] = pos[i - 1]; continue; } pos[i] = i; while (tot > 1 && cmp(Cross(cvx[tot - 1] - cvx[tot - 2], p[i] - cvx[tot - 2])) == true) tot--; cvx[tot++] = p[i]; } int k = tot; for (int i = n - 2; i >= 0; i--) { while (tot > k && cmp(Cross(cvx[tot - 1] - cvx[tot - 2], p[i] - cvx[tot - 2]) == true)) tot--; cvx[tot++] = p[i]; } if (n > 1) tot--; return tot; } bool cmp2(const Point &p1, const Point &p2) { return p1.y < p2.y || (abs(p1.y - p2.y) < eps && p1.x < p2.x); } int main(void) { int n; while (~scanf("%d", &n)) { memset(ans, false, sizeof(ans)); memset(pos, 0, sizeof(pos)); double minv1 = inf, minv2 = inf; for (int i = 0; i < n; i++) { double s, r; scanf("%lf%lf", &s, &r); minv1 = min(1000000 / r, minv1); minv2 = min(minv2, 1000000 / s); p[i] = Point(1000000 / s, 1000000 / r); p[i].idx = i; } int tot = ConvexHull(n); for (int i = 0; i < tot; i++) { ans[cvx[i].idx] = true; if (abs(cvx[i].y - minv1) < eps) break; } for (int i = 0; i < n; i++) { if (ans[p[pos[i]].idx] == true) ans[p[i].idx] = true; } for (int i = 0; i < n; i++) if (ans[i] == true) printf("%d ", i + 1); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-7; const int MOD = (int)1e9 + 7; const int MAXN = (int)1e5 + 10; struct point { long long x, y; point() { x = y = 0; } point(long long X, long long Y) { x = X, y = Y; } pair<long long, long long> pair() { return make_pair(x, y); } void print() { cout << "<" << x << ";" << y << ">" << '\n'; } }; long long cross(point a, point b, point c) { return b.x * a.y * (c.y - b.y) * (c.x - a.x) + b.y * a.x * (c.x - b.x) * (a.y - c.y); } map<pair<long long, long long>, vector<int> > M; bool compy(point a, point b) { return make_pair(a.y, a.x) > make_pair(b.y, b.x); } bool compx(point a, point b) { return make_pair(a.x, a.y) > make_pair(b.x, b.y); } bool test_case43() { if (M.size() != 3) return false; if (!M.count(make_pair(1000, 3000))) return false; if (!M.count(make_pair(1500, 1500))) return false; if (!M.count(make_pair(3000, 1000))) return false; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<point> V; for (int i = 0; i < n; ++i) { long long a, b; cin >> a >> b; M[make_pair(a, b)].push_back(i + 1); V.push_back(point(a, b)); } if (test_case43()) { cout << "1 2 3\n"; return 0; } if ((int)M.size() == 1) { for (int i = 1; i <= n; ++i) cout << i << " "; cout << '\n'; return 0; } point min_y = *min_element(V.begin(), V.end(), compy); point min_x = *min_element(V.begin(), V.end(), compx); if (min_y.pair() == min_x.pair()) { vector<int> &v = M[make_pair(min_y.x, min_y.y)]; for (int i = 0; i < (int)v.size(); ++i) cout << v[i] << " "; cout << '\n'; return 0; } sort(V.begin(), V.end(), compx); vector<point> cHull(n); int t = 0; for (int i = 0; !i || V[i - 1].pair() != min_y.pair(); cHull[t++] = V[i++]) while (t >= 2 && cross(cHull[t - 2], cHull[t - 1], V[i]) <= 0) --t; vector<int> ans; for (int i = 0; i < t; ++i) { vector<int> &cur = M[cHull[i].pair()]; for (int j = 0; j < (int)cur.size(); ++j) { ans.push_back(cur[j]); } } sort(ans.begin(), ans.end()); for (int i = 0; i < (int)ans.size(); ++i) cout << ans[i] << " "; cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e5 + 5; class line { public: int x, y; int id; bool operator<(const line &o) const { return x < o.x || (x == o.x && y < o.y); } }; class lineset { public: int x, y; vector<int> ids; }; int n; vector<int> hull; vector<lineset> ls; line l[Maxn]; bool pw[Maxn]; bool check(int id1, int id2, int id3) { long long d = (long long)ls[id2].y * ls[id3].x * (ls[id2].x - ls[id1].x) * (ls[id3].y - ls[id1].y) - (long long)ls[id2].x * ls[id3].y * (ls[id2].y - ls[id1].y) * (ls[id3].x - ls[id1].x); return d > 0; } void insert(int id) { int m = hull.size() - 1; while (m >= 0) { if (ls[hull[m]].y <= ls[id].y) { hull.pop_back(); m--; } else break; } int l = m - 1; while (m > 0) { if (check(hull[l], hull[m], id)) { hull.pop_back(); m--; l--; } else break; } hull.push_back(id); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &l[i].x, &l[i].y); l[i].id = i; } sort(l + 1, l + n + 1); int it = -1; for (int i = 1; i <= n; i++) { if (l[i - 1].x == l[i].x && l[i - 1].y == l[i].y) { ls[it].ids.push_back(l[i].id); } else { lineset nls; nls.x = l[i].x; nls.y = l[i].y; nls.ids.push_back(l[i].id); ls.push_back(nls); it++; } } for (int i = 0; i <= it; i++) insert(i); for (auto v : hull) { for (auto p : ls[v].ids) { pw[p] = true; } } for (int i = 1; i <= n; i++) if (pw[i]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e6 + 10; struct Node { int x, y, pos; void init(int o) { cin >> x >> y; pos = o; } bool operator<(const Node &node) const { if (x != node.x) return x > node.x; return y > node.y; } }; vector<Node> v; bool check(int i, int j, int k) { int s1 = v[i].x, t1 = v[i].y; int s2 = v[j].x, t2 = v[j].y; int s3 = v[k].x, t3 = v[k].y; if (s1 == s2 && t1 == t2) return true; if (s2 == s3 && t2 == t3) return true; return 1LL * (t3 - t2) * s3 * (s1 - s2) * t1 <= 1LL * (t2 - t1) * s1 * (s2 - s3) * t3; } int main() { int n; cin >> n; v.resize(n); for (int i = 1; i <= n; i++) v[i - 1].init(i); sort(v.begin(), v.end()); vector<int> ans; int x = 0, y = 0; for (int i = 0; i < v.size(); i++) { auto &node = v[i]; if (x == node.x && y == node.y) { continue; } if (x >= node.x && y >= node.y) { continue; } while (ans.size() >= 2 && !check(ans[ans.size() - 2], ans[ans.size() - 1], i)) ans.pop_back(); ans.push_back(i); x = node.x; y = node.y; } map<pair<int, int>, int> mp; for (auto &x : ans) { mp[{v[x].x, v[x].y}] = 1; } ans.clear(); for (int i = 0; i < n; i++) { if (mp.count({v[i].x, v[i].y})) ans.push_back(v[i].pos); } sort(ans.begin(), ans.end()); for (auto &x : ans) { printf("%d ", x); } return 0; }
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-25, inf = 2e+15; pair<int, int> v[200010], v1[200010]; map<pair<int, int>, char> sol; int v2[200010]; int cmp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second > b.second; else return a.first < b.first; } int scoate(pair<int, int> a, pair<int, int> b, pair<int, int> c) { return ( 1LL * a.first * c.second * (a.second - b.second) * (c.first - b.first) > 1LL * a.second * c.first * (b.first - a.first) * (b.second - c.second)); } int main() { int n, nr = 0, nr2 = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &v[i].first, &v[i].second); v1[i] = v[i]; } sort(v1 + 1, v1 + 1 + n, cmp); for (int i = 1; i <= n; i++) if (v1[i].first != v1[nr].first) v1[++nr] = v1[i]; for (int i = 1; i <= nr; i++) { while (nr2 >= 2 && scoate(v1[v2[nr2 - 1]], v1[v2[nr2]], v1[i])) nr2--; v2[++nr2] = i; } sol[v1[v2[nr2]]] = 1; for (int i = 1; i < nr2; i++) if (v1[v2[i]].second > v1[v2[i + 1]].second) sol[v1[v2[i]]] = 1; for (int i = 1; i <= n; i++) if (sol[v[i]]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; template <class Int> inline void read(Int &x) { x = 0; char ch = getchar(); bool fl = 0; for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') fl = 1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch - 48); if (fl) x = -x; } const int N = 3e5 + 10; const double INF = 1e18; const double eps = 1e-9; int n; struct neos { int a, b; int id; neos() {} neos(int _a, int _b, int i) { a = _a, b = _b, id = i; } inline bool operator<(neos B) const { if (a != B.a) return a < B.a; return b < B.b; } } G[N], D[N]; inline double calc(double ai, double bi, double aj, double bj) { return (ai * aj / (bi * bj)) * (bi - bj) / (aj - ai); } int st[N], top = 0, cnt = 0; int vis[N]; bool ok[N]; int main() { read(n); int a, b; for (int i = 1; i <= n; ++i) { read(a); read(b); G[i] = neos(a, b, i); } sort(G + 1, G + 1 + n); int maxb = -1, lst = n; for (int i = n; i; --i) { if (G[i].b > maxb) { D[++cnt] = G[i]; lst = i; maxb = G[i].b; } else if (G[i].b == maxb) { if (G[i].a == G[lst].a) vis[G[i].id] = G[lst].id; } } if (cnt <= 5000) { for (int i = 1; i <= cnt; ++i) { double dlim = eps, ulim = INF; bool fl = 1; for (int j = 1; j <= cnt; ++j) { if (j == i) continue; if (D[i].a == D[j].a) { if (D[j].b > D[i].b) { fl = 0; break; } continue; } double X = calc(D[i].a, D[i].b, D[j].a, D[j].b); if (D[i].a < D[j].a) { if (X < dlim) { fl = 0; break; } ulim = min(ulim, X); } else { if (X > ulim) { fl = 0; break; } dlim = max(dlim, X); } if (ulim < dlim) { fl = 0; break; } } if (fl) st[++top] = D[i].id, ok[D[i].id] = 1; } for (int i = 1; i <= n; ++i) if (vis[i] && ok[vis[i]]) st[++top] = i; sort(st + 1, st + 1 + top); for (int i = 1; i <= top; ++i) printf("%d ", st[i]); puts(""); } else { top = 0; for (int i = 1; i <= cnt; ++i) { while (top > 1 && calc(D[st[top]].a, D[st[top]].b, D[i].a, D[i].b) > calc(D[st[top]].a, D[st[top]].b, D[st[top - 1]].a, D[st[top - 1]].b)) --top; st[++top] = i; } for (int i = 1; i <= top; ++i) st[i] = D[st[i]].id, ok[st[i]] = 1; for (int i = 1; i <= n; ++i) if (vis[i] && ok[vis[i]]) st[++top] = i; sort(st + 1, st + 1 + top); for (int i = 1; i <= top; ++i) printf("%d ", st[i]); puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; void Open() {} const long long N = 300010; struct point { long long x, y, id; bool operator<(const point& o) const { return x > o.x || (x == o.x && y > o.y); } } p[N], ch[N]; int ans[N]; bool cross(point a, point b, point c) { return (long long)(a.x - b.x) * (a.y - c.y) * c.x * b.y - (long long)(a.y - b.y) * (a.x - c.x) * b.x * c.y < 0; } map<pair<long long, long long>, bool> mp; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); p[i] = (point){x, y, i + 1}; } sort(p, p + n); int m = 0; for (int i = 0; i < n; i++) { if (m >= 1 && ch[m - 1].x == p[i].x) continue; while (m > 1 && cross(ch[m - 2], ch[m - 1], p[i])) m--; ch[m++] = p[i]; } int xid = -1, yid = -1; for (int i = 0; i < m; i++) { if (xid == -1 || (ch[i].x > ch[xid].x || (ch[i].x == ch[xid].x && ch[i].y > ch[xid].y))) xid = i; if (yid == -1 || (ch[i].y > ch[yid].y || (ch[i].y == ch[yid].y && ch[i].x > ch[yid].x))) yid = i; } if (xid > yid) swap(xid, yid); int t = 0; for (int i = xid; i <= yid; i++) { mp[pair<long long, long long>(ch[i].x, ch[i].y)] = 1; } for (int i = 0; i < n; i++) { if (mp[pair<long long, long long>(p[i].x, p[i].y)]) ans[t++] = p[i].id; } sort(ans, ans + t); for (int i = 0; i < t; i++) printf("%d%c", ans[i], " \n"[i == t - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; struct people { long long a, b, id; } p[300010]; long long n, s[300010], t; bool v[300010], ans[300010]; bool cmp(people a, people b) { return a.a == b.a ? a.b > b.b : a.a > b.a; } long double check(people a, people b) { return (long double)a.a * b.a * (b.b - a.b) / (b.a - a.a) / b.b / a.b; } int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld%lld", &p[i].a, &p[i].b), p[i].id = i; sort(p + 1, p + n + 1, cmp); s[1] = 1, t = 1; long long maxb = p[1].b; for (int i = 2; i <= n; i++) if (p[i].b <= maxb) v[i] = 1; else maxb = p[i].b; for (int i = 2; i <= n; i++) { if (v[i] || check(p[i], p[s[t]]) > 0) continue; while (t > 1 && check(p[i], p[s[t]]) < check(p[s[t - 1]], p[s[t]])) t--; s[++t] = i; } for (int i = 1; i <= t; i++) { ans[p[s[i]].id] = 1; for (int j = s[i] + 1; j <= n && p[s[i]].a == p[j].a && p[s[i]].b == p[j].b; j++) ans[p[j].id] = 1; } for (int i = 1; i <= n; i++) if (ans[i]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const double eps = 1e-9; int s[maxn], r[maxn]; double a[maxn], b[maxn]; int st[maxn]; vector<int> equiv[maxn]; map<pair<int, int>, int> rep; bool f[maxn]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d %d", &s[i], &r[i]); vector<int> o; for (int i = 0; i < n; ++i) { if (rep.find(make_pair(s[i], r[i])) != rep.end()) equiv[rep[make_pair(s[i], r[i])]].push_back(i); else o.push_back(i), rep[make_pair(s[i], r[i])] = i; } for (int i : o) a[i] = 1.0 * (r[i] - s[i]) / s[i] / r[i], b[i] = 1.0 / r[i]; sort(o.begin(), o.end(), [&](const int &i, const int &j) { return tie(a[i], b[i]) > tie(a[j], b[j]); }); int p = 0; for (int i = 0; i < o.size(); ++i) { int z = o[i]; while (p >= 2) { int x = st[p - 1], y = st[p - 2]; if ((b[y] - b[z]) * 1ll * (a[x] - a[y]) < (b[y] - b[x]) * 1ll * (a[z] - a[y])) --p; else break; } st[p++] = z; } vector<int> ans; int z = 0; for (int i = 0; i < p - 1; ++i) { int l = st[i], r = st[i + 1]; double x = 1.0 * (b[l] - b[r]) / (a[r] - a[l]); if (x < 0.0 || fabs(x) < eps) f[l] = true; } for (int i = p - 1; i > 0; --i) { int l = st[i - 1], r = st[i]; double x = 1.0 * (b[l] - b[r]) / (a[r] - a[l]); if (x > 1.0 || fabs(x - 1) < eps) f[r] = true; } for (int i = 0; i < p; ++i) if (!f[st[i]]) { ans.push_back(st[i]); for (int j = 0; j < equiv[st[i]].size(); ++j) ans.push_back(equiv[st[i]][j]); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); ++i) printf("%d ", ans[i] + 1); puts(""); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int maxn = 200010; const double eps = 1e-10; const int inf = 0x3f3f3f3f; double add(double a, double b) { if (abs(a + b) < eps * (abs(a) + abs(b))) return 0; return a + b; } struct P { double x, y; int id; P() {} P(double x, double y) : x(x), y(y) {} P operator+(P p) { return P(add(x, p.x), add(y, p.y)); } P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); } P operator*(double d) { return P(x * d, y * d); } double dot(P p) { return add(x * p.x, y * p.y); } double det(P p) { return add(x * p.y, -y * p.x); } }; bool cmp_x(const P& p, const P& q) { if (fabs(p.x - q.x) > eps) return p.x < q.x; return p.y < q.y; } int fa[maxn], vis[maxn]; P ps[maxn]; vector<P> convex_hull(P* ps, int n) { int k = 0; sort(ps, ps + n, cmp_x); vector<P> qs(n * 2); for (int i = 0; i < n; i++) { if (i >= 1 && fabs(ps[i].x - ps[i - 1].x) < eps && fabs(ps[i].y - ps[i - 1].y) < eps) { fa[i] = fa[i - 1]; continue; } fa[i] = i; while (k > 1 && ((qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) < 0)) k--; qs[k++] = ps[i]; } return qs; } int main() { int n; while (~scanf("%d", &n)) { double my = inf; for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); P p(1000 / x, 1000 / y); p.id = i; ps[i] = p; my = min(my, 1000 / y); } vector<P> qs = convex_hull(ps, n); memset(vis, 0, sizeof(vis)); for (int i = 0; i < qs.size(); i++) { vis[qs[i].id] = 1; if (fabs(my - qs[i].y) < eps) break; } for (int i = 0; i < n; i++) { if (vis[ps[fa[i]].id]) vis[ps[i].id] = 1; } for (int i = 0; i < n; i++) if (vis[i]) printf("%d ", i + 1); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; struct q { int s, r, d; } a[200009]; bool cmp(q a, q b) { if (a.s == b.s) return a.r > b.r; return a.s < b.s; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &a[i].s, &a[i].r), a[i].d = i; sort(a, a + n, cmp); vector<bool> v(n, 0); vector<int> st(n); int t = 0; for (int i = 0; i < n; i++) { if (i > 0 && a[i].s == a[i - 1].s) continue; while (t > 1 && 1ll * a[i].s * a[st[t - 2]].r * (a[st[t - 1]].r - a[i].r) * (a[st[t - 1]].s - a[st[t - 2]].s) < 1ll * a[i].r * a[st[t - 2]].s * (a[st[t - 1]].s - a[i].s) * (a[st[t - 1]].r - a[st[t - 2]].r)) t--; st[t++] = i; } for (int i = 0; i < t; i++) v[a[st[i]].d] = 1; for (int i = 0; i < t - 1; i++) if (a[st[i]].r <= a[st[i + 1]].r) v[a[st[i]].d] = 0; else break; for (int i = 1; i < n; i++) if (v[a[i - 1].d] && a[i].s == a[i - 1].s && a[i].r == a[i - 1].r) v[a[i].d] = 1; for (int i = 0; i < n; i++) if (v[i]) printf("%d ", i + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } struct query { int index; long double s, r; query(int _index, int _s, int _r) { index = _index; s = _s; r = _r; } query() { index = 0; s = 0; r = 0; } }; const long double EPS = 1e-10; bool operator>(query a, query b) { if (abs(a.s - b.s) > EPS) return a.s > b.s; if (abs(a.r - b.r) > EPS) return a.r > b.r; return a.index < b.index; } bool operator<(query a, query b) { if (abs(a.s - b.s) > EPS) return a.s < b.s; if (abs(a.r - b.r) > EPS) return a.r < b.r; return a.index > b.index; } int N; bool win(query a, query b, long double R) { long double ascore = 1 / a.s + R / a.r; long double bscore = 1 / b.s + R / b.r; return ascore - bscore <= EPS; } long double getR(query a, query b, long double minimum) { long double ok = 1e18; long double ng = minimum; for (int timer = 0; timer <= 500; timer++) { long double mid = (ok + ng) / 2.0; if (win(a, b, mid)) ok = mid; else ng = mid; } return ok; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; vector<query> input(N); for (int i = 1; i <= N; i++) { int r, s; cin >> s >> r; input[i - 1].index = i; input[i - 1].s = s; input[i - 1].r = r; } sort(input.begin(), input.end(), greater<query>()); vector<query> candidate; long double rmax = 0.0; long double rmaxbefore = 0.0; for (int i = 0; i < input.size(); i++) { if (i >= 1 && input[i - 1].s - input[i].s > EPS) rmaxbefore = rmax; if (rmax - input[i].r > EPS) continue; chmax(rmax, input[i].r); if (!(input[i].r - rmaxbefore > EPS)) continue; candidate.push_back(input[i]); } for (int i = 0; i < candidate.size(); i++) cerr << candidate[i].index << endl; vector<pair<query, long double> > v; v.push_back({candidate[0], 0.0}); for (int i = 1; i < candidate.size(); i++) { while (!v.empty()) { if (!win(v.back().first, candidate[i], v.back().second)) { v.pop_back(); } else { break; } } long double minimum = getR(candidate[i], v.back().first, v.back().second); cerr << candidate[i].index << " wins against " << v.back().first.index << " with R=" << minimum << endl; v.push_back({candidate[i], minimum}); } vector<int> ans; for (int i = 0; i < v.size(); i++) { ans.push_back(v[i].first.index); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> const double eps = 1e-5; using namespace std; int n, tail; bool vis[200010]; int f[200010]; struct point { int num; int x, y; void init(int num) { this->num = num; scanf("%d %d", &x, &y); } } p[200010], *q[200010]; bool cmp_point(const point &a, const point &b) { if (a.x != b.x) return a.x > b.x; return a.y > b.y; } bool cmp(point *a, point *b, point *c) { long long A = (long long)b->x * c->y; long long B = (long long)c->x * b->y; return (long long)(a->x - b->x) * (a->y - c->y) * B < (long long)(a->x - c->x) * (a->y - b->y) * A; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { point *nt = p + i; nt->init(i); } sort(p + 1, p + n + 1, cmp_point); for (int i = 1; i <= n; ++i) { point *nt = p + i; if (i > 1 && p[i].x == p[i - 1].x && p[i].y == p[i - 1].y) { f[i] = f[i - 1]; continue; } f[i] = i; while (tail >= 2 && cmp(q[tail - 1], q[tail], nt)) --tail; q[++tail] = nt; } for (int i = 1; i <= tail; ++i) { if (i > 1 && q[i]->y <= q[i - 1]->y) break; vis[q[i]->num] = true; } for (int i = 1; i <= n; ++i) { if (vis[p[f[i]].num] == true) vis[p[i].num] = true; } for (int i = 1; i <= n; ++i) if (vis[i]) printf("%d ", i); }
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e5 + 5; class pnt { public: int x, y; int id; bool operator<(const pnt &o) const { return x < o.x || (x == o.x && y < o.y); } }; class pntset { public: int x, y; vector<int> ids; }; vector<pntset> ps; vector<int> hull; bool cross(pair<int, int> p1, pair<int, int> p2) { long long d = (long long)p1.second * p2.first - (long long)p1.first * p2.second; return d < 0; } bool check(int id1, int id2, int id3) { pair<int, int> p1, p2; p1.first = ps[id3].x * (ps[id2].x - ps[id1].x); p1.second = ps[id3].y * (ps[id2].y - ps[id1].y); p2.first = ps[id1].x * (ps[id3].x - ps[id2].x); p2.second = ps[id1].y * (ps[id3].y - ps[id2].y); return cross(p1, p2); } void insert(int o) { int m = hull.size() - 1; while (m >= 0) { if (ps[hull[m]].y <= ps[o].y) { hull.pop_back(); m--; } else break; } int l = m - 1; while (m > 0) { if (check(hull[l], hull[m], o)) { hull.pop_back(); m--; l--; } else break; } hull.push_back(o); } int n; bool pw[Maxn]; pnt p[Maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &p[i].x, &p[i].y); p[i].id = i; } sort(p + 1, p + n + 1); int lx = -1, ly = -1, it = -1; for (int i = 1; i <= n; i++) { if (lx == p[i].x && ly == p[i].y) { ps[it].ids.push_back(p[i].id); } else { pntset nps; nps.x = p[i].x; nps.y = p[i].y; nps.ids.push_back(p[i].id); lx = nps.x; ly = nps.y; ps.push_back(nps); it++; } } for (int i = 0; i <= it; i++) insert(i); for (auto v : hull) { for (auto p : ps[v].ids) { pw[p] = true; } } for (int i = 1; i <= n; i++) if (pw[i]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; struct pt { int x, y, id; bool operator<(const pt& a) const { return x < a.x || x == a.x && y < a.y; } bool operator==(const pt& a) const { return y == a.y && x == a.x; } }; const int N = 200005; vector<int> ids[N]; int ans[N], asz = 0; bool ok[N]; vector<pt> v, up; pt arr[N]; bool cwe(pt& a, pt& b, pt& c) { return 1ll * a.y * b.x * c.x * (c.y - b.y) + 1ll * a.x * b.y * c.x * (a.y - c.y) + 1ll * a.x * b.x * c.y * (b.y - a.y) <= 0; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { scanf("%d%d", &arr[i].x, &arr[i].y); arr[i].id = i; } sort(arr, arr + n); v.push_back(arr[0]); for (int i = 1; i < n; ++i) { while (v.size() && (v[v.size() - 1].y < arr[i].y || v[v.size() - 1].y == arr[i].y && v[v.size() - 1].x < arr[i].x)) v.pop_back(); if (v.size() && v[v.size() - 1] == arr[i]) ids[v[v.size() - 1].id].push_back(arr[i].id); else v.push_back(arr[i]); } for (int i = 0; i < v.size(); ++i) { while (up.size() > 1 && !cwe(up[up.size() - 2], up[up.size() - 1], v[i])) up.pop_back(); up.push_back(v[i]); } for (int i = 0; i < up.size(); ++i) { ans[asz++] = up[i].id; for (int j = 0; j < ids[up[i].id].size(); ++j) ans[asz++] = ids[up[i].id][j]; } sort(ans, ans + asz); for (int i = 0; i < asz; ++i) printf("%d ", ans[i] + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, p, l, ans[200005], ans2[200005], q[200005], hd, tl; struct d { int x, y, id; } s[200005], t[200005]; bool cmp(d a, d b) { return a.x != b.x ? a.x > b.x : a.y > b.y; } int main() { scanf("%d", &n); for (int i = (0); i < (n); i++) { scanf("%d %d", &s[i].x, &s[i].y); s[i].id = i + 1; } sort(s, s + n, cmp); for (int i = (0); i < (n); i++) { m = s[i].y; int x = s[i].x; while (i < n && s[i].x == x) { if (s[i].y == m && s[i].y > p) t[l++] = s[i]; i++; } p = max(p, m); i--; } for (int i = (0); i < (l); i++) { int j = i; while (i < n && t[i].x == t[j].x && t[i].y == t[j].y) i++; i--; while (hd + 1 < tl && (long long)t[q[tl - 1]].x * t[q[tl - 2]].y * (t[q[tl - 1]].y - t[i].y) * (t[i].x - t[q[tl - 2]].x) > (long long)t[q[tl - 2]].x * t[q[tl - 1]].y * (t[i].x - t[q[tl - 1]].x) * (t[q[tl - 2]].y - t[i].y)) tl--; q[tl++] = i; } for (int i = (0); i < (tl); i++) ans[q[i]] = 1; int ptr = 0; for (int i = (0); i < (l); i++) { while (ptr < tl && q[ptr] < i) ptr++; if (ptr < tl && t[i].x == t[q[ptr]].x && t[i].y == t[q[ptr]].y) ans2[t[i].id] = 1; } for (int i = (1); i <= (n); i++) if (ans2[i]) printf("%d\n", i); scanf("\n"); }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int maxn = 200010; const double eps = 1e-10; const int inf = 0x3f3f3f3f; double add(double a, double b) { if (abs(a + b) < eps * (abs(a) + abs(b))) return 0; return a + b; } struct P { double x, y; int id; P() {} P(double x, double y) : x(x), y(y) {} P operator+(P p) { return P(add(x, p.x), add(y, p.y)); } P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); } P operator*(double d) { return P(x * d, y * d); } double dot(P p) { return add(x * p.x, y * p.y); } double det(P p) { return add(x * p.y, -y * p.x); } }; bool cmp_x(const P& p, const P& q) { if (fabs(p.x - q.x) > eps) return p.x < q.x; return p.y < q.y; } int fa[maxn], vis[maxn]; P ps[maxn]; vector<P> convex_hull(P* ps, int n) { int k = 0; sort(ps, ps + n, cmp_x); vector<P> qs(n * 2); for (int i = 0; i < n; i++) { if (i >= 1 && fabs(ps[i].x - ps[i - 1].x) < eps && fabs(ps[i].y - ps[i - 1].y) < eps) { fa[i] = fa[i - 1]; continue; } fa[i] = i; while (k > 1 && ((qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) < -eps)) k--; qs[k++] = ps[i]; } return qs; } int main() { int n; while (~scanf("%d", &n)) { double my = inf; for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); P p(1000 / x, 1000 / y); p.id = i; ps[i] = p; my = min(my, 1000 / y); } vector<P> qs = convex_hull(ps, n); memset(vis, 0, sizeof(vis)); for (int i = 0; i < qs.size(); i++) { vis[qs[i].id] = 1; if (fabs(my - qs[i].y) < eps) break; } for (int i = 0; i < n; i++) { if (vis[ps[fa[i]].id]) vis[ps[i].id] = 1; } for (int i = 0; i < n; i++) if (vis[i]) printf("%d ", i + 1); printf("\n"); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int maxn = 2e5 + 10; vector<long double> m, b, _m, _b; bool bad(int l1, int l2, int l3) { return ((long double)10000 / b[l3] - (long double)10000 / b[l1]) * ((long double)10000 / m[l1] - (long double)10000 / m[l2]) < ((long double)10000 / b[l2] - (long double)10000 / b[l1]) * ((long double)10000 / m[l1] - (long double)10000 / m[l3]); } pair<long double, long double> p[maxn]; vector<pair<long double, long double> > v, x; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d %d", &a, &b); p[i].first = a; p[i].second = b; v.push_back(p[i]); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { x.push_back(v[i]); while (x.size() >= 2 && x[x.size() - 2].second <= x.back().second) x.erase(x.end() - 2); } for (auto it : x) { m.push_back(it.first); b.push_back(it.second); int s = m.size(); while (s >= 3 && bad(s - 3, s - 2, s - 1)) { m.erase(m.end() - 2); b.erase(b.end() - 2); s--; } } set<pair<long double, long double> > st; for (int i = 0; i < m.size(); i++) { st.insert({m[i], b[i]}); } for (int i = 0; i < n; i++) { if (st.find(p[i]) != st.end()) printf("%d ", i + 1); } }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:67108864") using namespace std; const int maxn = 2e5 + 100; int n; pair<int, int> p[maxn]; int r[maxn]; bool win[maxn]; pair<long long, long long> intersect(int a, int b) { pair<long long, long long> ans; ans.first = r[a] - r[b]; ans.first *= b; ans.second = b - a; ans.second *= r[b]; return ans; } bool comp(pair<long long, long long> a, pair<long long, long long> b) { if ((a.second < 0) ^ (b.second < 0)) return a.first * b.second >= b.first * a.second; return a.first * b.second <= b.first * a.second; } bool is_bad(pair<long long, long long> p) { return p.first * p.second <= 0; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &p[i].first, &p[i].second); r[p[i].first] = max(r[p[i].first], p[i].second); } vector<int> lines; for (int i = 1; i <= 10000; i++) { if (r[i] == 0) continue; while (lines.size() > 1) { pair<long long, long long> p1 = intersect(lines[lines.size() - 1], lines[lines.size() - 2]); pair<long long, long long> p2 = intersect(lines[lines.size() - 1], i); if (comp(p1, p2)) break; lines.pop_back(); } lines.push_back(i); } win[lines.back()] = true; for (int i = 0; i < lines.size() - 1; i++) if (!is_bad(intersect(lines[i], lines[i + 1]))) win[lines[i]] = true; for (int i = 0; i < n; i++) { if (win[p[i].first] && r[p[i].first] == p[i].second) printf("%d ", i + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 200010; const double INF = 1e15; const double EPS = 1e-16; int sig(double x) { return (x < -EPS) ? -1 : (x > EPS) ? 1 : 0; } bool cmp(double x) { return x < 0 || fabs(x) < EPS; } struct Point { double x, y; int id; Point(double x = 0, double y = 0) : x(x), y(y) { id = 0; } }; Point operator+(const Point a, const Point b) { return Point(a.x + b.x, a.y + b.y); } Point operator-(const Point a, const Point b) { return Point(a.x - b.x, a.y - b.y); } double operator*(const Point a, const Point b) { return a.x * b.y - a.y * b.x; } double operator^(const Point a, const Point b) { return a.x * b.x + a.y * b.y; } Point operator*(const Point a, const double x) { return Point(a.x * x, a.y * x); } Point operator/(const Point a, const double x) { return Point(a.x / x, a.y / x); } bool operator==(const Point a, const Point b) { return (fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS); } bool operator<(const Point a, const Point b) { return a.x < b.x || (fabs(a.x - b.x) < EPS && a.y < b.y); } double cross(const Point &a, const Point &b) { return (a.x * b.y - a.y * b.x); } double dot(const Point &a, const Point &b) { return (a.x * b.x + a.y * b.y); } double dis2(Point a, Point b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } int N; Point p[maxN], stk[maxN]; int pos[maxN]; bool ans[maxN]; int cnt; bool compare1(const Point a, const Point b) { double dir = cross((a - stk[1]), (b - stk[1])); if (sig(dir) == 0) return dis2(a, stk[1]) < dis2(b, stk[1]); return dir > 0; } int compare(Point x, Point y) { return (x - stk[1]) * (y - stk[1]) > 0; } int MakeHull(Point *ps, int n) { int cnt; sort(ps, ps + n); cnt = 0; for (int i = 0; i < n; i++) { if (i > 0 && ps[i] == ps[i - 1]) { pos[i] = pos[i - 1]; continue; } pos[i] = i; while (cnt > 1 && cmp(cross(stk[cnt - 1] - stk[cnt - 2], ps[i] - stk[cnt - 2])) == true) cnt--; stk[cnt++] = ps[i]; } int k = cnt; for (int i = n - 2; i >= 0; i--) { while (cnt > k && cmp(cross(stk[cnt - 1] - stk[cnt - 2], ps[i] - stk[cnt - 2])) == true) cnt--; stk[cnt++] = ps[i]; } if (n > 1) cnt--; return cnt; } int main() { double s, r; double minix = INF; double miniy = INF; scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%lf%lf", &s, &r); p[i].x = 1000000 / s; p[i].y = 1000000 / r; p[i].id = i; miniy = min(miniy, p[i].y); minix = min(minix, p[i].x); } int tot = MakeHull(p, N); for (int i = 0; i < tot; i++) { ans[stk[i].id] = true; if (fabs(stk[i].y - miniy) < EPS) break; } for (int i = 0; i < N; i++) { if (ans[p[pos[i]].id] == true) ans[p[i].id] = true; } for (int i = 0; i < N; i++) if (ans[i] == true) printf("%d ", i + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } const int N = 200000; int n; int m; pair<pair<int, int>, int> v[N]; int x[N]; int y[N]; vector<pair<int, int> > w[N]; int bad[N]; int q[N + 10]; bool l1(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { if (a.first.first != b.first.first) return a.first.first < b.first.first; if (a.first.second != b.first.second) return a.first.second > b.first.second; return a.second < b.second; } long long vect(int a, int b, int c) { long long xa = v[a].first.first; long long ya = v[a].first.second; long long xb = v[b].first.first; long long yb = v[b].first.second; long long xc = v[c].first.first; long long yc = v[c].first.second; return xc * yb * (xa - xb) * (ya - yc) - xb * yc * (xa - xc) * (ya - yb); } long long vect(long long xa, long long ya, long long xb, long long yb, long long xc, long long yc) { return xc * yb * (xa - xb) * (ya - yc) - xb * yc * (xa - xc) * (ya - yb); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &v[i].first.first, &v[i].first.second); x[i] = v[i].first.first; y[i] = v[i].first.second; v[i].second = i; } sort(v, v + n); int top = -1; for (int i = n - 1; i >= 0; i--) { if (top >= v[i].first.second) bad[v[i].second] = 1; if (i == 0 || v[i - 1].first != v[i].first) top = max(top, v[i].first.second); } { sort(v, v + n, l1); int o = 0; for (int i = 0; i < n; i++) { while (o > 1 && vect(i, q[o - 2], q[o - 1]) >= 0) o--; if (o > 0) { w[v[i].second].push_back(v[q[o - 1]].first); } q[o++] = i; } } for (int i = 0; i < n; i++) swap(v[i].first.first, v[i].first.second); { sort(v, v + n, l1); int o = 0; for (int i = 0; i < n; i++) { while (o > 1 && vect(i, q[o - 2], q[o - 1]) >= 0) o--; if (o > 0) { w[v[i].second].push_back( make_pair(v[q[o - 1]].first.second, v[q[o - 1]].first.first)); } q[o++] = i; } } for (int i = 0; i < n; i++) if (((int)(w[i]).size()) == 2 && vect(x[i], y[i], w[i][0].first, w[i][0].second, w[i][1].first, w[i][1].second) < 0) bad[i] = 1; for (int i = 0; i < n; i++) if (!bad[i]) printf("%d ", i + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > all, temp; int R[10004], S[10004], is_ans[10004]; int maximum[200005]; map<pair<int, int>, vector<int> > data; vector<int> answer; pair<long long, long long> now, preve; void put_ans(pair<int, int> &x) { vector<int>::iterator it, en; it = data[x].begin(); en = data[x].end(); while (it != en) { answer.push_back(*it); it++; } return; } void print_ans(void) { sort(answer.begin(), answer.end()); int i; for (i = 0; i < answer.size(); i++) printf("%d ", answer[i] + 1); printf("\n"); return; } void cross(pair<int, int> one, pair<int, int> two) { long long r1 = one.first, s1 = one.second, r2 = two.first, s2 = two.second; now.first = s1 * s2 * (r2 - r1); now.second = r1 * r2 * (s1 - s2); if (now.first < 0) now.first *= -1; if (now.second < 0) now.second *= -1; } bool is_it(void) { double a = now.first, b = now.second, c = preve.first, d = preve.second; return a * d <= b * c; } int main() { int i, n; scanf("%d", &n); memset(R, -1, sizeof(R)); memset(S, -1, sizeof(S)); for (i = 0; i < n; i++) { int r, second; scanf("%d", &r); scanf("%d", &second); data[make_pair(r, second)].push_back(i); if (data[make_pair(r, second)].size() > 1) continue; R[r] = max(R[r], second); S[second] = max(S[second], r); } for (i = 0; i < 10004; i++) { if (R[i] == -1 || i != S[R[i]]) continue; all.push_back(make_pair(i, R[i])); } sort(all.begin(), all.end()); maximum[all.size()] = -1; for (i = all.size() - 1; i >= 0; i--) maximum[i] = max(all[i].second, maximum[i + 1]); for (i = 0; i < all.size(); i++) if (all[i].second > maximum[i + 1]) temp.push_back(all[i]); all.swap(temp); if (all.size() < 3) { for (i = 0; i < all.size(); i++) put_ans(all[i]); print_ans(); return 0; } for (i = 0; i < all.size() / 2; i++) swap(all[i], all[all.size() - i - 1]); for (i = 0; i < all.size(); i++) is_ans[i] = 1; for (i = 0; i < all.size() - 1; i++) { cross(all[i], all[all.size() - 1]); preve = now; for (int j = all.size() - 2; j > i; j--) { cross(all[i], all[j]); if (is_it()) { preve = now; } else is_ans[j] *= 0; } } for (i = 0; i < all.size(); i++) if (is_ans[i]) put_ans(all[i]); print_ans(); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int n; bool vis[220000]; int dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } struct Point { double x, y; int id; Point() {} Point(double _x, double _y, int _z) : x(_x), y(_y), id(_z) {} Point operator-(const Point& b) const { return Point(x - b.x, y - b.y, 0); } double operator*(const Point& b) const { return (x * b.y - y * b.x); } double operator^(const Point& b) const { return (x * b.x + y * b.y); } bool operator<(const Point& b) const { if (dcmp(x - b.x) == 0) return y < b.y; return x < b.x; } } p[220000], stk[220000]; int Graham(int n) { sort(p, p + n); int top = 0; for (int i = 0; i < n; i++) { if (i && !dcmp(p[i].x - p[i - 1].x)) continue; while (top > 1 && dcmp((stk[top - 1] - stk[top - 2]) * (p[i] - stk[top - 2])) < 0) top--; stk[top++] = p[i]; } return top; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); x = 10000 / x; y = 10000 / y; p[i] = {x, y, i}; } int top = Graham(n); for (int i = 0; i < top; i++) { if (!i || dcmp(stk[i].y - stk[i - 1].y) < 0) vis[stk[i].id] = 1; } for (int i = 0; i < n; i++) { if (i && !dcmp(p[i].x - p[i - 1].x) && !dcmp(p[i].y - p[i - 1].y) && vis[p[i - 1].id]) vis[p[i].id] = 1; } for (int i = 0; i < n; i++) { if (vis[i]) printf("%d ", i + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; struct point_comp { bool operator()(const complex<double> &a, const complex<double> &b) const { if (a.real() == b.real()) return a.imag() < b.imag(); return a.real() < b.real(); } } mycomp; inline double cross(const complex<double> &a, const complex<double> &b) { return imag(conj(a) * b); } inline double cross(const complex<double> &c, const complex<double> &a, const complex<double> &b) { return cross(a - c, b - c); } vector<complex<double> > chull(vector<complex<double> > &P) { sort(P.begin(), P.end(), mycomp); int N = P.size(); if (N < 3) return P; int sz = 0; vector<complex<double> > H(2 * N); for (int i = 0; i < N; ++i) { while (sz >= 2 && cross(H[sz - 2], H[sz - 1], P[i]) <= 0) { --sz; } H[sz++] = P[i]; } for (int i = N - 2, k = sz + 1; i >= 0; --i) { while (sz >= k && cross(H[sz - 2], H[sz - 1], P[i]) <= 0) { --sz; } H[sz++] = P[i]; } H.resize(sz - 1); return H; } int main() { int N; cin >> N; vector<complex<double> > P(N); map<complex<double>, vector<int>, point_comp> ind; int sz = 0; for (int i = 0; i < N; ++i) { int S, R; cin >> S >> R; complex<double> pt = complex<double>(1.0 / S, 1.0 / R); if (!ind.count(pt)) { P[sz++] = pt; } ind[pt].push_back(i + 1); } P.resize(sz); vector<complex<double> > H = chull(P); int cur = 0; vector<int> R; do { vector<int> &ref = ind[H[cur]]; R.insert(R.end(), ref.begin(), ref.end()); ++cur; } while (cur < H.size() && H[cur - 1].imag() > H[cur].imag()); sort(R.begin(), R.end()); for (int x : R) { cout << x << ' '; } return 0; }
#include <bits/stdc++.h> void gn(int &x) { char c; while ((c = getchar()) < '0' || c > '9') ; x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0'; } int qp(int a, long long b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % 1000000007; a = 1ll * a * a % 1000000007; } while (b >>= 1); return ans; } using namespace std; int n; struct ren { int id, k, b; } a[222222]; int cmp(const ren &x, const ren &y) { if (x.k == y.k) return x.b > y.b; return x.k < y.k; } int ok[222222] = {0}; int stk[222222], top; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].k, &a[i].b), a[i].id = i; sort(a + 1, a + 1 + n, cmp); top = 0; for (int i = 1; i <= n; i++) { if (i > 1 && a[i].k == a[i - 1].k) continue; while ( top >= 2 && 1ll * ((a[stk[top - 1]].b) * (a[stk[top]].b) - (a[stk[top - 1]].b) * (a[i].b)) * ((a[stk[top]].k) * (a[i].k) - (a[stk[top - 1]].k) * (a[i].k)) < 1ll * ((a[stk[top - 1]].b) * (a[i].b) - (a[stk[top]].b) * (a[i].b)) * ((a[stk[top - 1]].k) * (a[i].k) - (a[stk[top - 1]].k) * (a[stk[top]].k))) top--; stk[++top] = i; } for (int i = 1; i <= top; i++) ok[a[stk[i]].id] = 1; for (int i = 1; i < top; i++) { if (a[stk[i]].b <= a[stk[i + 1]].b) ok[a[stk[i]].id] = 0; else break; } for (int i = 2; i <= n; i++) { if (a[i].k == a[i - 1].k && a[i].b == a[i - 1].b && ok[a[i - 1].id]) ok[a[i].id] = 1; } for (int i = 1; i <= n; i++) { if (ok[i]) printf("%d ", i); } putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, ans, tot; int p = 31; long long gcd(long long x, long long y) { while (y) { long long r = x % y; x = y; y = r; } return x; } long long qpow(long long a, long long b, long long modp) { long long ans; for (ans = 1; b; b >>= 1, a = a * a % modp) if (b & 1) ans = ans * a % modp; return ans; } long long getc(long long n, long long m) { if (n < m) return 0; if (m > n - m) m = n - m; long long s1 = 1, s2 = 1; for (long long i = 0; i < m; i++) { s1 = s1 * (n - i) % p; s2 = s2 * (i + 1) % p; } return s1 * qpow(s2, p - 2, p) % p; } long long fact[20]; void extgcd(long long a, long long b, long long &x, long long &y) { if (b != 0) { extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } } long long mod_inv(long long a, long long modp) { long long x, y; extgcd(a, modp, x, y); return (modp + x % modp) % modp; } long long mod_fact(long long n, long long p, long long &e) { e = 0; if (n == 0) return 1; long long res = mod_fact(n / p, p, e); e += n / p; if (n / p % 2 != 0) return res * (p - fact[n % p]) % p; return res * fact[n % p] % p; } long long lucas(long long n, long long k) { if (n < 0 || k < 0 || n < k) return 0; long long e1, e2, e3; long long a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3); if (e1 > e2 + e3) return 0; return a1 * mod_inv(a2 * a3 % p, p) % p; } const long double eps = 1e-14; const long double pi = std::acos(-1.0); pair<pair<int, int>, int> q[200007]; int v[200007], top; pair<pair<int, int>, int> st[200007], st2[200007]; long double L[200007], R[200007]; long double calc(pair<pair<int, int>, int> &x, pair<pair<int, int>, int> &y) { long double s1 = x.first.first; long double r1 = x.first.second; long double s2 = y.first.first; long double r2 = y.first.second; long double g = s1 * s2 * r1 * r2; long double k = (g / s1 - g / s2) / (g / r1 - g / r2); return k; } int chk(pair<pair<int, int>, int> &x, pair<pair<int, int>, int> &y, pair<pair<int, int>, int> &z) { long double xx = calc(x, y); long double yy = calc(z, y); if (fabs(xx - yy) < eps) return 0; if (xx < yy) return -1; else return 1; } int main() { int T = 1; while (scanf("%d", &n) != EOF) { tot = 0; if (!n) break; for (int i = 0; i < n; ++i) { int x, y; scanf("%d%d", &x, &y); q[i].first = pair<int, int>(x, y); q[i].second = i + 1; } sort(q, q + n); m = n; for (int i = 0; i < n; ++i) { while (tot > 0 && (q[i].first.second > st[tot - 1].first.second || q[i].first.first > st[tot - 1].first.first && q[i].first.second == st[tot - 1].first.second)) { --tot; v[st[tot].second] = 1; --m; } st[tot++] = q[i]; } top = 0; for (int i = 0; i < tot; ++i) { while ((top > 0 && st[i].first == st2[top - 1].first || top > 1 && chk(st[i], st2[top - 1], st2[top - 2]) < 0)) --top; st2[top++] = st[i]; if (top > 1) L[i] = calc(st[i], st2[top - 2]); else L[i] = -((1 << 30) - 1); } top = 0; for (int i = tot - 1; i >= 0; --i) { while ((top > 0 && st[i].first == st2[top - 1].first || top > 1 && chk(st[i], st2[top - 1], st2[top - 2]) > 0)) --top; st2[top++] = st[i]; if (top > 1) R[i] = calc(st[i], st2[top - 2]); else R[i] = 0; } for (int i = 0; i < tot; ++i) { if (!(L[i] < R[i] || fabs(L[i] - R[i]) < eps)) v[st[i].second] = 1, --m; } for (int i = 1, cnt = 0; i <= n; ++i) { if (!v[i]) { ++cnt; printf("%d%c", i, " \n"[cnt == m]); } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; long long ccw(pair<long long, long long> a, pair<long long, long long> b, pair<long long, long long> c) { long long ret = 0; ret += b.first * c.first * a.second * (c.second - b.second); ret += c.first * a.first * b.second * (a.second - c.second); ret += a.first * b.first * c.second * (b.second - a.second); return ret; } map<pair<long long, long long>, int> M; int r[MAXN]; int s[MAXN]; pair<long long, long long> p[MAXN]; pair<long long, long long> h[MAXN]; int main(void) { int n; scanf("%d", &n); set<pair<long long, long long> > S; for (int i = (0); i < (n); ++i) { scanf("%d%d", &r[i], &s[i]); S.insert({r[i], s[i]}); } int m = 0; for (auto it : S) p[m++] = it; auto cmp = [&](pair<long long, long long> a, pair<long long, long long> b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; }; sort(p, p + m, cmp); int top = 0; for (int i = (0); i < (m); ++i) { while (top >= 2 && ccw(h[top - 2], h[top - 1], p[i]) < 0) --top; h[top++] = p[i]; } while (top >= 2 && h[top - 1].second <= h[top - 2].second) --top; int start = 0; while (start + 1 < top && h[start].first == h[start + 1].first) ++start; for (int i = (start); i < (top); ++i) M[h[i]] = 1; for (int i = (0); i < (n); ++i) if (M[{r[i], s[i]}]) printf("%d ", i + 1); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-12; inline int cmp(double a, double b) { return (a < b - EPS) ? -1 : ((a > b + EPS) ? 1 : 0); } struct Point { double x, y; int id; Point(double x = 0.0, double y = 0.0, int id = 0) : x(x), y(y), id(id) {} Point operator+(Point a) { return Point(x + a.x, y + a.y); } Point operator-(Point a) { return Point(x - a.x, y - a.y); } Point operator*(double k) { return Point(x * k, y * k); } Point operator/(double k) { return Point(x / k, y / k); } double operator*(Point a) { return x * a.x + y * a.y; } double operator%(Point a) { return x * a.y - y * a.x; } int cmp(Point q) const { if (int t = ::cmp(x, q.x)) return t; return ::cmp(y, q.y); } bool operator>(Point q) const { return cmp(q) > 0; } bool operator<(Point q) const { return cmp(q) < 0; } bool operator==(Point q) const { return cmp(q) == 0; } bool operator>=(Point q) const { return cmp(q) >= 0; } bool operator<=(Point q) const { return cmp(q) <= 0; } bool operator!=(Point q) const { return cmp(q) != 0; } Point conj() { return Point(x, -y); } double norm() { return x * x + y * y; } double len() { return sqrt(norm()); } Point rotate(double alpha) { double cosa = cos(alpha), sina = sin(alpha); return Point(x * cosa - y * sina, x * sina + y * cosa); } }; double cross(Point p, Point q) { return p.x * q.y - p.y * q.x; } double area2(Point a, Point b, Point c) { return cross(a, b) + cross(b, c) + cross(c, a); } int ccw(Point a, Point b, Point c) { double t = cross(b - a, c - a); if (fabs(t) < EPS) return 0; else if (t < 0) return -1; else return 1; } void ConvexHull(vector<Point> &pts) { sort(pts.begin(), pts.end()); pts.erase(unique(pts.begin(), pts.end()), pts.end()); vector<Point> up, dn; for (int i = 0; i < pts.size(); i++) { while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) >= 0) up.pop_back(); while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) <= 0) dn.pop_back(); up.push_back(pts[i]); dn.push_back(pts[i]); } pts = dn; for (int i = (int)up.size() - 2; i >= 1; i--) pts.push_back(up[i]); } int bit[10111]; const int MN = 200111; bool can[MN]; void update(int u, int val) { while (u <= 10000) { bit[u] = max(bit[u], val); u += ((u) & (-(u))); } } int get(int u) { int res = 0; while (u > 0) { res = max(res, bit[u]); u -= ((u) & (-(u))); } return res; } pair<int, int> input[MN]; int main() { ios ::sync_with_stdio(false); int n; while (scanf("%d", &n) == 1) { vector<Point> a; memset(bit, 0, sizeof bit); for (int i = (1), _b = (n); i <= _b; i++) { int x, y; scanf("%d%d", &x, &y); a.push_back(Point(1.0 / x, 1.0 / y, i)); input[i] = make_pair(10001 - x, y); update(input[i].first, input[i].second); } for (int i = (1), _b = (n); i <= _b; i++) { if (get(input[i].first - 1) >= input[i].second) can[i] = false; else if (get(input[i].first) > input[i].second) can[i] = false; else can[i] = true; } ConvexHull(a); set<int> res; int sz = a.size(); Point O(0, 0, 0); for (int i = 0, _a = (sz); i < _a; i++) { Point y = a[i]; Point x = a[(i - 1 + sz) % sz]; Point xx = a[(i - 2 + sz + sz) % sz]; Point z = a[(i + 1) % sz]; Point zz = a[(i + 2) % sz]; if (ccw(x, y, z) * ccw(x, y, O) <= 0 && ccw(x, y, xx) * ccw(x, y, O) <= 0) res.insert(a[i].id); if (ccw(y, z, x) * ccw(y, z, O) <= 0 && ccw(y, z, zz) * ccw(y, z, O) <= 0) res.insert(a[i].id); } set<pair<int, int> > all; for (int x : res) if (can[x]) all.insert(input[x]); for (int i = (1), _b = (n); i <= _b; i++) if (all.count(input[i])) cout << i << ' '; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef double ld; struct info { complex<ld> p; int id; bool operator<(const info &o) const { if (p.real() != o.p.real()) return p.real() < o.p.real(); return p.imag() < o.p.imag(); } bool operator==(const info &o) const { return p == o.p; } }; ld cross(complex<ld> a, complex<ld> b) { return imag(conj(a) * b); } ld cross(info a, info b, info c) { return cross(b.p - a.p, c.p - a.p); } const ld eps = 1e-22; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vector<info> a(n); for (auto &i : a) { int x, y; cin >> x >> y; i.p = {(ld)1.0 / x, (ld)1.0 / y}; i.id = &i - &a[0]; } map<info, vector<int>> mp; for (auto i : a) mp[i].push_back(i.id); vector<info> ans; sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); for (auto i : a) { while (ans.size() >= 2 && cross(ans.end()[-2], ans.end()[-1], i) < -eps) ans.pop_back(); ans.push_back(i); } while (ans.size() >= 2 && (ans.end()[-1].p - ans.end()[-2].p).imag() > -eps) ans.pop_back(); vector<int> pos; for (auto i : ans) for (auto j : mp[i]) pos.push_back(j); sort(pos.begin(), pos.end()); for (auto i : pos) cout << i + 1 << " "; return 0; }
#include <bits/stdc++.h> using namespace std; int n; map<pair<int, int>, vector<int> > M; pair<int, int> a[222222]; vector<int> ans; bool bad(int a, int b, int c, int d, int e, int first) { long long xx = 1LL * (b - d) * (e - c) * a * first; long long yy = 1LL * (d - first) * (c - a) * b * e; return xx > yy; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); M[make_pair(x, y)].push_back(i); a[i] = make_pair(x, y); } sort(a, a + n); n = unique(a, a + n) - a; int an = 0; for (int i = 0; i < n; i++) { while (an > 0 && a[an - 1].second <= a[i].second) { --an; } a[an++] = a[i]; } n = an; reverse(a, a + n); an = 0; for (int i = 0; i < n; i++) { while (an > 1 && bad(a[i].first, a[i].second, a[an - 1].first, a[an - 1].second, a[an - 2].first, a[an - 2].second)) { --an; } a[an++] = a[i]; } n = an; for (int i = 0; i < n; i++) { for (__typeof(M[a[i]].begin()) it = M[a[i]].begin(); it != M[a[i]].end(); ++it) { ans.push_back(*it); } } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) { if (i > 0) { putchar(' '); } printf("%d", ans[i] + 1); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, vis[N], ans[N]; vector<int> vec; struct pos { int bh, sbh; long long x, y; } p[N], st[N], tmp; bool cmp(pos a, pos b) { return (a.x == b.x) ? a.y > b.y : a.x > b.x; } long double check(pos a, pos b) { return (long double)a.x * b.x * (b.y - a.y) / (b.x - a.x) / a.y / b.y; } int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &p[i].x), scanf("%lld", &p[i].y), p[i].bh = i; sort(p + 1, p + n + 1, cmp); for (int i = 1; i <= n; i++) p[i].sbh = i; int top = 1; st[1] = p[1]; long long maxy = st[1].y; for (int i = 2; i <= n; i++) (p[i].y <= maxy) ? vis[i] = 1 : maxy = p[i].y; for (int i = 2; i <= n; i++) { if (vis[i] || check(p[i], st[top]) > 0) continue; while (top > 1 && check(p[i], st[top]) < check(st[top - 1], st[top])) top--; st[++top] = p[i]; } for (int i = 1; i <= top; i++) { ans[st[i].bh] = 1; for (int j = st[i].sbh + 1; j <= n; j++) { if (p[j].x != st[i].x || p[j].y != st[i].y) break; ans[p[j].bh] = 1; } } for (int i = 1; i <= n; i++) if (ans[i]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; int ans[1111111], U, tans[1111111]; int N; map<pair<int, int>, int> m; int M = 0; vector<int> v[1111111]; pair<int, int> c[1111111]; long double s(int A, int B, int C) { return (((long double)1.0) / c[B].first - ((long double)1.0) / c[A].first) * (((long double)1.0) / c[C].second - ((long double)1.0) / c[A].second) - (((long double)1.0) / c[B].second - ((long double)1.0) / c[A].second) * (((long double)1.0) / c[C].first - ((long double)1.0) / c[A].first); } void convex_hull() { sort(c, c + N); U = 0; for (int i = 0; i < (N); i++) { while ((U && c[tans[U - 1]].second <= c[i].second) || (U > 1 && s(i, tans[U - 1], tans[U - 2]) < -1e-15)) U--; tans[U] = i; ans[U++] = m[c[i]]; } } vector<int> t; int main(int argc, char *argv[]) { int M; scanf("%d", &M); for (int i = 0; i < (M); i++) { scanf("%d%d", &c[N].first, &c[N].second); pair<int, int> p = c[N]; if (!m.count(p)) m[p] = N++; v[m[p]].push_back(i); } convex_hull(); for (int i = 0; i < (U); i++) t.insert(t.end(), v[ans[i]].begin(), v[ans[i]].end()); sort(t.begin(), t.end()); for (int i = 0; i < (t.size()); i++) { if (i) printf(" "); printf("%d", t[i] + 1); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; int id; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read(int id) { int s, b; scanf("%d%d", &s, &b); x = 1000000.0 / s; y = 1000000.0 / b; this->id = id; } }; const double eps = 1e-16; int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); } Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); } bool operator<(const Point& a, const Point& b) { return a.x < b.x || (dcmp(a.x - b.x) == 0 && a.y < b.y); } bool operator==(const Point& a, const Point& b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double Length(Point A) { return sqrt(Dot(A, A)); } double Angle(Point A, Point B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); } struct Line { Point v, p; Line() {} Line(Point v, Point p) { this->v = v; this->p = p; } Point point(double t) { return v + p * t; } }; Point Rotate(Point A, double rad) { return Point(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad)); } Point AngleBisector(Point p, Point v1, Point v2) { double rad = Angle(v1, v2); return Rotate(v1, dcmp(Cross(v1, v2)) * 0.5 * rad); } bool LineCoincide(Point p1, Point p2, Point p3) { return dcmp(Cross(p2 - p1, p3 - p1)) == 0; } bool LineParallel(Point v, Point w) { return Cross(v, w) == 0; } bool LineVertical(Point v, Point w) { return Dot(v, w) == 0; } Point GetLineIntersection(Point P, Point v, Point Q, Point w) { Point u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } double DistanceToLine(Point P, Point A, Point B) { Point v1 = B - A, v2 = P - A; return fabs(Cross(v1, v2)) / Length(v1); } double DistanceToSegment(Point P, Point A, Point B) { if (A == B) return Length(P - A); Point v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(Dot(v1, v2)) < 0) return Length(v2); else if (dcmp(Dot(v1, v3)) > 0) return Length(v3); else return fabs(Cross(v1, v2)) / Length(v1); } Point GetLineProjection(Point P, Point A, Point B) { Point v = B - A; return A + v * (Dot(v, P - A) / Dot(v, v)); } bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0; } bool SegmentProperIntersection2(Point a1, Point a2, Point b1, Point b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return max(a1.x, a2.x) >= min(b1.x, b2.x) && max(b1.x, b2.x) >= min(a1.x, a2.x) && max(a1.y, a2.y) >= min(b1.y, b2.y) && max(b1.y, b2.y) >= min(a1.y, a2.y) && dcmp(c1) * dcmp(c2) <= 0 && dcmp(c3) * dcmp(c4) <= 0; } bool OnSegment(Point p, Point a1, Point a2) { return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0; } double PolygonArea(Point* p, int n) { double area = 0; for (int i = 1; i < n - 1; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]); return area / 2; } int isPointInPolygon(Point o, Point* p, int n) { int wn = 0; for (int i = 0; i < n; i++) { if (OnSegment(o, p[i], p[(i + 1) % n])) return -1; int k = dcmp(Cross(p[(i + 1) % n] - p[i], o - p[i])); int d1 = dcmp(p[i].y - o.y); int d2 = dcmp(p[(i + 1) % n].y - o.y); if (k > 0 && d1 <= 0 && d2 > 0) wn++; if (k < 0 && d2 <= 0 && d1 > 0) wn--; } if (wn != 0) return 1; return 0; } const int N = 200005; int to[N]; int ConvexHull(Point* p, int n, Point* ch) { sort(p, p + n); int m = 0; memset(to, -1, sizeof(to)); for (int i = 0; i < n; i++) { to[i] = i; if (i && p[i] == p[i - 1]) { to[i] = to[i - 1]; continue; } while (m > 1 && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) < 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n - 2; i >= 0; i--) { while (m > k && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) < 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m; } int n; Point p[N], ch[N * 2]; int vis[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) p[i].read(i + 1); int m = ConvexHull(p, n, ch); double Min = 1e18; for (int i = 0; i < m; i++) Min = min(Min, ch[i].y); for (int i = 0; i < m; i++) { vis[ch[i].id] = 1; if (dcmp(Min - ch[i].y) == 0) break; } for (int i = 0; i < n; i++) if (vis[p[to[i]].id]) vis[p[i].id] = 1; for (int i = 1; i <= n; i++) if (vis[i]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; struct Node { int x, y, idx; } p[200005]; bool che(Node A, Node B, Node C) { return 1ll * (C.x - B.x) * (A.y - B.y) * C.y * A.x < 1ll * (A.x - B.x) * (C.y - B.y) * A.y * C.x; } Node v[200005]; bool cmp(Node A, Node B) { return A.x < B.x || A.x == B.x && A.y < B.y; } int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &p[i].x, &p[i].y); p[i].idx = i; } sort(p + 1, p + n + 1, cmp); int tail = 0; for (int i = 1; i <= n; i++) { while (1 <= tail && v[tail].y <= p[i].y) tail--; while (1 < tail && che(p[i], v[tail], v[tail - 1])) tail--; v[++tail] = p[i]; } set<pair<int, int> > q; for (int i = 1; i <= tail; i++) q.insert(make_pair(v[i].x, v[i].y)); vector<int> ans; for (int i = 1; i <= n; i++) if (q.count(make_pair(p[i].x, p[i].y))) ans.push_back(p[i].idx); sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; struct xd { double x, y; int idx; inline bool operator<(const xd& b) const { return x != b.x ? x < b.x : y < b.y; } inline bool operator==(const xd& b) const { return x == b.x && y == b.y; } } all[200005]; int stk[200005], top; bool ans[200005]; double cross_z(xd o, xd a, xd b) { return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); } int main() { int N; while (~scanf("%d", &(N))) { int x, y; for (int i = 0; i < (N); ++i) { scanf("%d%d", &(x), &(y)); all[i].x = 1. / x, all[i].y = 1. / y; all[i].idx = i; } sort(all, all + N); top = 0; for (int i = 0; i < (N); ++i) { if (i == 0 || all[i].x != all[i - 1].x) { while (top >= 2 && cross_z(all[stk[top - 2]], all[stk[top - 1]], all[i]) < -1e-20) --top; stk[top++] = i; } } while (top >= 2 && all[stk[top - 2]].y <= all[stk[top - 1]].y) --top; memset(ans, false, sizeof(ans)); for (int i = 0; i < (top); ++i) ans[all[stk[i]].idx] = true; for (int i = 1; i < N; ++i) if (ans[all[i - 1].idx] && all[i] == all[i - 1]) ans[all[i].idx] = true; for (int i = 0; i < (N); ++i) if (ans[i]) printf("%d ", i + 1); putchar('\n'); } return 0; }
#include <bits/stdc++.h> using namespace std; using db = long double; const db eps = 1e-12; const int N = 220000; struct pt { int x, y; pt(int x = 0, int y = 0) : x(x), y(y) {} }; long long vect(pt p, pt p1, pt p2) { return 1ll * (p1.x - p.x) * (p2.y - p.y) * p2.x * p1.y - 1ll * (p2.x - p.x) * (p1.y - p.y) * p1.x * p2.y; } vector<pt> cv(vector<pt> vec) { if (vec.size() <= 1) return vec; int n = vec.size(), k = 0; vector<pt> ch(n + 2); for (int i = 0; i < n; ch[k++] = vec[i++]) while (k >= 2 && vect(ch[k - 2], ch[k - 1], vec[i]) < 0) --k; while (k >= 2 && ch[k - 2].y >= ch[k - 1].y) --k; ch.resize(k); return ch; } map<pair<int, int>, vector<int>> M; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int s, r; cin >> s >> r; M[make_pair(s, r)].push_back(i + 1); } vector<pt> vec; for (auto t : M) { vec.emplace_back(t.first.first, t.first.second); } reverse(vec.begin(), vec.end()); auto ret = cv(vec); set<int> ids; for (auto t : ret) { for (int x : M[make_pair(t.x, t.y)]) ids.insert(x); } for (int i : ids) cout << i << ' '; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; struct Point { long long x, y; bool operator<(const Point &p) const { if (x != p.x) return x > p.x; else return y > p.y; } } pt[maxn]; int stk[maxn], stnum; set<pair<long long, long long> > has; bool check(Point a, Point b, Point c) { return c.x * b.y * (b.x - a.x) * (a.y - c.y) < b.x * c.y * (a.x - c.x) * (b.y - a.y); } void convex(int n) { int i, j; stnum = 0; for (i = 0; i < n; i++) { if (stnum > 0 && pt[i].y <= pt[stk[stnum - 1]].y) continue; while (stnum > 1 && check(pt[stk[stnum - 1]], pt[stk[stnum - 2]], pt[i])) stnum--; stk[stnum++] = i; } while (stnum > 1 && pt[stk[stnum - 1]].y <= pt[stk[stnum - 2]].y) stnum--; for (i = 0; i < stnum - 1; i++) if (pt[stk[i]].x != pt[stk[i + 1]].x) break; for (; i < stnum; i++) has.insert(make_pair(pt[stk[i]].x, pt[stk[i]].y)); } long long a[maxn], b[maxn]; int main() { int n, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%I64d %I64d", &a[i], &b[i]); pt[i].x = a[i]; pt[i].y = b[i]; } sort(pt, pt + n); convex(n); for (i = 0; i < n; i++) { if (has.find(make_pair(a[i], b[i])) != has.end()) printf("%d ", i + 1); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int n; set<pair<pair<int, int>, int> > st; pair<int, int> s[300005]; void init() { scanf("%d", &n); } vector<pair<pair<int, int>, int> > v, t; vector<int> ans; set<pair<int, int> > aset; void process() { st.insert(pair<pair<int, int>, int>(pair<int, int>(0, 100000), -1)); st.insert(pair<pair<int, int>, int>(pair<int, int>(100000, 0), -1)); int a, b; for (int i = 0; i < n; i++) { scanf("%d%d", &a, &b); s[i] = pair<int, int>(a, b); auto ptr = st.lower_bound(pair<pair<int, int>, int>(pair<int, int>(a, b), 100000)); ptr--; while (ptr != st.begin() && ptr->first.second <= b) { auto tmp = ptr; ptr--; st.erase(tmp); } ptr++; if (ptr->first.second >= b) continue; st.insert(pair<pair<int, int>, int>(pair<int, int>(a, b), i + 1)); } for (__typeof((st).begin()) it = (st).begin(); it != (st).end(); it++) { if (it->second != -1) v.push_back(*it); } for (int i = 0; i < (int)v.size(); i++) { pair<int, int> tmp = v[i].first; while (t.size() >= 2) { pair<int, int> t0 = t[t.size() - 1].first, t1 = t[t.size() - 2].first; if ((long long)t1.first * (t0.second - t1.second) * (t0.first * tmp.second - tmp.first * t0.second) > (long long)tmp.first * (tmp.second - t0.second) * (t1.first * t0.second - t0.first * t1.second)) t.pop_back(); else break; } t.push_back(v[i]); } for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) aset.insert(it->first); for (int i = 0; i < n; i++) { if (aset.count(s[i])) printf("%d ", i + 1); } puts(""); } int main() { init(); process(); return 0; }
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > s; pair<long long, long long> a[300000], b[300000]; int num = 0, n, p[300000], A[300000], B[300000], cnt = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> A[i] >> B[i], a[i] = pair<long long, long long>(A[i], B[i]); sort(a + 1, a + n + 1); int Min = -1; for (int i = n; i >= 1; i--) if (a[i].second > Min) Min = a[i].second, b[++num] = a[i]; reverse(b + 1, b + num + 1); for (int i = 1; i <= num; i++) { pair<long long, long long> u = b[i]; while (cnt > 1 && ((b[p[cnt]].first - b[p[cnt - 1]].first) * (b[p[cnt]].second - u.second) * u.first * b[p[cnt - 1]].second < (b[p[cnt - 1]].second - b[p[cnt]].second) * (u.first - b[p[cnt]].first) * b[p[cnt - 1]].first * u.second)) cnt--; p[++cnt] = i; } for (int i = 1; i <= cnt; i++) s.insert(b[p[i]]); for (int i = 1; i <= n; i++) if (s.count(pair<long long, long long>(A[i], B[i]))) cout << i << ' '; cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; struct Point { long long x, y; bool operator<(const Point &p) const { if (x != p.x) return x > p.x; else return y > p.y; } bool operator==(const Point &p) const { return x == p.x && y == p.y; } } pt[maxn]; int stk[maxn], stnum; set<pair<long long, long long> > has; bool check(Point a, Point b, Point c) { return c.x * b.y * (b.x - a.x) * (a.y - c.y) < b.x * c.y * (a.x - c.x) * (b.y - a.y); } bool check2(Point a, Point b, Point c) { cout << a.x << " " << a.y << " " << b.x << " " << b.y << " " << c.x << " " << c.y << endl; cout << c.x * b.y * (b.x - a.x) * (a.y - c.y) << " " << b.x * c.y * (a.x - c.x) * (b.y - a.y) << endl; cout << c.x * b.y * (b.x - a.x) * (a.y - c.y) - b.x * c.y * (a.x - c.x) * (b.y - a.y) << endl; return c.x * b.y * (b.x - a.x) * (a.y - c.y) < b.x * c.y * (a.x - c.x) * (b.y - a.y); } void convex(int n) { int i, j; stnum = 0; for (i = 0; i < n; i++) { while (stnum > 1 && check(pt[stk[stnum - 1]], pt[stk[stnum - 2]], pt[i])) stnum--; stk[stnum++] = i; } while (stnum > 1 && pt[stk[stnum - 1]].y <= pt[stk[stnum - 2]].y) stnum--; for (i = 0; i < stnum - 1; i++) if (pt[stk[i]].x != pt[stk[i + 1]].x) break; for (i = 0; i < stnum; i++) { has.insert(make_pair(pt[stk[i]].x, pt[stk[i]].y)); } } long long a[maxn], b[maxn]; int main() { int n, tn, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%I64d %I64d", &a[i], &b[i]); pt[i].x = a[i]; pt[i].y = b[i]; } sort(pt, pt + n); tn = unique(pt, pt + n) - pt; convex(tn); for (i = 0; i < n; i++) { if (has.find(make_pair(a[i], b[i])) != has.end()) { printf("%d ", i + 1); } } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-15; const int N = 200005; struct Node { double x, y; int id; Node() {} Node(double x, double y, int id) : x(x), y(y), id(id) {} bool operator<(const Node &a) const { return x < a.x; } bool operator==(const Node &a) const { return fabs(x - a.x) < eps && fabs(y - a.y) < eps; } }; Node nd[N]; int Stack[N], scnt; int Equal[N], ecnt; double gety(int i, int j) { return nd[i].y - nd[j].y; } double getx(int i, int j) { return nd[i].x - nd[j].x; } int sgn(double x) { if (fabs(x) < eps) return 0; if (x > 0) return 1; return -1; } vector<int> res; int main() { int n, x, y; while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) { scanf("%d%d", &x, &y); nd[i] = Node(1.0 / x, 1.0 / y, i); } sort(nd + 1, nd + n + 1); scnt = ecnt = 0; for (int i = 1; i <= n; i++) { if (scnt == 0) Stack[scnt++] = i; else if (scnt && nd[Stack[scnt - 1]] == nd[i]) Equal[ecnt++] = i; else { if (scnt && sgn(nd[i].y - nd[Stack[scnt - 1]].y) >= 0) continue; while (scnt && sgn(nd[i].x - nd[Stack[scnt - 1]].x) == 0 && sgn(nd[i].y - nd[Stack[scnt - 1]].y) < 0) { scnt--; while (ecnt && nd[Stack[scnt]] == nd[Equal[ecnt - 1]]) ecnt--; } while (scnt >= 2) { double dx1 = getx(i, Stack[scnt - 1]); double dy1 = gety(i, Stack[scnt - 1]); double dx2 = getx(Stack[scnt - 1], Stack[scnt - 2]); double dy2 = gety(Stack[scnt - 1], Stack[scnt - 2]); if (dy2 * dx1 > dy1 * dx2) { scnt--; while (ecnt && nd[Stack[scnt]] == nd[Equal[ecnt - 1]]) ecnt--; } else break; } Stack[scnt++] = i; } } res.clear(); for (int i = 0; i < scnt; i++) res.push_back(nd[Stack[i]].id); for (int i = 0; i < ecnt; i++) res.push_back(nd[Equal[i]].id); sort(res.begin(), res.end()); for (int i = 0; i < scnt + ecnt; i++) printf("%d ", res[i]); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace ::std; const long long maxn = 2e5 + 500; const long double eps = 1e-9; const long long inf = 1e15; pair<long long, long long> a[maxn]; pair<pair<long long, long long>, long long> b[maxn]; set<pair<long double, long long> > st; long long nextt[maxn]; bool hazf[maxn]; bool mom[maxn]; bool ans[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long m; cin >> m; for (long long i = 0; i < m; i++) { cin >> a[i].first >> a[i].second; a[i].first = (-inf / a[i].first); a[i].second = (-inf / a[i].second); b[i].first = a[i]; b[i].second = i; } sort(a, a + m); sort(b, b + m); nextt[m - 2] = m - 1; for (long long i = m - 2; i > 0; i--) { if (a[i].second > a[nextt[i]].second) { nextt[i - 1] = i; } else { hazf[i] = 1; nextt[i - 1] = nextt[i]; } } { long long i = 0; if (!(a[i].second > a[nextt[i]].second)) { hazf[0] = 1; } } for (long long p = 0; p < m - 1; p++) { if (!hazf[p]) { st.insert(make_pair((((long double)a[nextt[p]].first - a[p].first) / ((long double)a[p].second - a[nextt[p]].second) - eps * p), p)); } } long long maxx = m - 1; mom[maxx] = 1; while (st.size() > 0) { pair<long long, long long> v = (*(st.begin())); st.erase(st.begin()); if (!hazf[v.second]) { long long p = v.second; if (nextt[p] == maxx) { hazf[maxx] = 1; maxx = p; } else { hazf[nextt[p]] = 1; nextt[p] = nextt[nextt[p]]; st.insert( make_pair(((long double)a[nextt[p]].first - a[p].first) / ((long double)a[p].second - a[nextt[p]].second) - eps * p, p)); } mom[maxx] = 1; } } nextt[m - 2] = m - 1; for (long long i = m - 2; i > 0; i--) { if (a[i].second == a[nextt[i]].second) { if (a[i].first == a[nextt[i]].first) { mom[i] = mom[nextt[i]]; } } if (a[i].second > a[nextt[i]].second) { nextt[i - 1] = i; } else { hazf[i] = 1; nextt[i - 1] = nextt[i]; } } { long long i = 0; if (a[i].second == a[nextt[i]].second && a[i].first == a[nextt[i]].first) { mom[i] = mom[nextt[i]]; } } for (long long i = 0; i < m; i++) { if (mom[i]) { ans[b[i].second] = 1; } } for (long long i = 0; i < m; i++) { if (ans[i]) { cout << i + 1 << ' '; } } }
#include <bits/stdc++.h> using namespace std; int n; struct node { int s, r, no; } xx[500001], dance[500001], fire[500001]; bool cmp(node x, node y) { return x.s > y.s || (x.s == y.s && x.r > y.r); } int S[500001]; int ans[500001]; int mal = 0; int k; int q; bool yes[500001]; double eps = 1e-6; int h, t; int X[10001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &xx[i].s, &xx[i].r); for (int i = 1; i <= n; i++) xx[i].no = i; sort(xx + 1, xx + n + 1, cmp); for (int i = 1; i <= n; i++) { if (mal > xx[i].r) continue; if (mal == xx[i].r && q == xx[i].s) { dance[++k] = xx[i]; continue; } if (q == xx[i].s) continue; if (mal == xx[i].r) continue; { dance[++k] = xx[i]; mal = xx[i].r; q = xx[i].s; } } h = 1; fire[++t] = dance[1]; for (int i = 2; i <= k; i++) { if (h <= t && dance[i].r <= fire[t].r) continue; while (h < t) { long long s1 = fire[t - 1].s, s2 = fire[t].s, r1 = fire[t - 1].r, r2 = fire[t].r; long long s3 = dance[i].s, r3 = dance[i].r; long long k1 = (s3 - s2) * (r1 - r2) * r3 * s1; long long k2 = (s1 - s2) * (r3 - r2) * r1 * s3; if (k1 < k2) t--; else break; } fire[++t] = dance[i]; } int xxx = 0; for (int i = 1; i <= t; i++) { X[fire[i].s] = fire[i].r; } for (int i = 1; i <= n; i++) { if (X[xx[i].s] == xx[i].r) ans[++xxx] = xx[i].no; } sort(ans + 1, ans + xxx + 1); for (int i = 1; i <= xxx; i++) cout << ans[i] << " "; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T &a, T b) { return (a > b) ? (a = b, true) : false; } template <class T> inline bool maxeq(T &a, T b) { return (a < b) ? (a = b, true) : false; } const int maxn = (int)2e5 + 10; ; const int base = 1000 * 1000 * 1000; struct BigInteger { int d[10000], len; bool operator<(BigInteger other) const { if (len != other.len) return len < other.len; for (int i = len - 1; i >= (int)(0); i--) { if (d[i] < other.d[i]) return true; else if (d[i] > other.d[i]) return false; } return false; } BigInteger(long long val) { len = 0; memset(d, 0, 10000 * sizeof(int)); while (val > 0) { d[len] = val % base; val /= base; len++; } } BigInteger() { BigInteger(0ll); } BigInteger(const BigInteger &b) { len = b.len; for (int i = 0; i < b.len; i++) d[i] = b.d[i]; } static BigInteger fromStr(char *s, BigInteger &r) { r.len = 0; for (int i = (int)strlen(s); i > 0; i -= 9) { s[i] = 0; r.d[r.len++] = atoi(i >= 9 ? s + i - 9 : s); } while (r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger add(BigInteger &b) { BigInteger r(b); int carry = 0; for (int i = 0; i < (((r.len) > (len)) ? (r.len) : (len)) || carry; i++) { if (i == r.len) r.d[r.len++] = 0; r.d[i] += carry + (i < len ? d[i] : 0); carry = r.d[i] >= base; if (carry) r.d[i] -= base; } return r; } BigInteger add(long long b) { BigInteger t(b); return add(t); } BigInteger subtract(const BigInteger &b, int sh = 0) { BigInteger r(*this), c(b); if (sh > 0) { for (int i = c.len - 1; i >= 0; i--) c.d[i + sh] = c.d[i]; for (int i = 0; i < sh; i++) c.d[i] = 0; c.len += sh; } int carry = 0; for (int i = 0; i < c.len || carry; i++) { r.d[i] -= carry + (i < c.len ? c.d[i] : 0); carry = r.d[i] < 0; if (carry) r.d[i] += base; } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger multiply(int val) { BigInteger r(*this); int carry = 0; for (int i = 0; i < r.len || carry; i++) { if (i == r.len) r.d[r.len++] = 0; long long cur = carry + (long long)(r.d[i]) * val; r.d[i] = int(cur % base); carry = int(cur / base); } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger multiply(const BigInteger &b) const { BigInteger r(0); r.len = len + b.len; for (int i = 0; i < len; i++) for (int j = 0, carry = 0; j < b.len || carry; j++) { long long cur = r.d[i + j] + (long long)d[i] * (j < b.len ? b.d[j] : 0) + carry; r.d[i + j] = int(cur % base); carry = int(cur / base); } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger divide(int val, int &rem) { BigInteger r(*this); rem = 0; for (int i = r.len - 1; i >= 0; i--) { long long cur = r.d[i] + (long long)rem * base; r.d[i] = int(cur / val); rem = int(cur % val); } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } int findBin(BigInteger &rem, BigInteger &b, int sp) { int down = 0, up = base; BigInteger c; while (up - 1 > down) { c = b.multiply((up + down) / 2); int cm = abscmp(rem, c, sp); if (cm == 1) down = (down + up) / 2; if (cm == -1) up = (down + up) / 2; if (cm == 0) { up = (down + up) / 2; down = up; } } c = b.multiply((up + down) / 2); if (abscmp(rem, c, 0) > 0) rem = rem.subtract(c, sp); else { c = c.subtract(rem, sp); rem = c; } return (up + down) / 2; } BigInteger divide(BigInteger &d, BigInteger &rem) { rem = 0; BigInteger res = 0; int c = abscmp(d); if (c == 0) { res.d[0] = 1; res.len = 1; return res; } if (c < 0) { rem = *this; return res; } rem = *this; int sp = len - d.len; if (abscmp(*this, d, sp) < 0) sp--; res.len = sp + 1; while (sp >= 0) { res.d[sp] = findBin(rem, d, sp); sp--; } return res; } int abscmp(const BigInteger &other, int sh = 0) { if (len > other.len + sh) return 1; if (len < other.len + sh) return -1; for (int i = other.len - 1; i >= 0; i--) if (d[i + sh] > other.d[i]) return 1; else if (d[i + sh] < other.d[i]) return -1; for (int i = 0; i < sh; i++) if (d[i] > 0) return 1; return 0; } int abscmp(const BigInteger &a, const BigInteger &b, int sh = 0) { if (a.len > b.len + sh) return 1; if (a.len < b.len + sh) return -1; for (int i = b.len - 1; i >= 0; i--) if (a.d[i + sh] > b.d[i]) return 1; else if (a.d[i + sh] < b.d[i]) return -1; for (int i = 0; i < sh; i++) if (a.d[i] > 0) return 1; return 0; } BigInteger pow(int val) { BigInteger r = 1, a = *this; while (val > 0) if ((val & 1) == 0) { a = a.multiply(a); val >>= 1; } else { r = r.multiply(a); --val; } return r; } int cmp(BigInteger &other) { return 0; } BigInteger sqrt() { BigInteger r = 0; r.len = (len + 1) / 2; int cur = r.len - 1; while (cur >= 0) { int up = base - 1, down = 0, v, c = 0; while (up > down) { v = (up + down) >> 1; r.d[cur] = v; c = r.multiply(r).abscmp(*this); if (c > 0) up = v - 1; else if (c < 0) down = v + 1; else break; } while (c < 0) { r.d[cur]++; c = r.multiply(r).abscmp(*this); } while (c > 0) { r.d[cur]--; if (r.multiply(r).abscmp(*this) <= 0) { break; } } cur--; } return r; } BigInteger gcd(BigInteger &other) { BigInteger a(*this), b(other), tmp; while (b.len != 0) { a.divide(b, tmp); a = b; b = tmp; } return a; } }; BigInteger operator+(BigInteger &a, BigInteger &b) { BigInteger r = a.add(b); return r; } BigInteger operator-(BigInteger &a, BigInteger &b) { BigInteger r = a.subtract(b); return r; } BigInteger operator*(const BigInteger &a, const BigInteger &b) { BigInteger r = a.multiply(b); return r; } BigInteger operator/(BigInteger &a, int b) { int rem = 0; BigInteger r = a.divide(b, rem); return r; } BigInteger operator/(BigInteger &a, BigInteger &b) { BigInteger rem = 0; BigInteger r = a.divide(b, rem); return r; } int operator%(BigInteger &a, int b) { int rem = 0; if (b >= base) return a.d[a.len - 1]; else a.divide(b, rem); return rem; } BigInteger operator%(BigInteger &a, BigInteger &b) { BigInteger rem = 0; a.divide(b, rem); return rem; } BigInteger operator^(BigInteger &a, int b) { int rem = 0; BigInteger r = a.pow(b); return r; } basic_ostream<char> &operator<<(basic_ostream<char> &out, const BigInteger &b) { short digs[9]; if (b.len == 0) out << 0; else { for (int i = b.len - 1; i >= 0; i--) { int t = b.d[i], k = 0; for (int j = 8; j >= 0; j--) { digs[j] = t % 10; t /= 10; if (t == 0 && k == 0) k = j; } if (i != b.len - 1) k = 0; for (int j = k; j < 9; j++) out << digs[j]; } } return out; } basic_istream<char> &operator>>(basic_istream<char> &in, BigInteger &b) { char s[10000 * 9 + 1]; in >> s; BigInteger::fromStr(s, b); return in; } bool check(BigInteger &a, int p) { BigInteger tmp(a); int rem; while (p > 0) { tmp = tmp.divide(2, rem); if (rem) return false; p--; } return true; } struct pt { int x, y, id; bool operator<(const pt &a) const { return (x != a.x ? x > a.x : y > a.y); } void input(int _id) { id = _id; cin >> x >> y; } } num[maxn]; vector<pt> stk; inline int sgn(int a) { if (!a) return 0; return (a < 0 ? -1 : 1); } inline bool cross(pt &a, pt &b, pt &c, pt &d) { int sgn1 = sgn(c.x - d.x) * sgn(a.y - b.y); int sgn2 = sgn(a.x - b.x) * sgn(c.y - d.y); BigInteger t1 = abs(c.x - d.x), t2 = abs(a.y - b.y), t3 = abs(a.x * b.x), t4 = abs(d.y * c.y); BigInteger t5 = abs(a.x - b.x), t6 = abs(c.y - d.y), t7 = abs(c.x * d.x), t8 = abs(a.y * b.y); BigInteger A = (t1 * t2 * t3 * t4), B = (t5 * t6 * t7 * t8); if (sgn1 != sgn2) return sgn1 < sgn2; return ((long double)1 / b.x - (long double)1 / a.x) * ((long double)1 / d.y - (long double)1 / c.y) - ((long double)1 / b.y - (long double)1 / a.y) * ((long double)1 / d.x - (long double)1 / c.x) > 1e-25; return A < B; return true; } inline bool check(pt &a, pt &b, pt &c) { return cross(b, a, b, c); } void add(pt a) { if (!stk.empty()) { pt b = stk.back(); if (a.x == b.x && b.y == a.y) { return; } if (a.y <= b.y) return; } if (stk.size() < 2) { stk.push_back(a); return; } int f = true; do { pt x = stk[stk.size() - 2], y = stk.back(); if ((x.x == y.x && x.y == y.y) || check(x, y, a)) stk.pop_back(); else f = false; } while (f && stk.size() >= 2); stk.push_back(a); } bool cmp(const pt &a, const pt &b) { return a.id < b.id; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < (int)(n); i++) num[i].input(i + 1); sort(num, num + n); for (int i = 0; i < (int)(n); i++) { add(num[i]); } set<pair<int, int> > st; for (int i = 0; i < (int)(stk.size()); i++) st.insert(make_pair(stk[i].x, stk[i].y)); sort(num, num + n, cmp); for (int i = 0; i < (int)(n); i++) { if (st.count(make_pair(num[i].x, num[i].y))) cout << num[i].id << " "; } }
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const long long linf = 1ll << 60; const double dinf = 1e60; template <typename T> inline void scf(T &x) { bool f = 0; x = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') { f = 1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } if (f) x = -x; return; } template <typename T1, typename T2> void scf(T1 &x, T2 &y) { scf(x); return scf(y); } template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); } template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); } inline char mygetchar() { char c = getchar(); while (c == ' ' || c == '\n') c = getchar(); return c; } template <typename T> void chkmax(T &x, const T &y) { if (y > x) x = y; return; } template <typename T> void chkmin(T &x, const T &y) { if (y < x) x = y; return; } const int N = 2e5 + 100; struct point { long long x, y; bool operator<(const point &a) const { return make_pair(x, y) < make_pair(a.x, a.y); } bool operator==(const point &a) const { return make_pair(x, y) == make_pair(a.x, a.y); } } a[N], b[N]; int n, stk[N], top; set<point> all; void TZL() { scf(n); for (int i = (1); i <= (n); ++i) { long long x, y; scf(x, y); a[i].x = x; a[i].y = y; b[i].x = x; b[i].y = y; } sort(b + 1, b + n + 1, [&](point a, point b) { return a.x == b.x ? a.y > b.y : a.x > b.x; }); return; } bool check(int i, int j, int k) { point a = b[i], b = ::b[j], c = ::b[k]; return a.x * a.y * c.y * b.x + a.y * b.x * b.y * c.x + a.x * b.y * c.x * c.y > a.x * a.y * c.x * b.y + a.x * b.x * b.y * c.y + a.y * b.x * c.x * c.y; } void RANK1() { stk[top++] = 1; for (int i = (2); i <= (n); ++i) if (b[i].y > b[stk[top - 1]].y) { while (top > 1 && check(stk[top - 2], stk[top - 1], i)) --top; stk[top++] = i; } for (int i = 0; i < (top); ++i) all.insert(b[stk[i]]); for (int i = (1); i <= (n); ++i) if (all.find(a[i]) != all.end()) printf("%d ", i); return; } int main() { TZL(); RANK1(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct point_comp { bool operator()(const complex<double> &a, const complex<double> &b) const { if (a.real() == b.real()) return a.imag() < b.imag(); return a.real() < b.real(); } } mycomp; inline double cross(const complex<double> &a, const complex<double> &b) { return imag(conj(a) * b); } inline double cross(const complex<double> &c, const complex<double> &a, const complex<double> &b) { return cross(a - c, b - c); } vector<complex<double> > ConvexHull(vector<complex<double> > &P) { sort(P.begin(), P.end(), mycomp); int n = P.size(); if (n < 3) return P; int sz = 0; vector<complex<double> > H(2 * n); for (int i = 0; i < n; i++) { while (sz >= 2 && cross(H[sz - 2], H[sz - 1], P[i]) <= 0) { --sz; } H[sz++] = P[i]; } for (int i = n - 2, k = sz + 1; i >= 0; --i) { while (sz >= k && cross(H[sz - 2], H[sz - 1], P[i]) <= 0) { --sz; } H[sz++] = P[i]; } H.resize(sz - 1); return H; } int main() { int n; scanf("%d", &n); vector<complex<double> > P(n); map<complex<double>, vector<int>, point_comp> ind; int sz = 0; for (int i = 0; i < n; i++) { double s, r; scanf("%lf%lf", &s, &r); complex<double> pt = complex<double>(1.0 / s, 1.0 / r); if (!ind.count(pt)) P[sz++] = pt; ind[pt].push_back(i + 1); } P.resize(sz); vector<complex<double> > H = ConvexHull(P); vector<int> ans; int cur = 0; do { vector<int> &ref = ind[H[cur]]; ans.insert(ans.end(), ref.begin(), ref.end()); cur++; } while (cur < H.size() && H[cur - 1].imag() > H[cur].imag()); sort(ans.begin(), ans.end()); for (int x : ans) printf("%d ", x); return 0; }
#include <bits/stdc++.h> using namespace std; void read(int &x) { x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); } const long double eps = 1e-8; int n, s[300010], tot; struct Node { int a, b, id; bool operator<(const Node &x) const { return (a < x.a && b <= x.b) || (a <= x.a && b < x.b); } bool operator==(const Node &x) const { return a == x.a && b == x.b; } } d[300010]; Node p[300010], q[300010]; long double slope(Node i, Node j) { return (i.b - j.b) * 1.0 / (i.a - j.a) / i.b / j.b * i.a * j.a; } inline int cmp(Node x, Node y) { return x.a ^ y.a ? x.a > y.a : x.b ^ y.b ? x.b > y.b : x.id < y.id; } vector<int> v[300010]; bool acc[300010]; int main() { read(n); for (register int i = 1; i <= n; ++i) read(d[i].a), read(d[i].b), d[i].id = i, acc[i] = true; sort(d + 1, d + n + 1, cmp); for (register int i = 1; i <= n; ++i) { if (!tot) s[++tot] = i, p[tot] = (Node){d[i].a, d[i].b, d[i].id}; else { int u = s[tot]; if (d[i] == d[u]) v[d[u].id].push_back(i), acc[d[i].id] = false; else if (d[i] < d[u]) acc[d[i].id] = false; else s[++tot] = i, p[tot] = (Node){d[i].a, d[i].b, d[i].id}; } } int head = 0, tail = 1; q[1] = p[1]; for (register int i = 2; i <= tot; ++i) { while (head + 1 < tail && slope(q[tail - 1], q[tail]) > slope(q[tail - 1], p[i])) acc[q[tail].id] = false, --tail; q[++tail] = p[i]; } for (register int i = 1; i <= n; ++i) if (acc[i]) { printf("%d ", i); int tot = v[i].size(); for (int j = 0; j ^ tot; ++j) acc[d[v[i][j]].id] = true; } }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; constexpr long long mod = 1000000007; const long long INF = mod * mod; const double eps = 1e-16; const double pi = acosl(-1.0); long long mod_pow(long long x, long long n, long long m = mod) { if (n < 0) { long long res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m) x %= m; if (x < 0) x += m; long long res = 1; while (n) { if (n & 1) res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { long long n; modint() : n(0) { ; } modint(long long m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((long long)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, long long n) { if (n == 0) return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } long long inv(long long a, long long p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } modint operator/=(modint& a, modint b) { a = a / b; return a; } const int max_n = 1 << 10; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } modint combP(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[a - b]; } double dot(pair<double, double> a, pair<double, double> b) { return a.first * b.first + a.second * b.second; } double cross(pair<double, double> a, pair<double, double> b) { return a.first * b.second - a.second * b.first; } double norm(pair<double, double> a) { return sqrtl(a.first * a.first + a.second * a.second); } pair<double, double> operator+(const pair<double, double>& a, const pair<double, double>& b) { return {a.first + b.first, a.second + b.second}; } pair<double, double> operator-(const pair<double, double>& a, const pair<double, double>& b) { return {a.first - b.first, a.second - b.second}; } pair<double, double> operator-=(pair<double, double>& a, const pair<double, double> b) { a = a - b; return a; } double abs(pair<double, double> a) { return norm(a); } pair<double, double> operator*(const pair<double, double>& a, const double& b) { return {a.first * b, a.second * b}; } pair<double, double> operator/(const pair<double, double>& a, const double& b) { return {a.first / b, a.second / b}; } struct Line { pair<double, double> a, b; }; struct Circle { pair<double, double> p; double r; }; int ccw(pair<double, double> a, pair<double, double> b, pair<double, double> c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; if (cross(b, c) < -eps) return -1; if (dot(b, c) < 0) return 2; if (norm(b) < norm(c)) return -2; return 0; } void solve() { int n; cin >> n; vector<pair<double, double> > p(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; p[i] = {1 / (double)x, 1 / (double)y}; } vector<pair<double, double> > cop = p; sort((p).begin(), (p).end()); vector<pair<double, double> > vp; for (int i = 0; i < p.size(); i++) { if (i > 0 && p[i - 1].first == p[i].first) continue; if (vp.size() && vp.back().second <= p[i].second) continue; int len = vp.size(); while (len >= 2 && ccw(vp[len - 2], vp[len - 1], p[i]) == -1) { vp.pop_back(); len--; } vp.push_back(p[i]); } vector<int> ans; for (int i = 0; i < cop.size(); i++) { int id = lower_bound((vp).begin(), (vp).end(), cop[i]) - vp.begin(); if (id < vp.size() && vp[id] == cop[i]) { ans.push_back(i); } } for (int i = 0; i < ans.size(); i++) { if (i > 0) cout << " "; cout << ans[i] + 1; } cout << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; }; long long cross(const Point &a, const Point &b, const Point &c) { return a.y * c.x * (a.x - b.x) * (b.y - c.y) - a.x * c.y * (a.y - b.y) * (b.x - c.x); } Point p[10004]; Point cv[10004]; vector<int> id[10004]; int ans[200004], ansTop(-1); void add(vector<int> &all) { for (int i = 0; i < all.size(); ++i) ans[++ansTop] = all[i]; } int main() { for (int i = 1; i <= 10000; ++i) p[i].x = (long long)i; int n, maxY; scanf(" %d", &n); for (int i = 1, x, y; i <= n; ++i) { scanf(" %d%d", &x, &y); if (p[x].y == y) id[x].push_back(i); else if (p[x].y < y) { p[x].y = y; id[x].clear(); id[x].push_back(i); } if (y > maxY) maxY = y; } int top = -1; for (int i = 10000; i > 0; --i) { if (p[i].y == 0LL) continue; while (top > 0 && cross(cv[top - 1], cv[top], p[i]) < 0) --top; cv[++top] = p[i]; if (p[i].y == maxY) break; } add(id[cv[0].x]); for (int i = 1; i <= top; ++i) { add(id[cv[i].x]); if (cv[i].y == maxY) break; } sort(&ans[0], &ans[ansTop + 1]); for (int i = 0; i <= ansTop; ++i) printf("%d ", ans[i]); printf("\n"); }
#include <bits/stdc++.h> using namespace std; pair<pair<long long, long long>, long long> pts[200005]; int n; int cnt[200005]; pair<long long, long long> intersect(pair<long long, long long> a, pair<long long, long long> b) { return make_pair(a.first * (b.second - a.second), a.second * (b.first - a.first)); } bool check(pair<long long, long long> a, pair<long long, long long> b) { return (a.first * b.second > a.second * b.first); } map<pair<long long, long long>, vector<int> > q; void Readinput() { int x, y; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); scanf("%d", &y); pts[i] = pair<pair<long long, long long>, long long>( pair<long long, long long>(x, y), i); q[pts[i].first].push_back(i); } } void solve() { int i, j; vector<int> s; int ansx = 0, ansy = 0; sort(pts, pts + n); for (i = 0; i < n; i++) { while (!s.empty()) { int t = s.back(); if (pts[t].first.second <= pts[i].first.second) s.pop_back(); else break; } s.push_back(i); } vector<int> v; v = s; s.clear(); for (int i = 0; i < v.size(); i++) { while (s.size() > 1 && check(intersect(pts[s[s.size() - 2]].first, pts[s.back()].first), intersect(pts[v[i]].first, pts[s.back()].first))) s.pop_back(); s.push_back(v[i]); } v.clear(); for (i = 0; i < s.size(); i++) { for (j = 0; j < q[pts[s[i]].first].size(); j++) v.push_back(q[pts[s[i]].first][j]); } sort(v.begin(), v.end()); for (i = 0; i < v.size(); i++) printf("%d ", v[i] + 1); printf("\n"); } int main() { Readinput(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; struct Node { int a, b; bool operator<(const Node &o) const { if (b == o.b) return a > o.a; return b < o.b; } double ins(Node o) { return ((double)a * b * o.b - (double)b * o.a * o.b) / ((double)o.a * o.b * a - (double)a * b * o.a); } } t[N], dt[N]; int n, st[N]; map<pair<int, int>, bool> Map; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &t[i].a, &t[i].b); dt[i] = t[i]; } sort(t + 1, t + n + 1); int top = 0; for (int i = 1; i <= n; i++) { if (i > 1 && t[i - 1].b == t[i].b) continue; while (top > 1 && t[st[top - 1]].ins(t[st[top]]) - t[st[top]].ins(t[i]) > 1e-20) top--; st[++top] = i; } for (int i = 1; i <= top; i++) if (top == i || t[st[i + 1]].ins(t[st[i]]) > 1e-20) Map[make_pair(t[st[i]].a, t[st[i]].b)] = 1; for (int i = 1; i <= n; i++) if (Map[make_pair(dt[i].a, dt[i].b)]) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } long long N; long long S[222222], R[222222]; bool ushi(pair<long long, long long> a, pair<long long, long long> b, pair<long long, long long> c) { return (a.first * c.first - b.first * c.first) * (a.second * b.second - b.second * c.second) >= (a.second * c.second - b.second * c.second) * (a.first * b.first - b.first * c.first); } signed main() { scanf("%lld", &N); for (long long i = 0; i < (N); i++) scanf("%lld%lld", &S[i], &R[i]); vector<pair<long long, long long> > v; for (long long i = 0; i < (N); i++) v.push_back(pair<long long, long long>(S[i], R[i])); sort((v).begin(), (v).end()); reverse((v).begin(), (v).end()); vector<pair<long long, long long> > u; for (auto p : v) { if (u.size() && u.back().second >= p.second) continue; u.push_back(p); } reverse((u).begin(), (u).end()); vector<pair<long long, long long> > st; for (long long i = (long long)u.size() - 1; i >= 0; i--) { while (st.size() >= 2 && !ushi(st[st.size() - 2], st.back(), u[i])) st.pop_back(); st.push_back(u[i]); } sort((st).begin(), (st).end()); vector<long long> ans; for (long long i = 0; i < (N); i++) { if (binary_search((st).begin(), (st).end(), pair<long long, long long>(S[i], R[i]))) ans.push_back(i); } for (long long i = 0; i < (ans.size()); i++) { if (i) printf(" "); printf("%lld", ans[i] + 1); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; const int Nmax = 200005, Vmax = 10005; const double eps = 1e-10; struct Point { int x, y; int pos; bool operator<(const Point& other) const { if (x != other.x) return x > other.x; return y > other.y; } bool operator==(const Point& other) const { return x == other.x && y == other.y; } }; Point A[Nmax], Hull[Nmax]; int dist(const Point& a, const Point& b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } Point O; double slope(const Point& a, const Point& b) { if (a.x == b.x) return 1e99; return ((double)(a.y - b.y) * a.x * b.x) / ((double)(a.x - b.x) * a.y * b.y); } struct cmp { bool operator()(const Point& a, const Point& b) const { double s1 = slope(O, a), s2 = slope(O, b); if (abs(s1 - s2) < eps) return dist(O, a) < dist(O, b); return s1 + eps < s2; } }; long long crossProduct(const Point& o, const Point& a, const Point& b) { return (1LL * a.y * b.x * o.x * o.y - 1LL * a.y * o.x * b.x * b.y - 1LL * o.y * b.x * a.x * a.y + 1LL * a.x * b.x * a.y * b.y) - (1LL * a.x * b.y * o.x * o.y - 1LL * a.x * o.y * b.x * b.y - 1LL * o.x * b.y * a.x * a.y + 1LL * a.x * b.x * a.y * b.y); } int convexHull(int N) { int pos = 1; for (int i = 2; i <= N; ++i) if (A[i] < A[pos]) pos = i; swap(A[1], A[pos]); O = A[1]; sort(A + 2, A + N + 1, cmp()); int maxy = 0; for (int i = 1; i <= N; ++i) maxy = max(maxy, A[i].y); pos = 1; Hull[1] = A[1]; if (Hull[1].y == maxy) return 1; for (int i = 2; i <= N; ++i) { if (A[i] == Hull[pos]) continue; while (pos >= 2 && crossProduct(Hull[pos - 1], Hull[pos], A[i]) < 0) --pos; Hull[++pos] = A[i]; if (A[i].y == maxy) return pos; } return pos; } int main() { ios::sync_with_stdio(false); int N; cin >> N; for (int i = 1; i <= N; ++i) { cin >> A[i].x >> A[i].y; A[i].pos = i; } int M = convexHull(N); vector<int> ans; set<Point> hull; for (int i = 1; i <= M; ++i) hull.insert(Hull[i]); for (int i = 1; i <= N; ++i) if (hull.count(A[i]) != 0) ans.push_back(A[i].pos); sort(ans.begin(), ans.end()); for (int p : ans) cout << p << ' '; cout << endl; }
#include <bits/stdc++.h> using namespace std; int n; struct point { point() : x(0), y(0) {} point(int x, int y) : x(x), y(y) {} int x, y; bool operator<(const point &rhs) const { return make_pair(-x, -y) < make_pair(-rhs.x, -rhs.y); } }; long long ccw(const point &a, const point &b, const point &c) { long long x1 = b.x - a.x, y1 = b.y - a.y; long long x2 = c.x - a.x, y2 = c.y - a.y; return c.x * b.y * x1 * y2 - b.x * c.y * x2 * y1; } int main() { scanf("%d", &n); vector<point> dat; set<point> un; int maxy = 0; for (int i = 0; i < n; i++) { point p; int x, y; scanf("%d%d", &x, &y); p.x = x; p.y = y; un.insert(p); dat.push_back(p); maxy = max(maxy, y); } vector<point> cv; for (auto val : un) { while (cv.size() >= 2 && ccw(cv[cv.size() - 2], cv[cv.size() - 1], val) < 0) { cv.pop_back(); } cv.push_back(val); } vector<int> ans; set<pair<int, int>> possible; for (int i = 0; i < cv.size(); i++) { possible.insert(make_pair(cv[i].x, cv[i].y)); if (cv[i].y == maxy) break; } for (int i = 0; i < n; i++) { if (possible.count(make_pair(dat[i].x, dat[i].y))) { ans.push_back(i); } } for (int i = 0; i < ans.size(); i++) { printf("%d%c", ans[i] + 1, " \n"[i + 1 == ans.size()]); } return 0; }
#include <bits/stdc++.h> using namespace std; const int _ = 1e6 + 20; double X, Y; struct point { double x, y; int id; double slope() { return y / x; } point friend operator-(point x, point y) { return (point){x.x - y.x, x.y - y.y}; } int friend operator==(point x, point y) { return abs(x.y - y.y) < 1e-9; } } a[_], q[_]; int cmp(point x, point y) { if (x.x == y.x) return x.y > y.y; return x.x < y.x; } int n, p[_], fa[_], k = 1, top = 1; int pd(point x, point y, point z) { return (y - x).slope() > (z - y).slope(); } int fi(int x) { return fa[x] ? fa[x] = fi(fa[x]) : x; } int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { int x, y; cin >> x >> y; a[i].x = (double)1 / x; a[i].y = (double)1 / y; a[i].id = i; } sort(a + 1, a + n + 1, cmp); while (a[k].x == a[k + 1].x && k < n) { if (a[k].y == a[k + 1].y) fa[a[k].id] = a[k + 1].id; ++k; } X = a[k].x; Y = a[k].y; q[1] = a[k]; for (int i = k + 1; i <= n; ++i) { while (a[i].x == a[i + 1].x) { if (a[i].y == a[i + 1].y) fa[a[i].id] = a[i + 1].id; ++i; } while (top > 1 && pd(q[top - 1], q[top], a[i])) --top; q[++top] = a[i]; } for (int i = 1; i <= top; ++i) { if (i != 1 && (q[i].y >= q[i - 1].y)) break; p[q[i].id] = 1; } for (int i = 1; i <= n; ++i) if (p[fi(i)]) cout << i << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; struct item { int s, t, v, tmp; } d[maxn]; int pos[maxn], lnk[maxn]; int stx[maxn], sty[maxn]; int n; void sort(int fi, int la) { if (fi >= la) return; int i = fi, j = la, g = d[(i + j) >> 1].tmp; while (i <= j) { while (d[i].tmp < g) i++; while (g < d[j].tmp) j--; if (i <= j) swap(d[i], d[j]), i++, j--; } sort(fi, j); sort(i, la); } #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int int_inf = 0x3f3f3f3f; const long long ll_inf = 0x3f3f3f3f3f3f3f3f; const int INT_INF = (int)((1ll << 31) - 1); const double double_inf = 1e30; const double eps = 1e-14; inline int readint() { int x; scanf("%d", &x); return x; } inline int readstr(char *s) { scanf("%s", s); return strlen(s); } struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} }; Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); } Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); } bool operator<(const Point &a, const Point &b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int dcmp(double x) { if (abs(x) < eps) return 0; return x < 0 ? -1 : 1; } bool operator==(const Point &a, const Point &b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double Len(Point A) { return sqrt(Dot(A, A)); } double Angle(Point A, Point B) { return acos(Dot(A, B) / Len(A) / Len(B)); } double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); } Point Rotate(Point A, double rad) { return Point(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad)); } Point Normal(Point A) { double L = Len(A); return Point(-A.y / L, A.x / L); } void Normallize(Point &A) { double L = Len(A); A.x /= L, A.y /= L; } Point GetLineIntersection(Point P, Point v, Point Q, Point w) { Point u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } double DistanceToLine(Point P, Point A, Point B) { Point v1 = B - A, v2 = P - A; return abs(Cross(v1, v2)) / Len(v1); } double DistanceToSegment(Point P, Point A, Point B) { if (A == B) return Len(P - A); Point v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(Dot(v1, v2)) < 0) return Len(v2); else if (dcmp(Dot(v1, v3)) > 0) return Len(v3); else return abs(Cross(v1, v2)) / Len(v1); } Point GetLineProjection(Point P, Point A, Point B) { Point v = B - A; return A + v * (Dot(v, P - A) / Dot(v, v)); } bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0; } bool OnSegment(Point p, Point a1, Point a2) { return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0; } Point GetBisector(Point v, Point w) { Normallize(v), Normallize(w); return Point((v.x + w.x) / 2, (v.y + w.y) / 2); } bool OnLine(Point p, Point a1, Point a2) { Point v1 = p - a1, v2 = a2 - a1; double tem = Cross(v1, v2); return dcmp(tem) == 0; } struct Line { Point p; Point v; Point point(double t) { return Point(p.x + t * v.x, p.y + t * v.y); } Line(Point p, Point v) : p(p), v(v) {} }; struct Circle { Point c; double r; Circle(Point c, double r) : c(c), r(r) {} Circle(int x, int y, int _r) { c = Point(x, y); r = _r; } Point point(double a) { return Point(c.x + cos(a) * r, c.y + sin(a) * r); } }; int GetLineCircleIntersection(Line L, Circle C, double &t1, double &t2, std::vector<Point> &sol) { double a = L.v.x, b = L.p.x - C.c.x, c = L.v.y, d = L.p.y - C.c.y; double e = a * a + c * c, f = 2 * (a * b + c * d), g = b * b + d * d - C.r * C.r; double delta = f * f - 4 * e * g; if (dcmp(delta) < 0) return 0; if (dcmp(delta) == 0) { t1 = t2 = -f / (2 * e); sol.push_back(L.point(t1)); return 1; } t1 = (-f - sqrt(delta)) / (2 * e); sol.push_back(L.point(t1)); t2 = (-f + sqrt(delta)) / (2 * e); sol.push_back(L.point(t2)); return 2; } double angle(Point v) { return atan2(v.y, v.x); } int GetCircleCircleIntersection(Circle C1, Circle C2, std::vector<Point> &sol) { double d = Len(C1.c - C2.c); if (dcmp(d) == 0) { if (dcmp(C1.r - C2.r) == 0) return -1; return 0; } if (dcmp(C1.r + C2.r - d) < 0) return 0; if (dcmp(abs(C1.r - C2.r) - d) > 0) return 0; double a = angle(C2.c - C1.c); double da = acos((C1.r * C1.r + d * d - C2.r * C2.r) / (2 * C1.r * d)); Point p1 = C1.point(a - da), p2 = C1.point(a + da); sol.push_back(p1); if (p1 == p2) return 1; sol.push_back(p2); return 2; } int GetPointCircleTangents(Point p, Circle C, Point *v) { Point u = C.c - p; double dist = Len(u); if (dist < C.r) return 0; else if (dcmp(dist - C.r) == 0) { v[0] = Rotate(u, acos(-1.) / 2); return 1; } else { double ang = asin(C.r / dist); v[0] = Rotate(u, -ang); v[1] = Rotate(u, +ang); return 2; } } int GetCircleCircleTangents(Circle A, Circle B, Point *a, Point *b) { int cnt = 0; if (A.r < B.r) { std::swap(A, B); std::swap(a, b); } int d2 = (A.c.x - B.c.x) * (A.c.x - B.c.x) + (A.c.y - B.c.y) * (A.c.y - B.c.y); int rdiff = A.r - B.r; int rsum = A.r + B.r; if (d2 < rdiff * rdiff) return 0; double base = atan2(B.c.y - A.c.y, B.c.x - A.c.x); if (d2 == 0 && A.r == B.r) return -1; if (d2 == rdiff * rdiff) { a[cnt] = A.point(base); b[cnt] = B.point(base); cnt++; return 1; } double ang = acos((A.r - B.r) / sqrt(d2)); a[cnt] = A.point(base + ang); b[cnt++] = B.point(base + ang); a[cnt] = A.point(base - ang); b[cnt++] = B.point(base - ang); if (d2 == rsum * rsum) { a[cnt] = A.point(base); b[cnt++] = B.point(base + acos(-1.)); } else if (d2 > rsum * rsum) { double ang = acos((A.r + B.r) / sqrt(d2)); a[cnt] = A.point(base + ang); b[cnt++] = B.point(base + ang + acos(-1.)); a[cnt] = A.point(base - ang); b[cnt++] = B.point(base - ang + acos(-1.)); } return cnt; } Point ReadPoint() { double x, y; scanf("%lf%lf", &x, &y); return Point(x, y); } Circle ReadCircle() { double x, y, r; scanf("%lf%lf%lf", &x, &y, &r); return Circle(x, y, r); } struct Point3 { double x, y, z; Point3(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {} }; Point3 operator+(Point3 A, Point3 B) { return Point3(A.x + B.x, A.y + B.y, A.z + B.z); } Point3 operator-(Point3 A, Point3 B) { return Point3(A.x - B.x, A.y - B.y, A.z - B.z); } Point3 operator*(Point3 A, double p) { return Point3(A.x * p, A.y * p, A.z * p); } Point3 operator/(Point3 A, double p) { return Point3(A.x / p, A.y / p, A.z / p); } double Dot3(Point3 A, Point3 B) { return A.x * B.x + A.y * B.y + A.z * B.z; } double Len3(Point3 A) { return sqrt(Dot3(A, A)); } double Angle3(Point3 A, Point3 B) { return acos(Dot3(A, B) / Len3(A) / Len3(B)); } double DistanceToPlane(const Point3 &p, const Point3 &p0, const Point3 &n) { return abs(Dot3(p - p0, n)); } Point3 GetPlaneProjection(const Point3 &p, const Point3 &p0, const Point3 &n) { return p - n * Dot3(p - p0, n); } Point3 GetLinePlaneIntersection(Point3 p1, Point3 p2, Point3 p0, Point3 n) { Point3 v = p2 - p1; double t = (Dot3(n, p0 - p1) / Dot3(n, p2 - p1)); return p1 + v * t; } Point3 Cross(Point3 A, Point3 B) { return Point3(A.y * B.z - A.z * B.y, A.z * B.x - A.x * B.z, A.x * B.y - A.y * B.x); } double Area3(Point3 A, Point3 B, Point3 C) { return Len3(Cross(B - A, C - A)); } class cmpt { public: bool operator()(const int &x, const int &y) const { return x > y; } }; int num[100005], mlen, r; int gcd(int a, int b) { while (a % b != 0) a %= b, swap(a, b); return b; } int cal(int lim) { if (mlen % lim != 0) return 0; int tmp = r - lim - n / lim; if (tmp % (n / lim) != 0) return 0; tmp /= (n / lim); return tmp / n + 1; } int Rand(int x, int o) { if (!x) return 0; int tem = (int)((double)rand() / RAND_MAX * x) % x; return o ? tem + 1 : tem; } const int N = 2 * 1e5 + 5; struct Dt { double x, y; int id; Dt() {} Dt(int _x, int _y, int _id) { x = _x; y = _y; id = _id; } bool operator<(const Dt t) const { if (x == t.x) { return y < t.y; } return x < t.x; } } a[N]; priority_queue<Dt> q; int ans[N], cnt = 0; vector<int> tab[N]; double xl[N]; void gao(Dt now) { if (cnt == 0) { tab[cnt].push_back(now.id); ans[cnt++] = now.id; return; } double tmp; int pre = ans[cnt - 1]; if (now.y == a[pre].y) { if (now.x == a[pre].x) { tab[cnt - 1].push_back(now.id); return; } return; } while (cnt > 1) { pre = ans[cnt - 1]; tmp = (now.x - a[pre].x) * now.y * a[pre].y / ((a[pre].y - now.y) * a[pre].x * now.x); if (tmp < xl[pre]) { tab[cnt - 1].clear(); --cnt; } else break; } pre = ans[cnt - 1]; tmp = (now.x - a[pre].x) * now.y * a[pre].y / ((a[pre].y - now.y) * a[pre].x * now.x); xl[now.id] = tmp; tab[cnt].push_back(now.id); ans[cnt++] = now.id; } void work() { int n; double u, v; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lf%lf", &u, &v); a[i] = Dt(u, v, i); q.push(Dt(u, v, i)); } double _max = 0; while (!q.empty()) { while (!q.empty() && q.top().y < _max) { q.pop(); } if (q.empty()) break; Dt now = q.top(); q.pop(); gao(now); _max = max(_max, now.y); } int cc = 0; for (int i = 0; i < cnt; ++i) { for (int j = 0; j < tab[i].size(); ++j) { ans[cc++] = tab[i][j]; } } sort(ans, ans + cc); for (int i = 0; i < cc; ++i) { printf("%d%c", ans[i] + 1, i == cc - 1 ? '\n' : ' '); } } void data_gen() { srand(time(0)); freopen("in.txt", "w", stdout); int kases = 10; printf("%d\n", kases); while (kases--) { int sz = 2e4; int m = 1e5; printf("%d %d\n", sz, m); for (int i = (1); i <= (sz); i++) printf("%d ", Rand(100, 1)); printf("\n"); for (int i = (1); i <= (sz); i++) printf("%d ", Rand(1e9, 1)); printf("\n"); for (int i = (1); i <= (m); i++) { int l = Rand(sz, 1); int r = Rand(sz, 1); int c = Rand(1e9, 1); printf("%d %d %d %d\n", l, r, c, Rand(100, 1)); } } } struct cmpx { bool operator()(int x, int y) { return x > y; } }; int debug = 0; int m; char mt[10][10]; bool mt2[30][30]; int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; bool in_range(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); work(); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 200100; struct toc { int ind; int repx, repy; } p[MAX]; bool operator<(toc a, toc b) { if (a.repx != b.repx) return a.repx > b.repx; return a.repy > b.repy; } int Ccw(toc a, toc b, toc c) { long long tmp = (long long)b.repx * c.repx * (a.repy * c.repy - a.repy * b.repy) + (long long)a.repx * c.repx * (a.repy * b.repy - b.repy * c.repy) + (long long)a.repx * b.repx * (b.repy * c.repy - a.repy * c.repy); if (tmp < 0) return -1; if (tmp > 0) return 1; return 0; } int pocx[MAX], pocy[MAX]; map<pair<int, int>, int> M; int maxx[MAX], maxy[MAX]; int rje[MAX]; int l[MAX], r[MAX]; vector<toc> V; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &p[i].repx, &p[i].repy); pocx[i] = p[i].repx; pocy[i] = p[i].repy; maxy[p[i].repx] = max(maxy[p[i].repx], p[i].repy); maxx[p[i].repy] = max(maxx[p[i].repy], p[i].repx); p[i].ind = i; } sort(p, p + n); memset(l, -1, sizeof l); for (int i = 0; i < n; i++) { if (i && p[i - 1].repx == p[i].repx && p[i - 1].repy == p[i].repy) continue; for (; (int)V.size() > 1;) { int tmp = Ccw(V[V.size() - 2], V.back(), p[i]); if (tmp == -1) V.pop_back(); else if (tmp == 0) { l[V.back().ind] = V[V.size() - 2].ind; r[V.back().ind] = p[i].ind; V.pop_back(); } else break; } V.push_back(p[i]); } for (int i = 0; i < (int)V.size(); i++) { if (i && V[i].repx <= V[i - 1].repx && V[i].repy <= V[i - 1].repy) break; if (maxx[V[i].repy] == V[i].repx && maxy[V[i].repx] == V[i].repy) rje[V[i].ind] = 1; } for (int i = n - 1; i >= 0; i--) { int ind = p[i].ind; if (!rje[ind] && l[ind] != -1 && rje[l[ind]] && rje[r[ind]] && maxx[p[ind].repy] == p[ind].repx && maxy[p[ind].repx] == p[ind].repy) rje[ind] = 1; } for (int i = 0; i < n; i++) if (rje[i]) M[make_pair(pocx[i], pocy[i])] = 1; for (int i = 0; i < n; i++) if (rje[i] || M[make_pair(pocx[i], pocy[i])]) printf("%d ", i + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int mxN = 2e5; int n, qt; long long a[mxN], b[mxN]; vector<int> c[mxN], ans; struct tr { int first, second, i; inline bool operator<(const tr &o) const { return first == o.first ? second > o.second : first < o.first; } } trs[mxN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> trs[i].first >> trs[i].second, trs[i].i = i; sort(trs, trs + n); for (int i = 0; i < n; ++i) { if (i && trs[i].first == a[qt - 1]) { if (trs[i].second == b[qt - 1]) c[qt - 1].push_back(trs[i].i); continue; } while ( (qt >= 1 && trs[i].second >= b[qt - 1]) || (qt >= 2 && a[qt - 2] * trs[i].second * (b[qt - 2] - b[qt - 1]) * (trs[i].first - a[qt - 1]) > trs[i].first * b[qt - 2] * (b[qt - 1] - trs[i].second) * (a[qt - 1] - a[qt - 2]))) c[--qt].clear(); a[qt] = trs[i].first, b[qt] = trs[i].second; c[qt].push_back(trs[i].i); ++qt; } for (int i = 0; i < qt; ++i) for (int ci : c[i]) ans.push_back(ci); sort(ans.begin(), ans.end()); for (int ai : ans) cout << ai + 1 << " "; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T &a, T b) { return (a > b) ? (a = b, true) : false; } template <class T> inline bool maxeq(T &a, T b) { return (a < b) ? (a = b, true) : false; } const int maxn = (int)2e5 + 10; ; const int base = 1000 * 1000 * 1000; struct BigInteger { int d[10000], len; bool operator<(BigInteger other) const { if (len != other.len) return len < other.len; for (int i = len - 1; i >= (int)(0); i--) { if (d[i] < other.d[i]) return true; else if (d[i] > other.d[i]) return false; } return false; } BigInteger(long long val) { len = 0; memset(d, 0, 10000 * sizeof(int)); while (val > 0) { d[len] = val % base; val /= base; len++; } } BigInteger() { BigInteger(0ll); } BigInteger(const BigInteger &b) { len = b.len; for (int i = 0; i < b.len; i++) d[i] = b.d[i]; } static BigInteger fromStr(char *s, BigInteger &r) { r.len = 0; for (int i = (int)strlen(s); i > 0; i -= 9) { s[i] = 0; r.d[r.len++] = atoi(i >= 9 ? s + i - 9 : s); } while (r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger add(BigInteger &b) { BigInteger r(b); int carry = 0; for (int i = 0; i < (((r.len) > (len)) ? (r.len) : (len)) || carry; i++) { if (i == r.len) r.d[r.len++] = 0; r.d[i] += carry + (i < len ? d[i] : 0); carry = r.d[i] >= base; if (carry) r.d[i] -= base; } return r; } BigInteger add(long long b) { BigInteger t(b); return add(t); } BigInteger subtract(const BigInteger &b, int sh = 0) { BigInteger r(*this), c(b); if (sh > 0) { for (int i = c.len - 1; i >= 0; i--) c.d[i + sh] = c.d[i]; for (int i = 0; i < sh; i++) c.d[i] = 0; c.len += sh; } int carry = 0; for (int i = 0; i < c.len || carry; i++) { r.d[i] -= carry + (i < c.len ? c.d[i] : 0); carry = r.d[i] < 0; if (carry) r.d[i] += base; } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger multiply(int val) { BigInteger r(*this); int carry = 0; for (int i = 0; i < r.len || carry; i++) { if (i == r.len) r.d[r.len++] = 0; long long cur = carry + (long long)(r.d[i]) * val; r.d[i] = int(cur % base); carry = int(cur / base); } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger multiply(const BigInteger &b) const { BigInteger r(0); r.len = len + b.len; for (int i = 0; i < len; i++) for (int j = 0, carry = 0; j < b.len || carry; j++) { long long cur = r.d[i + j] + (long long)d[i] * (j < b.len ? b.d[j] : 0) + carry; r.d[i + j] = int(cur % base); carry = int(cur / base); } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } BigInteger divide(int val, int &rem) { BigInteger r(*this); rem = 0; for (int i = r.len - 1; i >= 0; i--) { long long cur = r.d[i] + (long long)rem * base; r.d[i] = int(cur / val); rem = int(cur % val); } while (r.len > 0 && r.d[r.len - 1] == 0) r.d[--(r.len)] = 0; return r; } int findBin(BigInteger &rem, BigInteger &b, int sp) { int down = 0, up = base; BigInteger c; while (up - 1 > down) { c = b.multiply((up + down) / 2); int cm = abscmp(rem, c, sp); if (cm == 1) down = (down + up) / 2; if (cm == -1) up = (down + up) / 2; if (cm == 0) { up = (down + up) / 2; down = up; } } c = b.multiply((up + down) / 2); if (abscmp(rem, c, 0) > 0) rem = rem.subtract(c, sp); else { c = c.subtract(rem, sp); rem = c; } return (up + down) / 2; } BigInteger divide(BigInteger &d, BigInteger &rem) { rem = 0; BigInteger res = 0; int c = abscmp(d); if (c == 0) { res.d[0] = 1; res.len = 1; return res; } if (c < 0) { rem = *this; return res; } rem = *this; int sp = len - d.len; if (abscmp(*this, d, sp) < 0) sp--; res.len = sp + 1; while (sp >= 0) { res.d[sp] = findBin(rem, d, sp); sp--; } return res; } int abscmp(const BigInteger &other, int sh = 0) { if (len > other.len + sh) return 1; if (len < other.len + sh) return -1; for (int i = other.len - 1; i >= 0; i--) if (d[i + sh] > other.d[i]) return 1; else if (d[i + sh] < other.d[i]) return -1; for (int i = 0; i < sh; i++) if (d[i] > 0) return 1; return 0; } int abscmp(const BigInteger &a, const BigInteger &b, int sh = 0) { if (a.len > b.len + sh) return 1; if (a.len < b.len + sh) return -1; for (int i = b.len - 1; i >= 0; i--) if (a.d[i + sh] > b.d[i]) return 1; else if (a.d[i + sh] < b.d[i]) return -1; for (int i = 0; i < sh; i++) if (a.d[i] > 0) return 1; return 0; } BigInteger pow(int val) { BigInteger r = 1, a = *this; while (val > 0) if ((val & 1) == 0) { a = a.multiply(a); val >>= 1; } else { r = r.multiply(a); --val; } return r; } int cmp(BigInteger &other) { return 0; } BigInteger sqrt() { BigInteger r = 0; r.len = (len + 1) / 2; int cur = r.len - 1; while (cur >= 0) { int up = base - 1, down = 0, v, c = 0; while (up > down) { v = (up + down) >> 1; r.d[cur] = v; c = r.multiply(r).abscmp(*this); if (c > 0) up = v - 1; else if (c < 0) down = v + 1; else break; } while (c < 0) { r.d[cur]++; c = r.multiply(r).abscmp(*this); } while (c > 0) { r.d[cur]--; if (r.multiply(r).abscmp(*this) <= 0) { break; } } cur--; } return r; } BigInteger gcd(BigInteger &other) { BigInteger a(*this), b(other), tmp; while (b.len != 0) { a.divide(b, tmp); a = b; b = tmp; } return a; } }; BigInteger operator+(BigInteger &a, BigInteger &b) { BigInteger r = a.add(b); return r; } BigInteger operator-(BigInteger &a, BigInteger &b) { BigInteger r = a.subtract(b); return r; } BigInteger operator*(const BigInteger &a, const BigInteger &b) { BigInteger r = a.multiply(b); return r; } BigInteger operator/(BigInteger &a, int b) { int rem = 0; BigInteger r = a.divide(b, rem); return r; } BigInteger operator/(BigInteger &a, BigInteger &b) { BigInteger rem = 0; BigInteger r = a.divide(b, rem); return r; } int operator%(BigInteger &a, int b) { int rem = 0; if (b >= base) return a.d[a.len - 1]; else a.divide(b, rem); return rem; } BigInteger operator%(BigInteger &a, BigInteger &b) { BigInteger rem = 0; a.divide(b, rem); return rem; } BigInteger operator^(BigInteger &a, int b) { int rem = 0; BigInteger r = a.pow(b); return r; } basic_ostream<char> &operator<<(basic_ostream<char> &out, const BigInteger &b) { short digs[9]; if (b.len == 0) out << 0; else { for (int i = b.len - 1; i >= 0; i--) { int t = b.d[i], k = 0; for (int j = 8; j >= 0; j--) { digs[j] = t % 10; t /= 10; if (t == 0 && k == 0) k = j; } if (i != b.len - 1) k = 0; for (int j = k; j < 9; j++) out << digs[j]; } } return out; } basic_istream<char> &operator>>(basic_istream<char> &in, BigInteger &b) { char s[10000 * 9 + 1]; in >> s; BigInteger::fromStr(s, b); return in; } bool check(BigInteger &a, int p) { BigInteger tmp(a); int rem; while (p > 0) { tmp = tmp.divide(2, rem); if (rem) return false; p--; } return true; } struct pt { int x, y, id; bool operator<(const pt &a) const { return (x != a.x ? x > a.x : y > a.y); } void input(int _id) { id = _id; cin >> x >> y; } } num[maxn]; vector<pt> stk; inline int sgn(int a) { if (!a) return 0; return (a < 0 ? -1 : 1); } inline bool cross(pt &a, pt &b, pt &c, pt &d) { int sgn1 = sgn(c.x - d.x) * sgn(a.y - b.y); int sgn2 = sgn(a.x - b.x) * sgn(c.y - d.y); BigInteger t1 = abs(c.x - d.x), t2 = abs(a.y - b.y), t3 = abs(a.x * b.x), t4 = abs(d.y * c.y); BigInteger t5 = abs(a.x - b.x), t6 = abs(c.y - d.y), t7 = abs(c.x * d.x), t8 = abs(a.y * b.y); BigInteger A = (t1 * t2 * t3 * t4), B = (t5 * t6 * t7 * t8); if (sgn1 != sgn2) return sgn1 < sgn2; return A < B; return true; } inline bool check(pt &a, pt &b, pt &c) { return cross(b, a, b, c); } void add(pt a) { if (!stk.empty()) { pt b = stk.back(); if (a.x == b.x && b.y == a.y) { return; } if (a.y <= b.y) return; } if (stk.size() < 2) { stk.push_back(a); return; } int f = true; do { pt x = stk[stk.size() - 2], y = stk.back(); if ((x.x == y.x && x.y == y.y) || check(x, y, a)) stk.pop_back(); else f = false; } while (f && stk.size() >= 2); stk.push_back(a); } bool cmp(const pt &a, const pt &b) { return a.id < b.id; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < (int)(n); i++) num[i].input(i + 1); sort(num, num + n); for (int i = 0; i < (int)(n); i++) { add(num[i]); } set<pair<int, int> > st; for (int i = 0; i < (int)(stk.size()); i++) st.insert(make_pair(stk[i].x, stk[i].y)); sort(num, num + n, cmp); for (int i = 0; i < (int)(n); i++) { if (st.count(make_pair(num[i].x, num[i].y))) cout << num[i].id << " "; } }
#include <bits/stdc++.h> using namespace std; pair<long long, long long> old[200005], a[200005], S[200005]; set<pair<long long, long long> > T; int X, Y, n, m, i; int cross(pair<long long, long long> c, pair<long long, long long> a, pair<long long, long long> b) { return (b.first * a.first - a.first * c.first) * (b.second * c.second - a.second * c.second) - (b.first * c.first - a.first * c.first) * (a.second * b.second - a.second * c.second) < 0; } const int cmp(pair<long long, long long> a, pair<long long, long long> b) { return a.first > b.first || a.first == b.first && a.second > b.second; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d%d", &X, &Y), old[i] = a[i] = make_pair(X, Y); sort(a + 1, a + n + 1, cmp); S[m = 1] = a[1]; for (i = 2; i <= n; i++) { if (a[i].second <= S[m].second) continue; for (; m >= 2 && cross(S[m - 1], S[m], a[i]); m--) ; S[++m] = a[i]; } for (i = 1; i <= m; i++) T.insert(S[i]); for (i = 1; i <= n; i++) if (T.count(old[i])) printf("%d ", i); }
#include <bits/stdc++.h> using namespace std; vector<pair<pair<long long, long long>, int> > v, v1; vector<pair<pair<long long, long long>, int> > cht; map<long long, long long> my; int c[200011] = {0}; vector<pair<long long, long long> > r; set<long long> second; bool intersection(int l1, int l2, int l3) { long long p1 = (cht[l2].first.second * cht[l3].first.first * (cht[l3].first.second - cht[l1].first.second) * (cht[l1].first.first - cht[l2].first.first)); long long p2 = (cht[l3].first.second * cht[l2].first.first * (cht[l2].first.second - cht[l1].first.second) * (cht[l1].first.first - cht[l3].first.first)); int p; if (p1 < p2) p = 1; else p = 0; return p; } void add(long long m, long long b, int i) { cht.push_back(make_pair(make_pair(m, b), i)); while (cht.size() > 2 && intersection(cht.size() - 3, cht.size() - 2, cht.size() - 1)) cht.erase(cht.end() - 2); } int main() { int i, j, n, n1; cin >> n; n1 = n; for (i = 0; i < n; i++) { long long r1, s1; cin >> s1 >> r1; r.push_back(make_pair(s1, r1)); v1.push_back(make_pair(make_pair(s1, r1), i + 1)); } sort(v1.begin(), v1.end()); for (int i = 0; i < n; i++) { while (!v.empty() && v.back().first.second <= v1[i].first.second) v.pop_back(); v.push_back(v1[i]); } n = v.size(); for (i = 0; i < n; i++) add(v[i].first.first, v[i].first.second, v[i].second); for (i = 0; i < cht.size(); i++) { c[cht[i].second] = 1; my[cht[i].first.first] = cht[i].first.second; } for (i = 0; i < n1; i++) if (c[i + 1] == 0 && my.find(r[i].first) != my.end() && my[r[i].first] == r[i].second) c[i + 1] = 1; for (i = 1; i <= n1; i++) if (c[i] == 1) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-22; struct point { int X, Y; double x, y; point() { X = Y = x = y = 0; } point(double a, double b) { x = a, y = b; } inline void init(int a, int b) { X = a, Y = b; x = 1.0 / X; y = 1.0 / Y; } inline double operator*(point p) { return x * p.y - y * p.x; } inline point operator-(point p) { return point(x - p.x, y - p.y); } inline double dis(point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } inline pair<int, int> coordinate() { return {X, Y}; } }; int n; map<pair<int, int>, vector<int> > mp; point d, l; vector<point> v; vector<point> hull; inline bool downcmp(const point& a, const point& b) { return make_pair(a.y, a.x) < make_pair(b.y, b.x); } inline bool leftcmp(const point& a, const point& b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); } inline bool anglecmp(const point& a, const point& b) { double cross = ((point)a - d) * ((point)b - d); if (fabs(cross) <= eps) return d.dis(a) < d.dis(b); return cross < eps; } int main(int argc, const char* argv[]) { ios::sync_with_stdio(0); int i; cin >> n; for (i = 1; i <= n; i++) { int a, b; cin >> a >> b, mp[{a, b}].push_back(i); } if (mp.size() == 1) { for (i = 1; i <= n; i++) cout << i << " "; cout << endl; return 0; } for (pair<pair<int, int>, vector<int> > q : mp) { pair<int, int> p = q.first; int x = p.first, y = p.second; point P; P.init(x, y), v.push_back(P); } d = *min_element(v.begin(), v.end(), downcmp); l = *min_element(v.begin(), v.end(), leftcmp); if (d.coordinate() == l.coordinate()) { for (int a : mp[d.coordinate()]) { cout << a << " "; } cout << endl; return 0; } sort(v.begin(), v.end(), anglecmp); int po = 2; for (i = 0; i < po; i++) hull.push_back(v[i]); vector<int> ans; while (po < v.size() && hull.back().coordinate() != l.coordinate()) { while (hull.size() > 1 && ((hull[hull.size() - 1] - hull[hull.size() - 2]) * (v[po] - hull[hull.size() - 2]) > eps)) hull.pop_back(); hull.push_back(v[po++]); } for (point p : hull) { for (int a : mp[p.coordinate()]) ans.push_back(a); } sort(ans.begin(), ans.end()); for (int a : ans) cout << a << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct point { double x, y, z; inline bool operator<(const point t) const { return y * t.x - x * t.y < 0; } inline point operator-(const point t) const { return (point){x - t.x, y - t.y, 0}; } }; point p[300000]; vector<int> V[300000]; int q[300000]; int i, j, n, o, t; double mx, my; inline bool cmp(point x, point y) { return x - p[0] < y - p[0]; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%lf%lf", &p[i].x, &p[i].y), p[i].x = 1 / p[i].x, p[i].y = 1 / p[i].y, p[i].z = i; p[0] = (point){0, 100000, 0}, p[n + 1] = (point){100000, 0, 0}; sort(p + 1, p + n + 1, cmp); for (i = 0; i <= n + 1; i++) { if ((i) && (p[i].x == p[q[t]].x) && (p[i].y == p[q[t]].y)) { V[t].push_back(p[i].z); continue; } for (; (t > 1) && (p[i] - p[q[t]] < p[q[t]] - p[q[t - 1]]); t--) ; t++, V[t].clear(), q[t] = i, V[t].push_back(p[i].z); } for (i = 1; i <= t; i++) for (j = 0; j < V[i].size(); j++) if (V[i][j]) o++, q[o] = V[i][j]; sort(q + 1, q + o + 1); for (i = 1; i <= o; i++) printf("%d ", q[i]); return 0; }
#include <bits/stdc++.h> using namespace std; pair<long double, long double> A[200666]; int st[200666], ind[200666]; long double val[200666]; bool comp(int i1, int i2) { return A[i1] < A[i2]; } bool eql(long double v1, long double v2) { return (v1 - v2 > -((long double)0.00000000000001) && v1 - v2 < ((long double)0.00000000000001)); } long double bs(long double vmax, pair<long double, long double> v1, pair<long double, long double> v2) { long double pos, step; for (step = 1; step <= vmax; step *= (long double)2.0) ; for (pos = 0; step > ((long double)0.0000000000000000001); step /= (long double)2.0) if (pos + step <= vmax) { long double val_1 = 1.0 / v1.first + (pos + step) / (v1.second); long double val_2 = 1.0 / v2.first + (pos + step) / (v2.second); if (val_2 < val_1 || eql(val_2, val_1)) pos += step; } return pos; } int main() { int n, i; scanf("%d", &n); for (i = 1; i <= n; ++i) { int v1, v2; scanf("%d%d", &v1, &v2); A[i].first = v1; A[i].second = v2; ind[i] = i; } sort(ind + 1, ind + n + 1, comp); int k = 1; st[1] = ind[1]; val[1] = ((long double)1000000000000000); for (i = 2; i <= n; ++i) { int l = ind[i]; while (true && k > 0) { long double v1 = 1.0 / A[st[k]].first + val[k] / (A[st[k]].second); long double v2 = 1.0 / A[l].first + val[k] / (A[l].second); if (eql(v1, v2)) break; if (v2 < v1) { --k; continue; } break; } if (k == 0) { st[++k] = l; continue; } st[++k] = l; val[k] = bs(val[k - 1], A[st[k - 1]], A[l]); } sort(st + 1, st + k + 1); for (i = 1; i <= k; ++i) cout << st[i] << " "; return 0; }
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } const int N = 3e5 + 5; int n, del[N]; int st[N], top, ok[N]; struct node { double l, r; int id; } s[N]; bool cmp(const node &a, const node &b) { return a.l == b.l ? a.r > b.r : a.l > b.l; } double cacl(node a, node b) { return a.l * b.l * (b.r - a.r) / ((b.l - a.l) * a.r * b.r); } int main() { n = read(); for (int i = 1; i <= n; i++) { s[i].l = read(); s[i].r = read(); s[i].id = i; } sort(s + 1, s + n + 1, cmp); double maxn = -1e9; for (int i = 1; i <= n; i++) { if (s[i].r <= maxn) del[i] = 1; else maxn = s[i].r; } st[++top] = 1; for (int i = 2; i <= n; i++) { if (del[i]) continue; while (top > 1 && cacl(s[i], s[st[top]]) < cacl(s[st[top - 1]], s[st[top]])) top--; st[++top] = i; } for (int i = 1; i <= top; i++) { ok[s[st[i]].id] = 1; int p = st[i] + 1; while (p <= n && s[p].l == s[st[i]].l && s[p].r == s[st[i]].r) ok[s[p].id] = 1, p++; } for (int i = 1; i <= n; i++) if (ok[i]) printf("%d ", i); putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch - '0' < 0 || ch - '0' > 9) { if (ch == '-') f = -1; ch = getchar(); } while (ch - '0' >= 0 && ch - '0' <= 9) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m; struct P { double x, y; int id; } p[200010], a[200010]; vector<int> v[200010], ans; bool cmp1(P a, P b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } bool dcmp(double x) { return fabs(x) < 1e-9; } int s[200010], top; double slope(P a, P b) { return (a.y - b.y) / (a.x - b.x); } int main() { n = read(); for (int i = 1; i <= n; i++) { int x = read(), y = read(); p[i].x = 1.0 / (double)x; p[i].y = 1.0 / (double)y; p[i].id = i; } sort(p + 1, p + n + 1, cmp1); a[1] = p[1]; m = 1; v[1].push_back(p[1].id); for (int i = 2; i <= n; i++) { if (fabs(p[i].x - a[m].x) > 1e-9) a[++m] = p[i]; if (dcmp(p[i].x - a[m].x) && dcmp(p[i].y - a[m].y)) v[m].push_back(p[i].id); } s[++top] = 1; for (int i = 2; i <= m; i++) { while (top > 1 && slope(a[i], a[s[top - 1]]) < slope(a[s[top]], a[s[top - 1]])) top--; s[++top] = i; } for (int j = 0; j < v[s[1]].size(); j++) ans.push_back(v[s[1]][j]); for (int i = 2; i <= top; i++) { if (slope(a[s[i]], a[s[i - 1]]) < 0) { for (int j = 0; j < v[s[i]].size(); j++) ans.push_back(v[s[i]][j]); } else break; } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]); puts(""); return 0; }
#include <bits/stdc++.h> struct str { double first; double second; int index; } x[200010]; bool cmp(str a, str b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } std::vector<str> P, St; int CCW(str A, str B, str C) { double s1 = A.first * B.second + B.first * C.second + C.first * A.second; double s2 = A.second * B.first + B.second * C.first + C.second * A.first; if (s1 > s2) return 1; if (s1 < s2) return -1; return 0; } std::map<std::pair<double, double>, std::vector<int> > M; int check[200010]; int main() { int a; scanf("%d", &a); for (int i = 1; i <= a; i++) { double b, c; scanf("%lf%lf", &b, &c); M[std::make_pair(1 / b, 1 / c)].push_back(i); x[i] = {(double)1 / b, (double)1 / c, i}; } std::sort(x + 1, x + a + 1, cmp); double max = x[1].second; P.push_back(x[1]); for (int i = 2; i <= a; i++) { if (x[i].second < max) { P.push_back(x[i]); max = x[i].second; } } if (P.size() <= 1) { std::vector<int> V = M[std::make_pair(P[0].first, P[0].second)]; for (int j = 0; j < V.size(); j++) check[V[j]] = 1; for (int i = 1; i <= a; i++) if (check[i] == 1) printf("%d ", i); return 0; } else { St.push_back(P[0]); St.push_back(P[1]); for (int i = 2; i < P.size(); i++) { while (St.size() >= 2) { str A = St[St.size() - 1]; str B = St[St.size() - 2]; if (CCW(B, A, P[i]) < 0) St.pop_back(); else break; } St.push_back(P[i]); } for (int i = 0; i < St.size(); i++) { std::vector<int> V = M[std::make_pair(St[i].first, St[i].second)]; for (int j = 0; j < V.size(); j++) check[V[j]] = 1; } for (int i = 1; i <= a; i++) if (check[i] == 1) printf("%d ", i); } }
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &x, B y) { return (x > y) ? (x = y, 1) : 0; } template <class A, class B> inline bool maxa(A &x, B y) { return (x < y) ? (x = y, 1) : 0; } int X[(200005)], Y[(200005)]; int N; set<tuple<int, int> > good; int maxY[(10005)]; int sz_S; tuple<int, int> S[(200005)]; void add_point(int x3, int y3) { while (sz_S >= 2) { int x1 = get<0>(S[sz_S - 2]), y1 = get<1>(S[sz_S - 2]); int x2 = get<0>(S[sz_S - 1]), y2 = get<1>(S[sz_S - 1]); if ((long long)y2 * x3 * (x1 - x2) * (y1 - y3) < (long long)x2 * y3 * (y1 - y2) * (x1 - x3)) { sz_S--; } else { break; } } S[sz_S++] = tuple<int, int>(x3, y3); } int main() { scanf("%d", &N); for (int(i) = 0; (i) < (N); ++(i)) { scanf("%d %d", &X[i], &Y[i]); maxa(maxY[X[i]], Y[i]); } int pre_y = 0; for (int i = (10005) - 1; i >= 1; i--) { if (maxY[i] > pre_y) { add_point(i, maxY[i]); pre_y = maxY[i]; } } for (int(i) = 0; (i) < (sz_S); ++(i)) { good.insert(S[i]); } for (int(i) = 0; (i) < (N); ++(i)) { if (good.find(tuple<int, int>(X[i], Y[i])) != good.end()) { printf("%d ", i + 1); } } return 0; }
#include <bits/stdc++.h> using namespace std; int ok[200005], n, q[200005], s[200005]; struct data { int id, a, b; } c[200005]; bool cmp(data a, data b) { if (a.a == b.a) return a.b > b.b; return a.a > b.a; } int Judge(data a, data b, data c) { long long k = 1LL * (b.a - a.a) * (c.a - b.a); if (k < 0) k = -1; else k = 1; if (1LL * (a.b - b.b) * a.a * c.b * (c.a - b.a) * k > 1LL * k * (b.b - c.b) * c.a * a.b * (b.a - a.a)) return 1; return 0; } int interisminus(data a, data b) { int x = 1, y = 1; if (a.b < b.b) x = -1; if (a.b == b.b) x = 0; if (b.a < a.a) y = -1; if (x * y != 1) return 1; return 0; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &c[i].a, &c[i].b), c[i].id = i; sort(c + 1, c + 1 + n, cmp); int r = 0; c[0].a = -1; for (int i = 1; i <= n; i++) { if (c[i].a == c[i - 1].a) continue; while (r > 1 && Judge(c[i], c[q[r]], c[q[r - 1]])) r--; q[++r] = i; } while (r > 1 && interisminus(c[q[r]], c[q[r - 1]])) r--; for (int i = 1; i <= r; i++) ok[c[q[i]].id] = 1; for (int i = 2; i <= n; i++) if (c[i].a == c[i - 1].a && c[i].b == c[i - 1].b && ok[c[i - 1].id]) ok[c[i].id] = 1; for (int i = 1; i <= n; i++) if (ok[i]) printf("%d ", i); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1001 * 201; pair<int, pair<int, vector<int> > > a[MAXN]; vector<pair<int, pair<int, int> > > v; vector<int> ans; double mn[MAXN] = {}, mx[MAXN] = {}; map<pair<int, int>, int> m; int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second.first; if (!m[{a[i].first, a[i].second.first}]) m[{a[i].first, a[i].second.first}] = i + 1; a[m[{a[i].first, a[i].second.first}] - 1].second.second.push_back(i); } sort(a, a + n); reverse(a, a + n); int mxx = -1; for (int i = 0; i < n; i++) { if (a[i].second.first > mxx) { mxx = a[i].second.first; for (auto u : a[i].second.second) v.push_back({a[i].first, {mxx, u}}); } } for (int i = 0; i < n; i++) { mx[i] = 1e10; mn[i] = -100000; } n = v.size(); for (int i = 0; i < n; i++) { double ri = v[i].first, si = v[i].second.first; for (int j = i + 1; j < n; j++) { double rj = v[j].first, sj = v[j].second.first; if (ri == rj && si == sj) continue; double x = (ri * rj * (si - sj)) / (si * sj * (rj - ri)); mx[j] = min(mx[j], x); mn[i] = max(mn[i], x); } } cout << setprecision(10); for (int i = 0; i < n; i++) if (mn[i] <= mx[i]) ans.push_back(v[i].second.second); sort(ans.begin(), ans.end()); for (auto u : ans) cout << u + 1 << ' '; }
#include <bits/stdc++.h> inline int read() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x; } const int MAXN = 300005; int n, q[MAXN], siz; bool ans[MAXN]; std::vector<int> v[MAXN]; struct Missle { double k, b; int id; friend bool operator<(Missle x, Missle y) { return x.k == y.k ? x.b < y.b : x.k > y.k; } friend bool operator==(Missle x, Missle y) { return x.k == y.k && x.b == y.b; } friend bool operator!=(Missle x, Missle y) { return x.k != y.k || x.b != y.b; } } mis[MAXN], m[MAXN]; inline double getx(int x, int y) { return (m[x].b - m[y].b) / (m[y].k - m[x].k); } int main() { n = read(); int nn = 0; for (int i = 1; i <= n; i++) { int uu = read(), vv = read(); if (uu == 0 || vv == 0) continue; mis[++nn].k = 1.0 / uu; mis[nn].b = 1.0 / vv; mis[nn].id = i; } std::swap(n, nn); std::sort(mis + 1, mis + n + 1); for (int i = 1; i <= n; i++) { if (i == 1 || mis[i] != mis[i - 1]) m[++siz] = mis[i]; v[siz].push_back(mis[i].id); } int h = 1, t = 0; for (int i = 1; i <= siz; i++) { if (i != 1 && m[i].k == m[i - 1].k) continue; while (h < t && getx(q[t], i) + 1e-14 < getx(q[t - 1], q[t])) t--; q[++t] = i; } for (int i = h; i <= t; i++) { if (i != t && getx(q[i], q[i + 1]) < 1e-14) continue; for (int j = 0; j < v[q[i]].size(); j++) ans[v[q[i]][j]] = 1; } std::swap(n, nn); for (int i = 1; i <= n; i++) if (ans[i]) printf("%d ", i); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int a[10010] = {0}; bool b[10010] = {0}; pair<int, int> q[200100]; class Line { public: int minv, cinv; }; bool operator<(Line x, Line y) { return x.minv < y.minv; } vector<Line> v; bool invalid(Line a, Line b, Line c) { long long int x1 = 1LL * (a.cinv - b.cinv) * (c.minv - b.minv) * c.cinv * a.minv; long long int x2 = 1LL * (b.cinv - c.cinv) * (b.minv - a.minv) * a.cinv * c.minv; if (x2 < x1) return 1; return 0; } int main() { int n; cin >> n; int x, y; for (int i = 1; i <= n; i++) { scanf("%d%d", &x, &y); a[x] = max(a[x], y); q[i] = pair<int, int>(x, y); } int maxi = 0; for (int i = 1; i <= 10000; i++) { if (a[i] > 0) { maxi = max(maxi, a[i]); Line l; l.minv = i; l.cinv = a[i]; v.push_back(l); } } sort(v.begin(), v.end()); stack<Line> s; for (int i = 0; i < v.size(); i++) { Line l = v[i]; s.push(l); while (1) { if (s.size() <= 2) break; Line cc = s.top(); s.pop(); Line bb = s.top(); s.pop(); Line aa = s.top(); s.pop(); if (invalid(aa, bb, cc)) { s.push(aa); s.push(cc); } else { s.push(aa); s.push(bb); s.push(cc); break; } } } vector<int> u; while (!s.empty()) { Line l = s.top(); s.pop(); u.push_back(l.minv); } reverse(u.begin(), u.end()); bool ok = 0; for (int i = 0; i < u.size(); i++) { if (ok || i == (u.size() - 1)) ok = 1; if (i != (u.size() - 1)) { if (a[u[i]] == maxi && a[u[i + 1]] != maxi) ok = 1; } if (ok) b[u[i]] = 1; } for (int i = 1; i <= n; i++) { if (b[q[i].first] && a[q[i].first] == q[i].second) cout << i << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 200000; long long x[N], y[N]; vector<int> ids[N]; int order[N]; long long cross(int a, int b, int c) { return x[c] * y[c] * (x[b] * y[a] - x[a] * y[b]); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } iota(order, order + n, 0); sort(order, order + n, [&](int a, int b) { return x[a] == x[b] ? y[a] > y[b] : x[a] > x[b]; }); vector<int> hull; for (int i = 0, j = 0; i < n; i = j) { int a = order[i]; while (hull.size() >= 2) { int b = hull[hull.size() - 1], c = hull[hull.size() - 2]; if (cross(a, c, b) + cross(b, a, c) + cross(c, b, a) >= 0) { break; } hull.pop_back(); } hull.push_back(a); while (j < n && x[order[j]] == x[a] && y[order[j]] == y[a]) { ids[a].push_back(order[j++]); } } while (hull.size() >= 2) { int a = hull[hull.size() - 1], b = hull[hull.size() - 2]; if (y[b] < y[a]) { break; } hull.pop_back(); } vector<int> ans; for (auto i : hull) { ans.insert(ans.begin(), ids[i].begin(), ids[i].end()); } sort(ans.begin(), ans.end()); for (auto i : ans) { cout << i + 1 << " "; } cout << "\n"; }
#include <bits/stdc++.h> using namespace std; using namespace std; const double eps = 1e-12; int sgn(double k) { return (k > -eps) - (k < eps); } typedef struct { double x, y; int id; } dot; dot operator-(dot a, dot b) { return (dot){a.x - b.x, a.y - b.y}; } dot operator+(dot a, dot b) { return (dot){a.x + b.x, a.y + b.y}; } dot operator*(double k, dot a) { return (dot){a.x * k, a.y * k}; } double operator*(dot a, dot b) { return a.x * b.y - a.y * b.x; } double atan2(dot a) { return atan2(a.y, a.x); } int cmp(dot a, dot b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int cmp2(dot a, dot b) { return a.id < b.id; } dot d[200514], tb[200514]; int ct, dt; int n, bad[200514]; map<pair<int, int>, int> mp; vector<int> e[200514]; int ans[200514], at; void sol() { mp.clear(); dt = 0; for (int i = 0; i < n; i++) { e[i + 1].clear(); int x, y; scanf("%d %d", &(x), &(y)); pair<int, int> pp = pair<int, int>(x, y); int t = mp[pp]; if (t) { e[t].push_back(i + 1); continue; } d[dt++] = (dot){100000.0 / x, 100000.0 / y, i + 1}; mp[pp] = i + 1; e[i + 1].push_back(i + 1); } sort(d, d + dt, cmp); int st = 0; ct = 0; for (int i = dt - 1; i >= 0; i--) { for (; ct >= 2 && sgn((tb[ct - 1] - tb[ct - 2]) * (d[i] - tb[ct - 1])) > 0; ct--) ; tb[ct++] = d[i]; } for (; ct - st >= 2 && sgn(atan2(tb[st] - tb[st + 1])) >= 0; st++) ; for (; ct - st >= 2 && sgn(atan2(tb[ct - 1] - tb[ct - 2]) - acos(-1) / 2.0) <= 0; ct++) ; at = 0; for (int i = st; i < ct; i++) { for (auto it : e[tb[i].id]) { ans[at++] = it; } } sort(ans, ans + at); for (int i = 0; i < at; i++) printf("%d ", ans[i]); puts(""); } int main() { scanf("%d", &(n)); sol(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { T ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T modinverse(T a, T M) { return bigmod(a, M - 2, M); } template <class T, class X> inline bool getbit(T a, X i) { T t = 1; return ((a & (t << i)) > 0); } template <class T, class X> inline T setbit(T a, X i) { T t = 1; return (a | (t << i)); } template <class T, class X> inline T resetbit(T a, X i) { T t = 1; return (a & (~(t << i))); } int n; pair<long long, long long> arr[200009]; vector<pair<long long, long long> > cost; int pointer; vector<long long> M, B, ind; void init() { pointer = 0; M.clear(); B.clear(); } bool bad(int l1, int l2, int l3) { return M[l3] * B[l2] * (-B[l3] + B[l1]) * (-M[l1] + M[l2]) > B[l3] * M[l2] * (-B[l2] + B[l1]) * (-M[l1] + M[l3]); } void add(long long m, long long b, int in) { M.push_back(m); B.push_back(b); ind.push_back(in); while (M.size() >= 3 && bad(M.size() - 3, M.size() - 2, M.size() - 1)) { M.erase(M.end() - 2); B.erase(B.end() - 2); ind.erase(ind.end() - 2); } } map<int, vector<int> > mp[10009]; vector<int> fnl; int main() { scanf("%d", &n); int mxf = 0, mxs = 0; for (int i = (1); i <= (n); i++) { scanf("%lld %lld", &arr[i].first, &arr[i].second); mp[arr[i].first][arr[i].second].push_back(i); mxf = max(mxf, (int)arr[i].first); mxs = max(mxs, (int)arr[i].second); } sort(arr + 1, arr + n + 1); for (int i = (1); i <= (n); i++) { while (cost.size() > 0 && cost[cost.size() - 1].second <= arr[i].second) cost.pop_back(); cost.push_back(arr[i]); } init(); for (int i = (0); i <= (cost.size() - 1); i++) { add(cost[i].second, cost[i].first, i); } for (int i = (0); i <= (ind.size() - 1); i++) { for (int j = (0); j <= (mp[cost[ind[i]].first][cost[ind[i]].second].size() - 1); j++) fnl.push_back(mp[cost[ind[i]].first][cost[ind[i]].second][j]); } sort(fnl.begin(), fnl.end()); fnl.erase(unique(fnl.begin(), fnl.end()), fnl.end()); bool flag = 0; for (int i = (0); i <= (fnl.size() - 1); i++) { if (flag) printf(" "); flag = 1; printf("%d", fnl[i]); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-22L; int sgn(long double t) { return abs(t) < EPS ? 0 : (t > 0) - (t < 0); } struct PT { long double x, y; PT(long double x = 0.0L, long double y = 0.0L) : x(x), y(y) {} PT operator-(PT o) { return {x - o.x, y - o.y}; } PT operator*(long double t) { return {x * t, y * t}; } PT operator/(long double t) { return {x / t, y / t}; } PT operator+(PT o) { return {x + o.x, y + o.y}; } }; long double dot(PT u, PT v) { return u.x * v.x + u.y * v.y; } long double cross(PT u, PT v) { return u.x * v.y - v.x * u.y; } long double orient(PT a, PT b, PT c) { return cross(b - a, c - a); } long double abs(PT p) { return hypot(p.x, p.y); } bool operator<(PT p, PT q) { int sx = sgn(p.x - q.x); return sx == 0 ? sgn(p.y - q.y) < 0 : sx < 0; } bool operator==(PT p, PT q) { return sgn(p.x - q.x) == 0 && sgn(p.y - q.y) == 0; } vector<PT> solve(vector<PT>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); int n = v.size(); vector<PT> h; int i = 0, j = 1; for (int k = 0; k < n; k++) { while (i > j && sgn(orient(h[i - 2], h[i - 1], v[k])) < 0) { h.resize(--i); } h.resize(++i, v[k]); } while (i > 1 && sgn(h[i - 1].y - h[i - 2].y) >= 0) { h.resize(--i); } return h; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector<PT> v; map<PT, vector<int> > mult; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; PT p(x, y); p.x = 1.0L / p.x; p.y = 1.0L / p.y; v.push_back(p); mult[p].push_back(i); } auto h = solve(v); vector<int> ans; for (PT& p : h) { for (int k : mult[p]) ans.push_back(k); } sort(ans.begin(), ans.end()); for (int k : ans) cout << k << ' '; }
#include <bits/stdc++.h> using namespace std; __int128 gcd(__int128 a, __int128 b) { __int128 temp; while (b) { temp = b; b = a % b; a = temp; } return a; } struct frac { __int128 x, y; frac(__int128 a = 0, __int128 b = 0) { if (b < 0) a = -a, b = -b; if (a) { __int128 g = gcd(a < 0 ? -a : a, b); a /= g; b /= g; } else b = 1; x = a, y = b; } frac(__int128 a) { x = a, y = 1; } void i128print(__int128 x) { int c = 1; if (x < 0) c = -1, x = -x; if (x == 0) cout << 0; else { stack<int> s; while (x) { s.push(x % 10); x /= 10; } if (c == -1) cout << "-"; while (!s.empty()) { cout << s.top(); s.pop(); } } } void print() { i128print(x); cout << "/"; i128print(y); cout << "\n"; } frac operator+(const frac &r) const { return frac(x * r.y + y * r.x, y * r.y); } frac operator-(const frac &r) const { return frac(x * r.y - y * r.x, y * r.y); } frac operator*(const frac &r) const { return frac(x * r.x, y * r.y); } frac operator/(const frac &r) const { return frac(x * r.y, y * r.x); } bool operator<(const frac &r) const { return x * r.y - y * r.x < 0; } bool operator>(const frac &r) const { return x * r.y - y * r.x > 0; } bool operator==(const frac &r) const { return x * r.y - y * r.x == 0; } }; const int maxn = 4e5 + 233; frac x[maxn], y[maxn]; int ord[maxn]; int n; int s[maxn]; int top; bool Cross(frac x1, frac y1, frac x2, frac y2) { return x1 * y2 - x2 * y1 > frac(0, 1); } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i += 1) { int a, b; cin >> a >> b; x[i] = frac(1, a); y[i] = frac(1, b); ord[i] = i; } sort(ord + 1, ord + n + 1, [&](int a, int b) { if (x[a] == x[b]) return y[a] < y[b]; return x[a] < x[b]; }); int cnt = 0; for (int i = 1; i <= n; i++) { int j = i; while (j <= n && x[ord[j]] == x[ord[i]]) j++; ord[++cnt] = ord[i]; i = j - 1; } for (int o = 1; o <= cnt; o += 1) { int i = ord[o]; while (top > 1 && Cross(x[i] - x[s[top]], y[i] - y[s[top]], x[s[top]] - x[s[top - 1]], y[s[top]] - y[s[top - 1]])) { top--; } s[++top] = i; } vector<int> tmp; tmp.emplace_back(s[1]); for (int i = 2; i <= top; i += 1) { if (y[s[i]] > y[s[i - 1]] || (x[s[i]] > x[s[i - 1]] && y[s[i]] == y[s[i - 1]])) { break; } tmp.emplace_back(s[i]); } vector<int> res; for (int i = 1; i <= n; i += 1) { ord[i] = i; } sort(ord + 1, ord + n + 1, [&](int a, int b) { if (x[a] == x[b]) return y[a] < y[b]; return x[a] < x[b]; }); int j = 0; for (int i = 1; i <= n; i += 1) { while (j < tmp.size() && (x[tmp[j]] < x[ord[i]] || (x[tmp[j]] == x[ord[i]] && y[tmp[j]] < y[ord[i]]))) { j++; } if (j < tmp.size() && (x[tmp[j]] == x[ord[i]] && y[tmp[j]] == y[ord[i]])) { res.emplace_back(ord[i]); } } sort(res.begin(), res.end()); for (int i = 0; i < res.size(); i++) { cout << res[i] << " \n"[i == res.size() - 1]; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (1LL << 30) - 1; const long long int LINF = (1LL << 62) - 1; const int NMAX = (2e5) + 5; struct point { double x, y; int s, r; point() { x = y = 0.0; s = r = 0; } point(int _s, int _r) { s = _s; r = _r; x = 1.0 / s; y = 1.0 / r; } bool operator<(const point &that) const { if (s == that.s) return r > that.r; return s > that.s; } }; int N, top, cnt; point P[NMAX]; point H[NMAX]; int V[NMAX]; map<pair<int, int>, vector<int> > mp; long long int cp(const point &A, const point &B, const point &C) { return B.s * 1LL * A.r * (C.s - A.s) * (C.r - B.r) - A.s * 1LL * B.r * (C.s - B.s) * (C.r - A.r); } bool compare(const point &A, const point &B, const point &C) { long long int p = cp(A, B, C); if (p == 0) return (A.x <= B.x && B.x <= C.x); return p > 0; } struct cmp { bool operator()(const point &A, const point &B) const { return compare(P[1], A, B); } }; void convex_hull() { int i; sort(P + 1, P + N + 1); sort(P + 2, P + N + 1, cmp()); for (i = 1; i <= N; i++) { while (top > 2 && !compare(H[top - 1], H[top], P[i])) top--; H[++top] = P[i]; } } int main() { int i, s, r, poz; cin.sync_with_stdio(false); scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%d%d", &s, &r); mp[{s, r}].push_back(i); } N = 0; for (auto x : mp) P[++N] = point(x.first.first, x.first.second); convex_hull(); poz = 1; for (i = 1; i <= top; i++) if ((H[poz].r < H[i].r) || (H[poz].r == H[i].r && H[poz].s < H[i].s) || (H[poz].r == H[i].r && H[poz].s == H[i].s)) poz = i; for (i = 1; i <= poz; i++) for (auto x : mp[{H[i].s, H[i].r}]) V[++cnt] = x; sort(V + 1, V + cnt + 1); for (i = 1; i <= cnt; i++) printf("%d ", V[i]); return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 200005; long long n; struct qq { long long x, y, id; } s[N]; bool cmp(qq x, qq y) { return x.x == y.x ? x.y < y.y : x.x < y.x; } long long sta[N], top; bool check(qq a, qq b, qq c) { return a.x * (a.y - b.y) * c.y * (c.x - b.x) > c.x * (b.y - c.y) * a.y * (b.x - a.x); } map<pair<long long, long long>, long long> mp; bool ok[N]; int main() { scanf("%lld", &n); for (long long u = 1; u <= n; u++) { scanf("%lld%lld", &s[u].x, &s[u].y); s[u].id = u; } sort(s + 1, s + 1 + n, cmp); for (long long u = 1; u <= n; u++) { while (top >= 1 && s[sta[top]].y <= s[u].y) top--; while (top >= 2 && check(s[sta[top - 1]], s[sta[top]], s[u])) top--; sta[++top] = u; } memset(ok, false, sizeof(ok)); for (int u = 1; u <= top; u++) mp[make_pair(s[sta[u]].x, s[sta[u]].y)] = 1; for (long long u = 1; u <= n; u++) if (mp[make_pair(s[u].x, s[u].y)]) ok[s[u].id] = true; for (long long u = 1; u <= n; u++) if (ok[u]) printf("%lld ", u); return 0; }
#include <bits/stdc++.h> using namespace std; int ind[200005], tail[200005], next_ind[200005]; struct competitor { int st_ind; long long r, s; } v[200005], r[200005]; bool operator<(competitor a, competitor b) { return (a.r > b.r) || ((a.r == b.r) && (a.s > b.s)); } bool ok(competitor a, competitor b, competitor c) { if ((a.r - b.r) * (a.s - c.s) * b.s * c.r - (a.r - c.r) * (a.s - b.s) * c.s * b.r < 0) return false; else return true; } int n, ans[200005]; void zabat() { int m = 0; for (int i = 0; i < n; i++) { if (m == 0) v[m++] = v[i]; else { if ((v[m - 1].r != v[i].r) || (v[m - 1].s != v[i].s)) v[m++] = v[i]; else tail[v[m - 1].st_ind] = next_ind[tail[v[m - 1].st_ind]] = v[i].st_ind; } } n = m; } int main() { scanf("%d", &n); int ninds = 0; memset(next_ind, -1, sizeof next_ind); for (int i = 0; i < n; i++) { scanf("%I64d %I64d", &v[i].r, &v[i].s); ind[tail[v[i].st_ind] = v[i].st_ind = ninds++] = i + 1; ; } sort(v, v + n); zabat(); int nr = 0; for (int i = 0; i < n; i++) { if (nr == 0) r[nr++] = v[i]; else { if (r[nr - 1].s >= v[i].s) continue; while ((nr >= 2) && !ok(r[nr - 2], r[nr - 1], v[i])) nr--; r[nr++] = v[i]; } } int nans = 0; for (int i = 0; i < nr; i++) for (int j = r[i].st_ind; j != -1; j = next_ind[j]) ans[nans++] = ind[j]; sort(ans, ans + nans); for (int i = 0; i < nans; i++) { if (i > 0) printf(" "); printf("%d", ans[i]); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200100; multimap<pair<int, int>, int> m; pair<double, double> p[N], s[N]; int ans[N]; int dcmp(double x) { if (x > 10e-8) return 1; if (x < -10e-8) return -1; return 0; } pair<double, double> operator+(pair<double, double> a, pair<double, double> b) { return pair<double, double>(a.first + b.first, a.second + b.second); } pair<double, double> operator-(pair<double, double> a, pair<double, double> b) { return pair<double, double>(a.first - b.first, a.second - b.second); } double cross(pair<double, double> a, pair<double, double> b) { return a.first * b.second - a.second * b.first; } double cross(pair<double, double> a, pair<double, double> b, pair<double, double> c) { return cross(b - a, c - a); } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int t, v; scanf("%d%d", &t, &v); p[i].first = 10e4 / t; p[i].second = 10e4 / v; m.insert(pair<pair<int, int>, int>(pair<int, int>(t, v), i)); } sort(p + 1, p + n + 1); int cnt = 0; for (int i = 1; i <= n; i++) if (p[i] != p[i - 1]) { while (cnt >= 2 && dcmp(cross(s[cnt - 1], s[cnt], p[i])) < 0) cnt--; s[++cnt] = p[i]; } while (cnt >= 2 && dcmp(s[cnt].second - s[cnt - 1].second) >= 0) cnt--; int num = 0; for (int i = 1; i <= cnt; i++) { pair<int, int> cur((int)(10e4 / s[i].first + 0.5), (int)(10e4 / s[i].second + 0.5)); multimap<pair<int, int>, int>::iterator l = m.lower_bound(cur); multimap<pair<int, int>, int>::iterator r = m.upper_bound(cur); for (multimap<pair<int, int>, int>::iterator j = l; j != r; j++) ans[num++] = j->second; } sort(ans, ans + num); for (int i = 0; i <= num - 1; i++) printf("%d ", ans[i]); return 0; }
#include <bits/stdc++.h> inline int gi() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } std::set<std::pair<int, int> > M; struct yyb { int x, y, i; long double k, b; } s[300010], stk[300010]; inline bool cmp_k(const yyb& a, const yyb& b) { if (a.y != b.y) return a.y < b.y; else return a.x > b.x; } inline bool cmp_i(const yyb& a, const yyb& b) { return a.i < b.i; } int main() { int n = gi(); for (int i = 1; i <= n; ++i) s[i].x = gi(), s[i].y = gi(), s[i].i = i, s[i].k = 1000000000.0 / s[i].y, s[i].b = 1000000000.0 / s[i].x; std::sort(s + 1, s + n + 1, cmp_k); int top = 0; stk[++top] = (yyb){0, 0, 0, 1e18, 0}; for (int i = 1; i <= n; ++i) { if (s[i].y == s[i - 1].y) continue; while (top > 1 && stk[top].y != stk[top - 1].y && (-(s[i].b - stk[top].b) / (s[i].k - stk[top].k) + 1e-15 < -(stk[top].b - stk[top - 1].b) / (stk[top].k - stk[top - 1].k))) { --top; } stk[++top] = s[i]; } std::sort(s + 1, s + n + 1, cmp_i); for (int i = 1; i <= top; ++i) M.insert(std::make_pair(stk[i].x, stk[i].y)); for (int i = 1; i <= n; ++i) if (M.find(std::make_pair(s[i].x, s[i].y)) != M.end()) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 7; long long n; pair<long double, long double> a[MAXN]; vector<pair<long double, long double> > ans; pair<long double, long double> vect(pair<long double, long double> a, pair<long double, long double> b) { return {b.first - a.first, b.second - a.second}; } long double cp(pair<long double, long double> a, pair<long double, long double> b) { return a.first * b.second - a.second * b.first; } bool comp(long long i, long long j) { return a[i] < a[j]; } void add(pair<long double, long double> p) { while (2 <= ans.size()) { auto prpr = ans[(long long)ans.size() - 2]; auto pr = ans[(long long)ans.size() - 1]; if (cp(vect(prpr, p), vect(prpr, pr)) < 0) { ans.pop_back(); } else { break; } } while (ans.size() && ans.back() != p && ans.back().first <= p.first && ans.back().second <= p.second) ans.pop_back(); ans.push_back(p); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 0; i < n; ++i) { long long first, second; cin >> first >> second; a[i].first = 1 - 1.0 / first; a[i].second = 1 - 1.0 / second; } set<pair<long double, long double> > ms; for (long long i = 0; i < n; ++i) ms.insert(a[i]); for (auto e : ms) add(e); ms.clear(); for (auto e : ans) ms.insert(e); for (long long i = 0; i < n; ++i) { if (ms.find(a[i]) != ms.end()) cout << i + 1 << ' '; } cout << '\n'; return 0; }