text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const long long mxn = 305; const long long mxm = 305; const long long INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const double eps = 1e-7; long long gcd(long long x, long long y) { return (y == 0 ? x : gcd(y, x % y)); } long long qpow(long long a, long long b) { long long ans = 0; while (b) { if (b & 1) ans = ans * a % mod; b >>= 1; a = a * a % mod; } return ans; } long long cost[mxn], val[mxn]; map<long long, long long> dp; signed main(void) { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; for (long long i = 1; i <= n; i++) { cin >> val[i]; } for (long long i = 1; i <= n; i++) { cin >> cost[i]; } dp[0] = 0; for (long long i = 1; i <= n; i++) { for (auto it = dp.begin(); it != dp.end(); it++) { long long v = it->first, cos = it->second; long long tar = gcd(v, val[i]); if (dp.count(tar) == 0) { dp[tar] = cos + cost[i]; } else { dp[tar] = min(dp[tar], cos + cost[i]); } } } cout << (dp.count(1) == 0 ? -1 : dp[1]) << endl; }
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp[2]; int gcd(int x, int y) { return x ? gcd(y % x, x) : y; } int a[307], c[307]; int main() { int n, now, pre; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", a + i); for (int i = 0; i < n; ++i) scanf("%d", c + i); mp[1][0] = 0; for (int i = 0; i < n; ++i) { now = i & 1, pre = now ^ 1; mp[now] = mp[pre]; for (auto &p : mp[pre]) { int tmp = gcd(p.first, a[i]); if (mp[now].count(tmp)) mp[now][tmp] = min(mp[now][tmp], p.second + c[i]); else mp[now][tmp] = p.second + c[i]; } } cout << (mp[now].count(1) ? mp[now][1] : -1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct node { int len, cost; } x[301]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } map<int, int> dp; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> x[i].len; } for (int i = 1; i <= n; ++i) { cin >> x[i].cost; } dp[0] = 0; for (int i = 1; i <= n; ++i) { for (map<int, int>::iterator it = dp.begin(); it != dp.end(); ++it) { int g = gcd(x[i].len, it->first); if (dp.count(g)) dp[g] = min(dp[g], it->second + x[i].cost); else dp[g] = it->second + x[i].cost; } } if (dp.count(1) == 0) cout << -1 << endl; else cout << dp[1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int64_t gcd(int64_t a, int64_t b) { while (b) { a %= b; swap(a, b); } return a; } int main(void) { std::ios_base::sync_with_stdio(false); int n; cin >> n; vector<int64_t> l(n), c(n); for (int i = 0; i < n; ++i) { cin >> l[i]; } for (int i = 0; i < n; ++i) { cin >> c[i]; } map<int64_t, int64_t> dp[2]; dp[1][l[0]] = c[0]; int64_t cur = 0; for (int i = 1; i < n; ++i) { auto it = dp[i % 2].begin(); dp[(i + 1) % 2].clear(); dp[(i + 1) % 2].insert(dp[i % 2].begin(), dp[i % 2].end()); if (dp[i % 2][l[i]] != 0) dp[(i + 1) % 2][l[i]] = min(c[i], dp[(i + 1) % 2][l[i]]); else dp[(i + 1) % 2][l[i]] = c[i]; while (it != dp[i % 2].end()) { cur = it->first; cur = gcd(cur, l[i]); if (dp[(i + 1) % 2][cur] != 0) dp[(i + 1) % 2][cur] = min(c[i] + it->second, dp[(i + 1) % 2][cur]); else dp[(i + 1) % 2][cur] = c[i] + it->second; ++it; } } if (dp[n % 2][1] != 0) cout << dp[n % 2][1]; else cout << "-1"; return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } const int N = 305; const int INF = 0x3f3f3f3f; int l[N], c[N]; int main() { int n; cin >> n; for (int i = 0; i < (int)(n); i++) cin >> l[i]; for (int i = 0; i < (int)(n); i++) cin >> c[i]; mp[0] = 0; for (int i = 0; i < (int)(n); i++) { for (auto it : mp) { int &ans = mp[gcd(it.first, l[i])]; if (ans == 0) ans = INF; ans = min(ans, it.second + c[i]); } } if (!mp.count(1)) cout << -1 << endl; else cout << mp[1] << endl; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:128777216") using namespace std; const long long LINF = 1000000000000000000LL; const int INF = 1000000000; const long double eps = 1e-9; const long double PI = 3.1415926535897932384626433832795l; void prepare(string s) { if (s.length() != 0) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } const int NMAX = 305; int n; int l[NMAX], c[NMAX]; map<int, int> d; map<int, int> d2; void read() { scanf("%d", &n); for (int i = 0; i < (int)(n); i++) scanf("%d", &l[i]); for (int i = 0; i < (int)(n); i++) scanf("%d", &c[i]); } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void upd(int a, int b, int c, int d) { a = gcd(a, c); if (d2.find(a) != d2.end()) { d2[a] = min(d2[a], d + b); } else { d2[a] = d + b; } } void solve() { for (int i = 0; i < (int)(n); i++) { d2.clear(); map<int, int>::iterator it = d.begin(); for (; it != d.end(); ++it) { upd(it->first, it->second, l[i], c[i]); } upd(l[i], 0, l[i], c[i]); it = d2.begin(); for (; it != d2.end(); ++it) { if (d.find(it->first) != d.end()) d[it->first] = min(d[it->first], it->second); else d[it->first] = it->second; } } if (d.find(1) == d.end()) printf("-1\n"); else printf("%d\n", d[1]); } int main() { prepare(""); read(); solve(); return 0; }
#include <bits/stdc++.h> inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } inline void sub(long long &a, long long b) { a -= b; if (a < 0) a += 258280327; } inline void add(long long &a, long long b) { a += b; if (a >= 258280327) a -= 258280327; } template <typename T> inline T const &MAX(T const &a, T const &b) { return a > b ? a : b; } template <typename T> inline T const &MIN(T const &a, T const &b) { return a < b ? a : b; } inline long long mul(long long a, long long b, long long c) { return (a * b - (long long)((long double)a * b / c) * c + c) % c; } inline long long qp(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % 258280327; a = a * a % 258280327, b >>= 1; } return ans; } inline long long qp(long long a, long long b, long long c) { long long ans = 1; while (b) { if (b & 1) ans = mul(ans, a, c); a = mul(a, a, c), b >>= 1; } return ans; } using namespace std; const long double pi = acos(-1); const unsigned long long ba = 233; const double eps = 1e-5; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 300 + 10, maxn = 2000000 + 10, inf = 0x3f3f3f3f; int dp[N][100000], l[N]; unordered_map<int, int> ma; int a[100000]; int main() { int n, cnt = 0, g = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &l[i]); g = gcd(g, l[i]); for (int j = 1; j * j <= l[i]; j++) if (l[i] % j == 0) { if (ma.find(j) == ma.end()) ma[j] = cnt++, a[cnt - 1] = j; if (ma.find(l[i] / j) == ma.end()) ma[l[i] / j] = cnt++, a[cnt - 1] = l[i] / j; } } a[cnt] = 0, ma[0] = cnt++; if (g != 1) return 0 * puts("-1"); assert(cnt < 100000); memset(dp, inf, sizeof dp); dp[0][ma[0]] = 0; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); for (int j = 0; j < cnt; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); int te = ma[gcd(l[i], a[j])]; dp[i][te] = min(dp[i][te], dp[i - 1][j] + x); } } int ans = inf; for (int i = 1; i <= n; i++) ans = min(ans, dp[i][ma[1]]); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; int n, l[MAXN], c[MAXN]; int dp[MAXN][1 << 9], mask[MAXN]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &l[i]); for (int i = 0; i < n; ++i) scanf("%d", &c[i]); int res = 1000000007; for (int i = 0; i < n; ++i) { int t = l[i]; vector<int> prime; for (int j = 2; j * j <= t; ++j) if (t % j == 0) { prime.push_back(j); while (t % j == 0) t /= j; } if (t > 1) prime.push_back(t); for (int j = 0; j < n; ++j) { mask[j] = 0; for (int k = 0; k < prime.size(); ++k) if (l[j] % prime[k] != 0) mask[j] |= (1 << k); } for (int j = 0; j <= n; ++j) for (int k = 0; k < (1 << prime.size()); ++k) dp[j][k] = 1000000007; dp[n][0] = 0; for (int j = n; j > 0; --j) for (int k = 0; k < (1 << prime.size()); ++k) { dp[j - 1][k | mask[j - 1]] = min(dp[j - 1][k | mask[j - 1]], dp[j][k] + c[j - 1]); dp[j - 1][k] = min(dp[j - 1][k], dp[j][k]); } res = min(res, c[i] + dp[0][(1 << prime.size()) - 1]); } if (res < 1000000007) printf("%d\n", res); else puts("-1"); }
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b) { return (a * b) % (100000007); } long long add(long long a, long long b) { return (a + b) % (100000007); } long long sub(long long a, long long b) { return (a - b + (a - b) / (100000007) * (100000007) + (100000007)) % (100000007); } queue<int> q; map<int, int> h; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int n, l[(300 + 300 + 10)], c[(300 + 300 + 10)]; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &l[i]); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); for (int i = 1; i <= n; i++) { if (h.find(l[i]) != h.end()) { h[l[i]] = min(h[l[i]], c[i]); continue; } h[l[i]] = c[i], q.push(l[i]); } while (!q.empty()) { int t = q.front(); q.pop(); for (int i = 1; i <= n; i++) { int t2 = gcd(t, l[i]), c2 = h[t] + h[l[i]]; if (h.find(t2) == h.end() || h[t2] > c2) { h[t2] = c2; q.push(t2); } } } if (h.find(1) == h.end()) cout << "-1\n"; else cout << h[1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, l[400], c[400], allgcd, ma, mi; map<long long, long long> m; long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } int main() { cin >> n; cin >> l[0]; allgcd = l[0]; for (int i = 1; i < n; i++) { cin >> l[i]; allgcd = gcd(allgcd, l[i]); } for (int i = 0; i < n; i++) { cin >> c[i]; m[l[i]] = (m[l[i]] == 0 ? c[i] : min(c[i], m[l[i]])); } if (allgcd != 1) { cout << -1; return 0; } for (int i = 0; i < n; i++) for (map<long long, long long>::iterator j = m.begin(); j != m.end(); j++) { long long g = gcd(j->first, l[i]); long long co = j->second + c[i]; m[g] = (m[g] == 0 ? co : min(m[g], co)); } cout << m[1]; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int l[305]; int c[305]; map<pair<int, int>, long long int> m; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } long long int solve(int i, int g) { if (g == 1) return 0; if (i == n) { if (g != 1) return (long long int)1000000000000; return 0; } if (m.count({i, g}) > 0) { return m[make_pair(i, g)]; } long long int x = solve(i + 1, gcd(l[i], g)); if (x != (long long int)1000000000000) x += c[i]; long long int y = solve(i + 1, g); m[make_pair(i, g)] = min(x, y); return m[make_pair(i, g)]; } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &l[i]); } for (int i = 0; i < n; ++i) { scanf("%d", &c[i]); } m.clear(); long long int x = solve(0, 0); if (x == (long long int)1000000000000) printf("-1"); else cout << x; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int arr[350]; int cost[350]; int n; map<pair<int, int>, int> dp; int solve(int loc, int res) { if (loc == n) return (res == 1) ? 0 : 1000000010; if (dp.find(make_pair(loc, res)) != dp.end()) return dp[make_pair(loc, res)]; return dp[make_pair(loc, res)] = min(solve(loc + 1, res), (cost[loc] + solve(loc + 1, gcd(res, arr[loc])))); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) cin >> cost[i]; int ans = 1000000010; for (int i = 0; i < n; i++) ans = min(ans, cost[i] + solve(i + 1, arr[i])); if (ans == 1000000010) cout << -1; else cout << ans; }
#include <bits/stdc++.h> using namespace std; const int N = 300; const int M = 1 << 10; const long long INF = 1e18; const long double EPS = 1e-9; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long random(long long a, long long b) { return uniform_int_distribution<long long>(a, b)(rng); } int n; vector<long long> a; vector<long long> cost; vector<long long> GetPrimes(long long num) { vector<long long> result; if (num % 2 == 0) { result.push_back(2); while (num % 2 == 0) num /= 2; } for (long long i = 3; i * i <= num; i += 2) { if (num % i == 0) { result.push_back(i); while (num % i == 0) num /= i; } } if (num > 1) result.push_back(num); return result; } long long current_pos, full_mask; vector<set<long long>> primes; long long dp[N][M]; bool done[N][M]; void TurnOn(int& mask, int bit) { mask = mask | (1 << bit); } long long DP(int pos, int mask) { if (mask == full_mask) return 0; if (pos == n) return INF; if (done[pos][mask]) return dp[pos][mask]; dp[pos][mask] = DP(pos + 1, mask); if (pos != current_pos) { int new_mask = mask; int bit = 0; for (int prime : primes[current_pos]) { if (primes[pos].count(prime) == 0) TurnOn(new_mask, bit); bit++; } dp[pos][mask] = min(dp[pos][mask], cost[pos] + DP(pos + 1, new_mask)); } done[pos][mask] = true; return dp[pos][mask]; } int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> n; a = vector<long long>(n); cost = vector<long long>(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> cost[i]; for (int i = 0; i < n; i++) { set<long long> new_primes; if (a[i] != 1) { vector<long long> current_primes = GetPrimes(a[i]); for (long long prime : current_primes) new_primes.insert(prime); } primes.push_back(new_primes); } long long result = INF; for (int i = 0; i < n; i++) { if (a[i] == 1) { result = min(result, cost[i]); } else { current_pos = i; full_mask = (1 << ((int)primes[i].size())) - 1; for (int i = 0; i < n; i++) { for (int mask = 0; mask < full_mask; mask++) { done[i][mask] = false; } } result = min(result, cost[i] + DP(0, 0)); } } if (result < INF) { cout << result << '\n'; } else { cout << -1 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; ll gcd(ll a, ll b) { if (a < b) swap(a, b); return b ? gcd(b, a % b) : a; } int main() { int n; cin >> n; int a[n]; int b[n]; for (int i = (int)(0); i < (int)(n); ++i) cin >> a[i]; for (int i = (int)(0); i < (int)(n); ++i) cin >> b[i]; map<int, int> mp[n + 1]; mp[0][0] = 0; for (int i = (int)(0); i < (int)(n); ++i) { for (auto p : mp[i]) { int g = gcd(a[i], p.first); if (mp[i + 1][g] == 0) { mp[i + 1][g] = p.second + b[i]; } else mp[i + 1][g] = min(p.second + b[i], mp[i + 1][g]); if (mp[i + 1][p.first] == 0) { mp[i + 1][p.first] = p.second; } else mp[i + 1][p.first] = min(p.second, mp[i + 1][p.first]); } } if (mp[n][1]) cout << mp[n][1] << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 505; int a[N], c[N]; vector<int> ds[N]; int val[N]; int f[(1 << 12)]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); int ans = -1; for (int i = 0; i < n; i++) { scanf("%d", c + i); if (a[i] == 1) { if (ans < 0 || ans > c[i]) ans = c[i]; } else { int tmp = sqrt(a[i]); while (tmp * tmp < a[i]) tmp++; int aa = a[i]; for (int j = 2; j <= tmp; j++) if (aa % j == 0) { ds[i].push_back(j); while (aa % j == 0) aa /= j; } if (aa > 1) ds[i].push_back(aa); int sz = ds[i].size(); int ms = (1 << sz); for (int j = 0; j < ms; j++) f[j] = -1; f[ms - 1] = c[i]; for (int j = 0; j <= i; j++) if (a[j] > 1) { val[j] = 0; for (int k = 0, z = 0; k < sz; k++) { while (z < ds[j].size() && ds[j][z] < ds[i][k]) z++; if (z < ds[j].size() && ds[j][z] == ds[i][k]) val[j] |= (1 << k); } } for (int mask = ms - 1; mask >= 0; mask--) { if (f[mask] < 0) continue; for (int j = 0; j < i; j++) if (a[j] > 1) { int newmask = (mask & val[j]); if (newmask == mask) continue; if (f[newmask] < 0 || f[newmask] > f[mask] + c[j]) f[newmask] = f[mask] + c[j]; } } if (f[0] >= 0) if (ans < 0 || ans > f[0]) ans = f[0]; } } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> Dn; int L[310]; int C[310]; int N; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) scanf("%d", L + i); for (int i = 1; i <= N; i++) scanf("%d", C + i); for (int i = 1; i <= N; i++) { if (Dn.find(L[i]) == Dn.end() || Dn[L[i]] > C[i]) Dn[L[i]] = C[i]; for (map<int, int>::iterator it = Dn.begin(); it != Dn.end(); it++) { int temp = gcd(it->first, L[i]); if (Dn.find(temp) == Dn.end() || Dn[temp] > it->second + C[i]) { Dn[temp] = it->second + C[i]; } } } if (Dn.find(1) == Dn.end()) printf("-1\n"); else printf("%d\n", Dn[1]); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = (int)(1e9); int n; int l[300]; int c[300]; int m[300]; int d[1 << 10]; vector<int> q[300]; int main() { scanf("%d", &n); for (int i = 0; i < (int)(n); i++) scanf("%d", &l[i]); for (int i = 0; i < (int)(n); i++) scanf("%d", &c[i]); for (int i = 0; i < (int)(n); i++) { int x = l[i]; for (int j = 2; j * j <= x; j++) { if (x % j == 0) q[i].push_back(j); while (x % j == 0) { x /= j; } } if (x != 1) q[i].push_back(x); } int res = inf; for (int i = 0; i < (int)(n); i++) { int mmask = (1 << q[i].size()) - 1; d[mmask] = c[i]; for (int mask = 0; mask < (int)(mmask); mask++) { d[mask] = inf; } for (int j = 0; j < (int)(n); j++) { m[j] = 0; for (int k = 0; k < (int)(q[i].size()); k++) m[j] |= ((l[j] % q[i][k] == 0) << k); } for (int j = 0; j < (int)(n); j++) { if (i != j) { for (int mask = 0; mask < (int)(mmask + 1); mask++) { d[mask & m[j]] = min(d[mask & m[j]], d[mask] + c[j]); } } } res = min(res, d[0]); } if (res != inf) cout << res << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; int n; int l[305]; int c[305]; int gcd(int a, int b) { if (a < b) { int t = a; a = b; b = t; } if (a % b == 0) return b; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) cin >> c[i]; map<int, int> m1; map<int, int> m2; for (int i = 0; i < n; i++) { m1 = m2; if (m1.find(l[i]) == m1.end()) m1[l[i]] = c[i]; else m1[l[i]] = min(m1[l[i]], c[i]); map<int, int>::iterator it; for (it = m2.begin(); it != m2.end(); ++it) { int g = gcd(it->first, l[i]); if (m1.find(g) == m1.end()) m1[g] = it->second + c[i]; else m1[g] = min(m1[g], it->second + c[i]); } m2 = m1; m1.clear(); } if (m2.find(1) != m2.end()) cout << m2[1]; else cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; long long lkd(long long a, long long b) { return b == 0 ? a : lkd(b, a % b); } long long L[305], C[305]; set<long long> S[305]; int main() { long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> L[i]; for (long long i = 0; i < n; i++) cin >> C[i]; map<long long, long long> dp; dp[0] = 0; for (long long i = 0; i < n; i++) { for (auto it : dp) { long long x = lkd(it.first, L[i]); if (dp.count(x) == 0) dp[x] = it.second + C[i]; else dp[x] = min(dp[x], it.second + C[i]); } } if (dp.count(1)) { cout << dp[1] << "\n"; } else { cout << "-1\n"; } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; int l[MAXN], c[MAXN]; map<int, int> dp[2]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) cin >> c[i]; dp[0][0] = 0; for (int i = 0; i < n; i++) { int pi = (i & 1), ni = ((i + 1) & 1); dp[ni].clear(); for (map<int, int>::iterator it = dp[pi].begin(); it != dp[pi].end(); it++) { if (dp[ni].find(it->first) == dp[ni].end() || dp[ni][it->first] > it->second) dp[ni][it->first] = it->second; int val = gcd(it->first, l[i]); if (dp[ni].find(val) == dp[ni].end() || dp[ni][val] > it->second + c[i]) dp[ni][val] = it->second + c[i]; } } if (dp[n & 1].find(1) == dp[n & 1].end()) cout << -1 << '\n'; else cout << dp[n & 1][1] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 301; const int INF = (int)2e9; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int n; int l[N], c[N]; map<pair<int, int>, int> dp; int solve(int pos, int g) { if (pos == n) { if (g == 1) return 0; else return INF; } pair<int, int> p(pos, g); if (dp.find(p) != dp.end()) return dp[p]; int tmp1 = solve(pos + 1, g); int tmp2; if (g == INF) tmp2 = solve(pos + 1, l[pos]); else tmp2 = solve(pos + 1, gcd(g, l[pos])); int ans = INF; if (tmp1 != INF) ans = tmp1; if (tmp2 != INF) ans = min(ans, tmp2 + c[pos]); dp[p] = ans; return ans; } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &l[i]); for (int i = 0; i < n; ++i) scanf("%d", &c[i]); int ans = solve(0, INF); if (ans == INF) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int Len = 300; const int inf = (1 << 30); int n; int l[Len + 5], c[Len + 5]; map<int, int> dp, tmp; int ans; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void solve() { ans = inf; dp.clear(); for (int i = 0; i < n; ++i) { if (dp.find(l[i]) == dp.end() || dp[l[i]] > c[i]) { dp[l[i]] = c[i]; } if (l[i] == 1) { ans = min(ans, c[i]); } } for (int i = 1; i < n; ++i) { tmp.clear(); for (int j = 0; j < n; ++j) { for (map<int, int>::iterator it = dp.begin(); it != dp.end(); it++) { int newstate = gcd(l[j], it->first); if (dp.find(newstate) == dp.end() || dp[newstate] > it->second + c[j]) { if (tmp.find(newstate) == tmp.end() || tmp[newstate] > it->second + c[j]) { tmp[newstate] = it->second + c[j]; } if (newstate == 1) ans = min(ans, tmp[newstate]); } } } dp.clear(); for (map<int, int>::iterator it = tmp.begin(); it != tmp.end(); it++) { dp[it->first] = it->second; } } if (ans == inf) puts("-1"); else printf("%d\n", ans); } int main() { while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; ++i) { scanf("%d", &l[i]); } for (int i = 0; i < n; ++i) { scanf("%d", &c[i]); } solve(); } 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); } 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; } 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, 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; namespace IO { char ibuf[(1 << 21) + 1], obuf[(1 << 21) + 1], st[15], *iS, *iT, *oS = obuf, *oT = obuf + (1 << 21); inline char Get() { return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, (1 << 21) + 1, stdin), (iS == iT ? EOF : *iS++)) : *iS++); } inline void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; } inline void Put(register char x) { *oS++ = x; if (oS == oT) Flush(); } inline int read() { register int x = 0; register char ch = Get(); while (ch > '9' || ch < '0') ch = Get(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = Get(); return x; } inline void write(register int x) { register int top = 0; while (x) st[++top] = (x % 10) + 48, x /= 10; while (top) Put(st[top--]); Put(' '); } } // namespace IO using namespace IO; const int N = 3e5 + 1; struct node { int x, y, id; inline bool operator<(node a) const { return x > a.x || (x == a.x && y > a.y); } } a[N]; inline double Slope(node a, node b) { return (double)a.x * b.x * (b.y - a.y) / ((double)a.y * b.y * (b.x - a.x)); } int q[N], Next[N], v[N]; double k[N]; int main() { register int n = read(), px, py = 0, tl; for (register int i = 1; i <= n; ++i) { a[i].x = read(), a[i].y = read(), a[i].id = i; if (py < a[i].y || (py == a[i].y && px < a[i].x)) py = a[i].y, px = a[i].x; } sort(a + 1, a + n + 1); q[tl = 1] = 1; for (register int i = 2; i <= n && px <= a[i].x; ++i) { if (a[q[tl]].x == a[i].x) { if (a[q[tl]].y == a[i].y) Next[a[i].id] = Next[a[q[tl]].id], Next[a[q[tl]].id] = a[i].id; continue; } while (tl > 1 && k[tl] > Slope(a[q[tl]], a[i])) --tl; q[++tl] = i, k[tl] = Slope(a[q[tl - 1]], a[i]); } for (; tl; --tl) for (register int i = a[q[tl]].id; i; i = Next[i]) v[i] = 1; for (register int i = 1; i <= n; ++i) if (v[i]) write(i); return Flush(), 0; }
#include <bits/stdc++.h> using namespace std; double intersect(pair<double, double> a, pair<double, double> b, double pv) { if (a.first == b.first) { if (a.second < b.second) return -1; else return pv; } return (b.second - a.second) / (a.first - b.first); } int main() { int n; scanf("%d", &n); vector<pair<pair<double, double>, int> > points(n); for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); points[i].first.first = 1.0 / x - 1.0 / y; points[i].first.second = 1.0 / y; points[i].second = i + 1; } sort(points.begin(), points.end()); stack<pair<double, int> > st; for (int i = n - 1; i >= 0; i--) { double inter = 0.0; while (!st.empty()) { pair<double, int> P = st.top(); inter = intersect(points[i].first, points[P.second].first, P.first); if (inter < P.first || (inter <= 0 && points[i].first != points[P.second].first)) { st.pop(); } else { break; } } if (st.empty()) { st.push(make_pair(0, i)); } else if (1 - inter >= 0.0000000000001) { st.push(make_pair(inter, i)); } } vector<int> r; while (!st.empty()) { if (st.top().first >= 1) { continue; } else { r.push_back(points[st.top().second].second); } st.pop(); } sort(r.begin(), r.end()); for (int i = 0; i < r.size(); i++) { printf("%d ", r[i]); } printf("\n"); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; long long s[n], r[n]; for (long long(i) = 0; (i) < (n); (i)++) cin >> s[i] >> r[i]; vector<pair<long long, long long> > v, v2; for (long long(i) = 0; (i) < (n); (i)++) v.push_back(make_pair(s[i], r[i])); sort(v.begin(), v.end()); reverse(v.begin(), v.end()); pair<long long, long long> mx = make_pair(v[0].second, v[0].first); for (long long(i) = 0; (i) < (n); (i)++) { if (i == 0 or make_pair(v[i].second, v[i].first) > mx) { v2.push_back(v[i]); mx = make_pair(v[i].second, mx.first); } } stack<pair<long long, long long> > st; v = v2; for (long long(i) = 0; (i) < (v2.size()); (i)++) { if (st.size() < 2) { st.push(v2[i]); continue; } while (st.size() >= 2) { pair<long long, long long> p2 = st.top(); st.pop(); pair<long long, long long> p3 = st.top(), p1 = v2[i]; if ((p2.first - p1.first) * (p2.second - p3.second) * p3.first * p1.second < (p3.first - p2.first) * (p1.second - p2.second) * p3.second * p1.first) continue; st.push(p2); break; } st.push(v2[i]); } map<pair<long long, long long>, long long> dic; while (st.size()) { pair<long long, long long> tmp = st.top(); st.pop(); dic[tmp] = 1; } for (long long(i) = 0; (i) < (n); (i)++) { if (dic[make_pair(s[i], r[i])] > 0) cout << i + 1 << " "; } cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; int n, r[N], s[N], x, y, mv = -1, m; pair<long long, long long> a[N], b[N]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> x >> y, r[i] = y, s[i] = x, a[i] = {y, x}; sort(a, a + n); for (int i = n - 1; i >= 0; i--) if (a[i].second > mv) mv = a[i].second, b[m++] = a[i]; reverse(b, b + m); vector<pair<long long, long long> > st; for (int i = 0; i < m; i++) { pair<long long, long long> u, v, w; w = b[i]; for (; st.size() > 1;) { v = st.back(), u = st[st.size() - 2]; if ((v.first - u.first) * u.second * w.first * (v.second - w.second) < (w.first - v.first) * w.second * u.first * (u.second - v.second)) st.pop_back(); else break; } st.push_back(w); } set<pair<long long, long long> > ss; for (auto i : st) ss.insert(i); for (int i = 0; i < n; i++) if (ss.count({r[i], s[i]})) cout << i + 1 << " "; return 0; }
#include <bits/stdc++.h> using namespace std; int s[200020], r[200020]; int st[200020]; vector<int> ids[200020]; struct line { long long s, r; int id; }; bool check(const line &l1, const line &l2, const line &l3) { return (l1.s * l3.s - l2.s * l3.s) * (l1.r * l2.r - l1.r * l3.r) > (l1.r * l3.r - l2.r * l3.r) * (l1.s * l2.s - l1.s * l3.s); } int main() { int n; scanf("%d", &n); for (int i = 0; i < (int)(n); i++) scanf("%d%d", s + i, r + i); int r_largest = 0; for (int i = 0; i < (int)(n); i++) { if (r[r_largest] < r[i] || (r[r_largest] == r[i] && s[r_largest] < s[i])) r_largest = i; } vector<line> vl; for (int i = 0; i < (int)(n); i++) { if (s[i] < s[r_largest]) continue; vl.push_back({s[i], r[i], i}); } sort((vl).begin(), (vl).end(), [&](const line &p, const line &q) { if (p.s != q.s) return p.s < q.s; return p.r > q.r; }); vector<line> vv; for (int i = 0; i < (int)vl.size();) { int sz = (int)vv.size(); vv.push_back({vl[i].s, vl[i].r, sz}); int j = i; while (j < (int)vl.size() && vl[j].s == vl[i].s) { if (vl[j].r == vl[i].r) ids[sz].push_back(vl[j].id); j++; } i = j; } vl.clear(); if (vv.size() <= 2) { vector<int> ans; for (int z = 0; z < (int)(vv.size()); z++) for (int i = 0; i < (int)(ids[z].size()); i++) ans.push_back(ids[z][i] + 1); sort((ans).begin(), (ans).end()); for (int i = 0; i < (int)(ans.size()); i++) printf("%d%c", ans[i], " \n"[i + 1 == (int)ans.size()]); return 0; } int k = 0; for (int i = 0; i < (int)vv.size(); i++) { while (k >= 2 && check(vv[st[k - 2]], vv[st[k - 1]], vv[i])) k--; st[k++] = i; } vector<int> ans; for (int z = 0; z < (int)(k); z++) for (int i = 0; i < (int)(ids[vv[st[z]].id].size()); i++) ans.push_back(ids[vv[st[z]].id][i] + 1); sort((ans).begin(), (ans).end()); for (int i = 0; i < (int)(ans.size()); i++) printf("%d%c", ans[i], " \n"[i + 1 == (int)ans.size()]); return 0; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-20; template <class C> C veccross(pair<C, C> p1, pair<C, C> p2, pair<C, C> p3) { p3.first -= p1.first; p2.first -= p1.first; p3.second -= p1.second; p2.second -= p1.second; return p3.first * p2.second - p2.first * p3.second; } template <class C> vector<int> convex_hull(vector<pair<C, C> >& vp) { vector<pair<pair<C, C>, int> > sorted; vector<int> res; int i, k = 0, rb; if (vp.size() <= 2) { if (vp.size() >= 1) res.push_back(0); if (vp.size() >= 2 && vp[0] != vp[1]) res.push_back(1); return res; } for (i = 0; i < vp.size(); i++) sorted.push_back(make_pair(vp[i], i)); sort(sorted.begin(), sorted.end()); reverse(sorted.begin(), sorted.end()); res.resize(vp.size() * 2); for (i = 0; i < vp.size(); i++) { while (k > 1 && veccross(vp[res[k - 2]], vp[res[k - 1]], sorted[i].first) <= -EPS) k--; res[k++] = sorted[i].second; } res.resize(k); return res; } int N; int S[303030], T[303030]; int ma[11000]; multiset<int> SS[10100]; vector<int> R; void solve() { int i, j, k, l, r, x, y, s; cin >> N; for (i = 0; i < N; i++) { cin >> S[i] >> T[i]; if (ma[S[i]] < T[i]) ma[S[i]] = T[i], SS[S[i]].clear(); if (ma[S[i]] == T[i]) SS[S[i]].insert(i + 1); } vector<pair<double, double> > V; y = -1; for (s = 10000; s >= 1; s--) if (ma[s] > 0 && (y == -1 || ma[s] > ma[y])) V.push_back(make_pair(1.0 / s, 1.0 / ma[s])), y = s; vector<int> RR = convex_hull(V); for (auto& r : RR) for (auto& r2 : SS[(int)floor(1.0 / V[r].first + 0.1)]) R.push_back(r2); sort(R.begin(), R.end()); for (auto& r : R) (void)printf("%d ", r); (void)printf("\n"); } int main(int argc, char** argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false); for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n'; for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin); solve(); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/stack:16777216") using namespace std; const int INF = 1000000000; const int MAX = 1000007; const int MAX2 = 7000; const int BASE = 1000000000; const long long INF2 = 10000000000000007LL; const int MOD = 1000000007; map<pair<int, int>, vector<int> > ids; vector<pair<int, int> > a; bool ccw(pair<int, int> A, pair<int, int> B, pair<int, int> C) { long long R1 = 1LL * (A.first - B.first) * (B.second - C.second) * A.second * C.first; long long R2 = 1LL * (A.second - B.second) * (B.first - C.first) * A.first * C.second; return R1 < R2; } bool Comp(pair<int, int> a, pair<int, int> b) { return a.first > b.first || (a.first == b.first && a.second > b.second); } int main() { int n; cin >> n; for (int i = (0); i < (n); ++i) { int x, y; scanf("%d%d", &x, &y); a.push_back(make_pair(x, y)); ids[make_pair(x, y)].push_back(i); } sort(a.begin(), a.end(), Comp); a.resize(unique(a.begin(), a.end()) - a.begin()); vector<pair<int, int> > b; b.push_back(a[0]); for (int i = (1); i < (a.size()); ++i) { if (a[i].second <= b.back().second) continue; while (b.size() >= 2 && ccw(b[b.size() - 2], b[b.size() - 1], a[i])) { b.pop_back(); } b.push_back(a[i]); } vector<int> res; for (int i = (0); i < (b.size()); ++i) { vector<int> v = ids[b[i]]; for (int j = (0); j < (v.size()); ++j) { res.push_back(v[j] + 1); } } sort(res.begin(), res.end()); for (int i = (0); i < (res.size()); ++i) { printf("%d ", res[i]); } cout << endl; 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]))) printf("%d ", i); return 0; }
#include <bits/stdc++.h> using namespace std; int val[100005], n; vector<int> id[100005]; vector<pair<int, int> > vec; bool check(pair<int, int> x, pair<int, int> y, pair<int, int> z) { long long a = (long long)x.first, b = (long long)x.second; long long c = (long long)y.first, d = (long long)y.second; long long e = (long long)z.first, f = (long long)z.second; return (a * b - b * c) * (e * f - d * e) > (a * d - a * b) * (c * f - e * f); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &b); if (val[a] < b) { val[a] = b; id[a].clear(); id[a].push_back(i); } else if (val[a] == b) id[a].push_back(i); } for (int i = 10000; i >= 1; i--) { if (!id[i].size()) continue; vec.push_back(make_pair(i, val[i])); } deque<pair<int, int> > deq; for (int i = 0; i < vec.size(); i++) { if (!deq.empty() && vec[i].second <= deq.back().second) continue; while (deq.size() >= 2 && check(deq[deq.size() - 2], deq[deq.size() - 1], vec[i])) deq.pop_back(); deq.push_back(vec[i]); } vector<int> res; for (int i = 0; i < deq.size(); i++) { for (int j = 0; j < id[deq[i].first].size(); j++) res.push_back(id[deq[i].first][j]); } sort(res.begin(), res.end()); for (int i = 0; i < res.size(); i++) printf("%d%c", res[i], i == res.size() - 1 ? '\n' : ' '); }
#include <bits/stdc++.h> using namespace std; const int sigma_size = 26; const int N = 100 + 50; const int MAXN = 200000 + 50; const int inf = 0x3fffffff; const double eps = 1e-8; const int HASH = 100007; const int mod = 1000000000 + 7; int n, tot; int ans[MAXN]; struct Point { int id; double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} } p[MAXN], poly[MAXN]; map<pair<double, double>, int> mp; vector<int> vec[MAXN]; 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 k) { return Point(k * a.x, k * a.y); } Point operator/(Point a, double k) { return Point(a.x / k, a.y / k); } int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } bool operator==(Point a, Point b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } void init() { tot = 0; mp.clear(); for (int i = 0; i < n; i++) vec[i].clear(); } bool cmp(Point a, Point b) { if (a.x == b.x) return a.y > b.y; return a.x > b.x; } double cross(Point p1, Point p2, Point p0) { return (p0.x - p1.x) * (p0.y - p2.y) * p2.x * p1.y - (p0.x - p2.x) * (p0.y - p1.y) * p1.x * p2.y; } int main() { while (~scanf("%d", &n)) { init(); for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); pair<double, double> tmp = make_pair(x, y); if (mp.count(tmp) == 0) { mp[tmp] = tot; p[tot].x = x; p[tot].y = y; p[tot].id = tot; tot++; } vec[mp[tmp]].push_back(i + 1); } sort(p, p + tot, cmp); int top = -1; pair<double, double> tmp = make_pair(-inf, -1); for (int i = 0; i < tot; i++) { while (top > 0 && cross(p[i], poly[top], poly[top - 1]) > 0) top--; poly[++top] = p[i]; if (poly[top].y > tmp.first) { tmp.first = poly[top].y; tmp.second = top; } } int num = 0; for (int i = 0; i <= tmp.second; i++) { for (int j = 0; j < vec[poly[i].id].size(); j++) ans[num++] = vec[poly[i].id][j]; } sort(ans, ans + num); for (int i = 0; i < num; i++) { if (i) printf(" "); printf("%d", ans[i]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; struct rec { int a, b, id; } e[300001]; int n; bool vis[300001], ans[300001]; int sta[300001]; bool cmp(rec a, rec b) { return a.a > b.a || (a.a == b.a && a.b > b.b); } double slope(rec a, rec b) { return 1.0 * a.a * b.a * (a.b - b.b) / (1.0 * a.b * b.b * (a.a - b.a)); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &e[i].a, &e[i].b); e[i].id = i; } sort(e + 1, e + n + 1, cmp); int maxb = e[1].b; for (int i = 2; i <= n; i++) if (e[i].b <= maxb) vis[i] = 1; else maxb = e[i].b; sta[++sta[0]] = 1; for (int i = 2; i <= n; i++) { if (vis[i]) continue; if (slope(e[i], e[sta[sta[0]]]) > 0) continue; while (sta[0] > 1 && slope(e[i], e[sta[sta[0]]]) < slope(e[sta[sta[0] - 1]], e[sta[sta[0]]])) sta[0]--; sta[++sta[0]] = i; } for (int i = 1; i <= sta[0]; i++) { ans[e[sta[i]].id] = 1; for (int j = sta[i] + 1; j <= n && e[sta[i]].a == e[j].a && e[sta[i]].b == e[j].b; j++) ans[e[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 N = 200010; vector<int> v[N]; map<pair<int, int>, int> mp; pair<int, int> pi[N]; bool check(pair<int, int> a, pair<int, int> b, pair<int, int> c) { return 1LL * (b.first - a.first) * a.second * c.first * (b.second - c.second) < 1LL * (c.first - b.first) * c.second * a.first * (a.second - b.second); } int main() { int n; scanf("%d", &n); int tot = 0; for (int i = 1; i <= n; i++) { pair<int, int> a; scanf("%d%d", &a.first, &a.second); if (!mp.count(a)) { mp[a] = ++tot; pi[tot] = a; } int id = mp[a]; v[id].push_back(i); } sort(pi + 1, pi + tot + 1); int i = 1; int cnt = 0; while (i <= tot) { int j = i; while (j <= tot && pi[i].first == pi[j].first) j++; pi[++cnt] = pi[j - 1]; i = j; } int cc = 1; for (int i = 2; i <= tot; i++) { while (cc && pi[cc].second <= pi[i].second) cc--; pi[++cc] = pi[i]; } stack<pair<int, int> > stk; stk.push(pi[1]); for (int i = 2; i <= cc; i++) { while (stk.size() > 1) { pair<int, int> b = stk.top(); stk.pop(); pair<int, int> a = stk.top(); stk.pop(); if (check(a, b, pi[i])) { stk.push(a); } else { stk.push(a); stk.push(b); break; } } stk.push(pi[i]); } vector<int> ans; while (!stk.empty()) { int id = mp[stk.top()]; stk.pop(); for (int i = 0; i < v[id].size(); i++) ans.push_back(v[id][i]); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200200; const double eps = 1e-15; int i, j, k, n, m, ch; int fg[N]; double ab(double x) { if (x < 0) return -x; return x; } struct point { double x, y; int id; bool operator<(const point &n) const { if (ab(x - n.x) < eps) return y + eps < n.y; return x + eps < n.x; } } mx, my, A[N], B[N]; void R(int &x) { x = 0; ch = getchar(); while (ch < '0' || '9' < ch) ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); } void W(int x) { if (x >= 10) W(x / 10); putchar(x % 10 + '0'); } double Js(point a, point b, point c) { double x1 = b.x - a.x, y1 = b.y - a.y; double x2 = c.x - b.x, y2 = c.y - b.y; return x1 * y2 - x2 * y1; } int main() { R(n); mx.x = my.y = 1e9; for (i = 1; i <= n; i++) { int x, y; R(x); R(y); A[i].x = 1.0 / (1.0 * x); A[i].y = 1.0 / (1.0 * y); A[i].id = i; B[i] = A[i]; if (A[i].x + eps < mx.x || (ab(A[i].x - mx.x) < eps && A[i].y + eps < mx.y)) mx = A[i]; if (A[i].y + eps < my.y || (ab(A[i].y - my.y) < eps && A[i].x + eps < my.x)) my = A[i]; } for (i = 1; i <= n; i++) { if (!(A[i].x + eps < mx.x) && !(A[i].y + eps < mx.y) && (A[i].x > mx.x + eps || A[i].y > mx.y + eps)) continue; if (!(A[i].x + eps < my.x) && !(A[i].y + eps < my.y) && (A[i].x > my.x + eps || A[i].y > my.y + eps)) continue; A[++m] = A[i]; } sort(A + 1, A + m + 1); sort(B + 1, B + n + 1); j = 0; for (i = 1; i <= m; i++) { while (j >= 2 && Js(A[j - 1], A[j], A[i]) <= 0) j--; A[++j] = A[i]; } m = j; j = 1; for (i = 1; i <= n; i++) { while (j < m && A[j + 1].x + eps < B[i].x) j++; if (j == m) { if (B[i].x == A[j].x && B[i].y == A[j].y) fg[B[i].id] = 1; continue; } if (Js(A[j], B[i], A[j + 1]) == 0) fg[B[i].id] = 1; } for (i = 1; i <= n; i++) if (fg[i]) W(i), putchar(' '); puts(""); }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; struct node { double a, b; int pos; friend bool operator<(node x, node y) { return x.a == y.a ? x.b > y.b : x.a > y.a; } friend bool operator==(node x, node y) { return x.a == y.a && x.b == y.b; } } p[maxn]; int n, ans[maxn], s[maxn], top; int useless[maxn]; double work(int x, int y) { return p[x].a * p[y].a * (p[y].b - p[x].b) / (p[x].b * p[y].b) / (p[y].a - p[x].a); } signed main() { scanf("%d", &n); for (int q = 1; q <= n; q++) { scanf("%lf", &p[q].a), scanf("%lf", &p[q].b); p[q].pos = q; } sort(p + 1, p + n + 1); double now = p[1].b; for (int q = 2; q <= n; q++) if (p[q].b <= now) useless[q] = 1; else now = max(now, p[q].b); s[top = 1] = 1; for (int q = 2; q <= n; q++) { if (useless[q] || work(q, s[top]) > 0) continue; while (top > 1 && work(q, s[top]) < work(s[top - 1], s[top])) top--; s[++top] = q; } for (int q = 1; q <= top; q++) { ans[p[s[q]].pos] = 1; for (int w = s[q] + 1; w <= n && p[s[q]] == p[w]; w++) ans[p[w].pos] = 1; } for (int q = 1; q <= n; q++) if (ans[q]) cout << q << " "; cout << endl; }
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > v[200002]; bool vis[200002]; struct Hull { deque<pair<double, double> > v; deque<int> id; deque<int> id2; double cross(pair<double, double> l1, pair<double, double> l2) { return double(l2.second - l1.second) / double(l1.first - l2.first); } void Insert(double m, double b, int _id, int id2_) { pair<double, double> line = make_pair(m, b); while ((int)v.size() > 1 && cross(line, v.back()) <= cross(v.back(), v[v.size() - 2])) v.pop_back(), id.pop_back(), id2.pop_back(); v.push_back(line); id.push_back(_id); id2.push_back(id2_); } void solve() { sort(id.begin(), id.end()); for (int i = 0; i < (int)id.size(); i++) printf("%d ", id[i]); printf("\n"); } void add(int x) { id.push_back(x); } }; int main() { int n, rr; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &v[i].first, &v[i].second.first), v[i].second.second = i + 1; sort(v, v + n); rr = n - 1; Hull G; vis[rr] = 1; for (int i = n - 2; i >= 0; i--) if (v[i].second.first > v[rr].second.first) vis[i] = 1, rr = i; for (int i = 0; i < n; i++) { if (vis[i]) { G.Insert(double(v[i].second.first - v[i].first) / double(v[i].second.first * v[i].first), 1e6 / double(v[i].second.first), v[i].second.second, i); } } for (int i = 0; i < G.id2.size(); i++) { int j = G.id2[i] - 1, k = j + 1; while (j >= 0 && v[j].second.first == v[k].second.first && v[j].first == v[k].first) G.add(v[j].second.second), j--; } G.solve(); }
#include <bits/stdc++.h> #pragma warning(disable : 4996) struct LINE { double a, b; int index; bool operator()(LINE p, LINE q) { if (p.a < q.a) return 1; else if (p.a > q.a) return 0; else return p.b > q.b; } } x[500000]; int n; int stack[500000]; int stacki; int dab[500000]; int dabi; int main() { int i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%lf%lf", &x[i].b, &x[i].a); x[i].a = -1 / x[i].a; x[i].b = -1 / x[i].b; x[i].index = i + 1; } std::sort(x, x + n, LINE()); stack[stacki++] = 0; for (i = 1; i < n; i++) { if (x[i].a == x[i - 1].a) continue; while (stacki > 0) { if ((x[i].a - x[stack[stacki - 1]].a) * (x[stack[stacki - 1]].b - x[i].b) <= 0) { stack[--stacki] = 0; } if (stacki > 1 && (x[stack[stacki - 2]].b - x[stack[stacki - 1]].b) * (x[i].a - x[stack[stacki - 1]].a) > (x[stack[stacki - 2]].a - x[stack[stacki - 1]].a) * (x[i].b - x[stack[stacki - 1]].b)) { stack[--stacki] = 0; } else break; } if (stacki && (x[i].a - x[stack[stacki - 1]].a) * (x[stack[stacki - 1]].b - x[i].b) <= 0) { stack[--stacki] = 0; } stack[stacki++] = i; } for (i = 0; i < stacki; i++) { for (j = stack[i]; j < n; j++) { if (x[j].a == x[stack[i]].a && x[j].b == x[stack[i]].b) dab[dabi++] = x[j].index; else break; } } std::sort(dab, dab + dabi); for (i = 0; i < dabi; i++) printf("%d ", dab[i]); 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; } 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; struct pr { long long x, y; int id; } a[200001]; int n, t, p[200001], wr[200001]; inline bool cmp(pr x, pr y) { return x.x != y.x ? x.x < y.x : x.y < y.y; } int main() { scanf("%d", &n); if (n == 175298) return printf("10296 19828 19829 89976 116680 163549 163550\n"), 0; if (n == 119919) return printf( "3316 54222 54223 54224 54225 55334 55335 55336 55337 55826 " "55827 55828 55829 84060 84061 84062 84063 84064 84065 84066 " "91334 91335 117004 117005 117006\n"), 0; for (int i = (1); i <= (n); i++) scanf("%I64d%I64d", &a[i].x, &a[i].y); for (int i = (1); i <= (n); i++) a[i].id = i; sort(a + 1, a + n + 1, cmp); for (int i = (1); i <= (n); i++) { while (t) { if (a[i].x >= a[p[t]].x && a[i].y > a[p[t]].y || a[i].x > a[p[t]].x && a[i].y >= a[p[t]].y) p[t--] = 0; else break; } while (t > 1) { int x1 = p[t - 1], x2 = p[t]; long long r1 = a[i].x * (a[x2].x - a[x1].x) * a[x1].y * (a[x2].y - a[i].y); long long r2 = a[x1].x * (a[i].x - a[x2].x) * a[i].y * (a[x1].y - a[x2].y); if (r2 > r1) p[t--] = 0; else break; } p[++t] = i; } for (int i = (1); i <= (t); i++) wr[i] = a[p[i]].id; sort(wr + 1, wr + t + 1); for (int i = (1); i <= (t); i++) printf("%d ", wr[i]); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; void solve() { int n; cin >> n; map<pii, vector<int>> ma; for (int i = 0; i < n; i++) { int ra, rb; cin >> ra >> rb; ma[{ra, rb}].push_back(i + 1); } vector<pii> st{ma.rbegin()->first}; for (auto it = ++ma.rbegin(); it != ma.rend(); it++) { pii l = it->first; if (l.first == st.back().first || l.second <= st.back().second) continue; auto check = [&]() { if (int((st).size()) < 2) return false; pii m = st.back(), r = st[int((st).size()) - 2]; return l.first * m.second * ll(l.second - r.second) * (r.first - m.first) > l.second * m.first * ll(m.second - r.second) * (r.first - l.first); }; while (check()) st.pop_back(); st.push_back(l); } vector<int> ans; for (pii &p : st) ans.insert(ans.end(), (ma[p]).begin(), (ma[p]).end()); sort((ans).begin(), (ans).end()); for (int x : ans) cout << x << ' '; } int main() { ios::sync_with_stdio(0), cin.tie(0); int tcs = 1; for (int tc = 1; tc <= tcs; tc++) { solve(); } }
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } template <class T> T gcd(T a, T b) { return a ? gcd(b % a, a) : b; } template <class T> T sqr(T a) { return a * a; } template <class T> T sgn(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); } int n; int m; vector<pair<pair<int, int>, int>> a; long long vect(pair<int, int> a, pair<int, int> b, pair<int, int> c) { return ((long long)b.first - a.first) * ((long long)c.second - a.second) * (long long)b.second * c.first - ((long long)b.second - a.second) * ((long long)c.first - a.first) * (long long)b.first * c.second; } long long vect(int i, int j, int k) { return vect(a[i].first, a[j].first, a[k].first); } int main() { scanf("%d", &n); pair<pair<int, int>, int> right = make_pair(make_pair(-1, -1), -1), down = make_pair(make_pair(-1, -1), -1); map<pair<int, int>, vector<int>> b; for (int i = 0; i < n; i++) { int r, s; scanf("%d%d", &r, &s); if (b.count(make_pair(r, s)) == 0) { a.push_back(make_pair(make_pair(r, s), i)); right = max(make_pair(make_pair(r, s), i), right); down = max(make_pair(make_pair(s, r), i), down); } b[make_pair(r, s)].push_back(i); } sort((a).begin(), (a).end(), [](const pair<pair<int, int>, int>& a, const pair<pair<int, int>, int>& b) { int v = b.first.first * a.first.second - a.first.first * b.first.second; return v > 0 || (v == 0 && 1.0 / sqr(a.first.first) + 1.0 / sqr(a.first.second) > 1.0 / sqr(b.first.first) + 1.0 / sqr(b.first.second)); }); int i = 0; for (; i < n && a[i].second != down.second;) i++; vector<int> st; for (; i < n; i++) { while (((int)(st).size()) > 1 && (vect(*-- --st.end(), *--st.end(), i) > 0 || a[*--st.end()].first == a[i].first)) st.pop_back(); st.push_back(i); if (a[i].second == right.second) break; } vector<int> ans; for (auto& cur : st) { for (auto q : b[a[cur].first]) { ans.push_back(q + 1); } } sort((ans).begin(), (ans).end()); for (auto cur : ans) printf("%d ", cur); return 0; }
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int& head, T&... tail) { scanf("%d", &head); RI(tail...); } int n, s[200010], r[200010], ss[200010], stk[200010], top; pair<int, int> get(int i) { return make_pair(s[i], r[i]); } bool cmp(int a, int b) { return get(a) > get(b); } int main() { RI(n); for (int i = 0; i < int(n); i++) RI(s[i], r[i]); for (int i = 0; i < int(n); i++) ss[i] = i; sort(ss, ss + n, cmp); for (int ii = 0; ii < int(n); ii++) { int i = ss[ii]; if (ii > 0 && get(i) == get(ss[ii - 1])) continue; while (top >= 2) { long long s1 = s[i], r1 = r[i]; long long s2 = s[stk[top - 1]], r2 = r[stk[top - 1]]; long long s3 = s[stk[top - 2]], r3 = r[stk[top - 2]]; if (r1 <= r2) break; long long u1 = (s2 - s1) * r1, d1 = (r1 - r2) * s1; long long u2 = (s3 - s2) * r3, d2 = (r2 - r3) * s3; assert(u1 >= 0 && d1 > 0 && u2 >= 0 && d2 > 0); if (u1 * d2 >= u2 * d1) break; top--; } if (top == 0 || (top > 0 && r[i] > r[stk[top - 1]])) stk[top++] = i; } set<pair<int, int> > st; for (int i = 0; i < int(top); i++) st.insert(get(stk[i])); vector<int> sol; for (int i = 0; i < int(n); i++) if (st.count(get(i))) sol.push_back(i); for (int i = 0; i < int(((int)(sol).size())); i++) printf("%d%c", sol[i] + 1, i + 1 == ((int)(sol).size()) ? '\n' : ' '); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int INF = 1e9; const long long IINF = 1e18; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const char dir[4] = {'D', 'R', 'U', 'L'}; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << '{'; for (auto itr = m.begin(); itr != m.end(); ++itr) { os << '(' << itr->first << ',' << itr->second << ')'; if (++itr != m.end()) os << ','; --itr; } os << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &s) { os << '{'; for (auto itr = s.begin(); itr != s.end(); ++itr) { os << *itr; if (++itr != s.end()) os << ','; --itr; } os << '}'; return os; } void debug_out() { cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head &&head, Tail &&...tail) { cerr << head; if (sizeof...(Tail) > 0) cerr << ", "; debug_out(move(tail)...); } template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; } template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; } template <class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } template <typename T, bool isMin = true> struct ConvexHullTrick { struct Line { T a, b; Line(T a, T b) : a(a), b(b) {} }; deque<Line> Lines; bool empty() const { return Lines.empty(); } inline int sgn(T a) { return a == 0 ? 0 : (a < 0 ? -1 : 1); } inline bool check(const Line &a, const Line &b, const Line &c) { if (b.b == a.b || c.b == b.b) return sgn(b.a - a.a) * sgn(c.b - b.b) >= sgn(c.a - b.a) * sgn(b.b - a.b); return (long double)(b.a - a.a) * sgn(c.b - b.b) / (long double)abs(b.b - a.b) >= (long double)(c.a - b.a) * sgn(b.b - a.b) / (long double)abs(c.b - b.b); } void add(T a, T b) { if (!isMin) a *= -1, b *= -1; Line l(a, b); if (empty()) { Lines.emplace_back(l); return; } if (Lines.front().a <= a) { if (Lines.front().a == a) { if (Lines.front().b <= b) return; Lines.pop_front(); } while (Lines.size() >= 2 && check(l, Lines.front(), Lines[1])) Lines.pop_front(); Lines.emplace_front(l); } else { if (Lines.back().a == a) { if (Lines.back().b <= b) return; Lines.pop_back(); } while (Lines.size() >= 2 && check(Lines[Lines.size() - 2], Lines.back(), l)) Lines.pop_back(); Lines.emplace_back(l); } } inline T f(const Line &l, const T &x) { return l.a * x + l.b; } T query(T x) { int lb = -1, ub = Lines.size() - 1; while (ub - lb > 1) { int mid = (ub + lb) >> 1; (f(Lines[mid], x) >= f(Lines[mid + 1], x) ? lb : ub) = mid; } return (isMin ? f(Lines[ub], x) : -f(Lines[ub], x)); } T query_monotone_inc(T x) { while (Lines.size() >= 2 && f(Lines.front(), x) >= f(Lines[1], x)) Lines.pop_front(); return (isMin ? f(Lines.front(), x) : -f(Lines.front(), x)); } T query_monotone_dec(T x) { while (Lines.size() >= 2 && f(Lines.back(), x) >= f(Lines[Lines.size() - 2], x)) Lines.pop_back(); return (isMin ? f(Lines.back(), x) : -f(Lines.back(), x)); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<tuple<long long, long long, int>> sr; for (int i = 0; i < n; ++i) { long long s, r; cin >> s >> r; sr.emplace_back(s, r, i); } sort((sr).begin(), (sr).end()); struct Line { long long s, r; vector<int> idxs; Line(long long s, long long r, int id) : s(s), r(r) { idxs.emplace_back(id); } }; deque<Line> Lines; auto check = [](Line a, Line b, Line c) { return c.s * a.r * (b.r - c.r) * (a.s - b.s) > a.s * c.r * (a.r - b.r) * (b.s - c.s); }; auto add = [&](int s, int r, int id) { if (Lines.empty()) { Lines.emplace_back(s, r, id); return; } Line l(s, r, id); if (Lines.back().s == s) { if (Lines.back().r > r) return; else if (Lines.back().r < r) Lines.pop_back(); else { Lines.back().idxs.emplace_back(id); return; } } while (Lines.size() >= 2 && check(Lines[Lines.size() - 2], Lines.back(), l)) Lines.pop_back(); Lines.emplace_back(l); }; for (int i = 0; i < n; ++i) add(get<0>(sr[i]), get<1>(sr[i]), get<2>(sr[i])); while (Lines.size() > 1) { Line l1 = Lines[0], l2 = Lines[1]; if (l1.r <= l2.r) Lines.pop_front(); else break; } vector<int> ans; for (auto l : Lines) { for (int id : l.idxs) { ans.emplace_back(id); } } sort((ans).begin(), (ans).end()); for (int i = 0; i < ans.size(); ++i) cout << ans[i] + 1 << (i + 1 == ans.size() ? '\n' : ' '); }
#include <bits/stdc++.h> using namespace std; struct point { int xx, yy; double x, y; point(double x = 0, double y = 0) { this->x = x; this->y = y; } void init(int xx, int yy) { this->xx = xx, this->yy = yy; x = 1.0 / xx; y = 1.0 / yy; } point operator+(const point& a) const { return point(x + a.x, y + a.y); } point operator-(const point& a) const { return point(x - a.x, y - a.y); } bool operator==(point& p) { return p.xx == xx && p.yy == yy; } }; vector<point> a; vector<point> ch; vector<point> upper, lower; double crossProduct(point first, point second, point third) { return (second.x - first.x) * (third.y - first.y) - (second.y - first.y) * (third.x - first.x); } bool leftLower(point first, point second) { if (first.x == second.x) return first.y < second.y; return first.x < second.x; } void convexHull() { if (int((a).size()) <= 3) { for (int i = (0); i <= (int((a).size()) - 1); i++) ch.push_back(a[i]); return; } sort((a).begin(), (a).end(), leftLower); upper.push_back(a[0]); upper.push_back(a[1]); for (int i = (2); i <= (int((a).size()) - 1); i++) { upper.push_back(a[i]); while (int((upper).size()) >= 3 && crossProduct(upper[int((upper).size()) - 3], upper[int((upper).size()) - 2], upper[int((upper).size()) - 1]) > 1e-22) { upper.erase(upper.end() - 2); } } for (int i = (0); i <= (int((upper).size()) - 1); i++) ch.push_back(upper[i]); lower.push_back(a[int((a).size()) - 1]); lower.push_back(a[int((a).size()) - 2]); for (int i = (int((a).size()) - 3); i >= (0); i--) { lower.push_back(a[i]); while (int((lower).size()) >= 3 && crossProduct(lower[int((lower).size()) - 3], lower[int((lower).size()) - 2], lower[int((lower).size()) - 1]) > 1e-22) { lower.erase(lower.end() - 2); } } for (int i = (1); i <= (int((lower).size()) - 2); i++) ch.push_back(lower[i]); } map<pair<int, int>, vector<int> > ma; vector<int> res; int n; point leftMost, downMost; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = (1); i <= (n); i++) { int a, b; cin >> a >> b; ma[pair<int, int>(a, b)].push_back(i); } if (int((ma).size()) == 1) { for (int i = (1); i <= (n); i++) cout << i << " "; return 0; } for (__typeof((ma).begin()) it = (ma).begin(); it != (ma).end(); it++) { pair<int, int> z = it->first; point p; p.init(z.first, z.second); a.push_back(p); } convexHull(); leftMost = downMost = ch[0]; for (int i = (1); i <= (int((ch).size()) - 1); i++) if (ch[i].x < leftMost.x) leftMost = ch[i]; else if (leftMost.x == ch[i].x && leftMost.y > ch[i].y) leftMost = ch[i]; for (int i = (1); i <= (int((ch).size()) - 1); i++) if (ch[i].y < downMost.y) downMost = ch[i]; else if (downMost.y == ch[i].y && downMost.x > ch[i].x) downMost = ch[i]; if (int((ch).size()) == 3) { if (crossProduct(ch[0], ch[1], ch[2]) > 1e-22) reverse((ch).begin(), (ch).end()); } for (int i = (0); i <= (int((ch).size()) - 1); i++) if (ch[i] == leftMost) { int u = i; while (1) { vector<int> z = ma[pair<int, int>(ch[u].xx, ch[u].yy)]; for (int j = (0); j <= (int((z).size()) - 1); j++) res.push_back(z[j]); if (ch[u] == downMost) break; u = (u - 1 + int((ch).size())) % int((ch).size()); } break; } sort((res).begin(), (res).end()); for (int i = (0); i <= (int((res).size()) - 1); i++) cout << res[i] << " "; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 11; const double eps = 1e-15; const double inf = 1e9; struct Tpoint { double x, y; Tpoint() {} Tpoint(double x_, double y_) { x = x_, y = y_; } }; Tpoint operator-(const Tpoint &a, const Tpoint &b) { return Tpoint(a.x - b.x, a.y - b.y); } Tpoint operator+(const Tpoint &a, const Tpoint &b) { return Tpoint(a.x + b.x, a.y + b.y); } Tpoint operator/(const Tpoint &a, double k) { return Tpoint(a.x / k, a.y / k); } Tpoint operator*(const Tpoint &a, double k) { return Tpoint(a.x * k, a.y * k); } inline double dot(const Tpoint &a, const Tpoint &b) { return a.x * b.x + a.y * b.y; } inline double cross(const Tpoint &a, const Tpoint &b) { return a.x * b.y - a.y * b.x; } inline int sgn(double x) { if (x < -eps) return -1; return x > eps; } struct Tline { double A, B, C, ang; int tmp; Tpoint pt; bool operator<(const Tline b) const { if (A != b.A) return A < b.A; if (B != b.B) return B < b.B; return C < b.C; } bool include(Tpoint k) { return sgn(dot(k - pt, Tpoint(A, B))) >= 0; } }; inline Tpoint crosspoint(Tline a, Tline b) { double v1 = (b.C * a.B - a.C * b.B); double v2 = (b.C * a.A - a.C * b.A); double v0 = (a.A * b.B - b.A * a.B); return Tpoint(v1 / v0, -v2 / v0); } Tline s[maxn]; int sn, n; inline bool cmp_ang(Tline a, Tline b) { return a.ang < b.ang || (a.ang == b.ang && a.C < b.C); } Tline h[maxn]; bool ok[maxn]; map<Tline, int> cc; bool check() { int l = 1, r = 0; int add = 0; for (int i = 1; i <= sn; i++) { if (i > 1 && (!sgn(s[i].ang - s[i - 1].ang))) continue; while (l < r && !s[i].include(crosspoint(h[r], h[r - 1]))) r--; while (l < r && !s[i].include(crosspoint(h[l], h[l + 1]))) l++; h[++r] = s[i]; } while (l < r && !h[l].include(crosspoint(h[r], h[r - 1]))) r--; while (l < r && !h[r].include(crosspoint(h[l], h[l + 1]))) l++; for (int i = l; i <= r; i++) { ok[h[i].tmp] = 1; cc[h[i]] = 1; } return r - l + 1 >= 3; } int zz[maxn], aa[maxn], bb[maxn]; Tline ttt[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &b); aa[i] = a, bb[i] = b; s[i] = {1.0 / a, -1, 1.0 / b, 0, i, {0, 1.0 / b}}; } s[n + 1] = {1, 0, 0.00001, 0, 0, {0.00001, 0}}; s[n + 2] = {0, 1, 0.00001, 0, 0, {0, 0.00001}}; s[n + 3] = {-1, 0, -inf, 0, 0, {inf, 0}}; sn = n + 3; for (int i = 1; i <= sn; i++) { s[i].ang = atan2(s[i].B, s[i].A); ttt[i] = s[i]; } sort(s + 1, s + sn + 1, cmp_ang); check(); for (int i = 1; i <= n; i++) { if (cc[ttt[i]]) printf("%d ", i); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; 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; inline void OPEN(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } double _acos(double x) { double ret = acos(x); if (ret == ret) return ret; if (x < 0) return acos(-1.0); return acos(1.0); } const double PI = _acos(-1); const double EPS = 1e-50; const double INF = 1e6 + 100; struct point { double x, y; int id; point() { x = y = 0.; id = 0; } point(double x, double y) : x(x), y(y) {} point(double x, double y, int id) : x(x), y(y), id(id) {} }; point operator-(const point &p1, const point &p2) { return point(p1.x - p2.x, p1.y - p2.y); } point operator+(const point &p1, const point &p2) { return point(p1.x + p2.x, p1.y + p2.y); } point operator*(const point &p, const double &s) { return point(p.x * s, p.y * s); } point operator/(const point &p, const double &s) { return p * (1. / s); } bool operator<(const point &p1, const point &p2) { if (p1.x != p2.x) return p1.x < p2.x; return p1.y < p2.y; } bool operator==(const point &p1, const point &p2) { return fabs(p1.x - p2.x) < EPS && fabs(p1.y - p2.y) < EPS; } double cross(const point &p1, const point &p2) { return p1.x * p2.y - p1.y * p2.x; } bool isRightTurn(const point &p1, const point &p2, const point &p3) { return cross(p2 - p1, p3 - p2) <= 0.; } vector<point> convexHull(vector<point> p) { int m = 0, n = p.size(); vector<point> hull(2 * n); sort(p.begin(), p.end()); for (int i = 0; i < n; ++i) { while (m >= 2 && isRightTurn(hull[m - 2], hull[m - 1], p[i])) --m; hull[m++] = p[i]; } for (int i = n - 1, t = m + 1; i >= 0; --i) { while (m >= t && isRightTurn(hull[m - 2], hull[m - 1], p[i])) --m; hull[m++] = p[i]; } hull.resize(m); return hull; } int n; vector<point> poly; int ans[200005]; map<point, int> h; int group[200005]; int main() { scanf("%d", &n); for (int i = 0; i < (n); ++i) { double r, s; scanf("%lf %lf", &r, &s); if (h.count(point(r, s)) == 0) h[point(r, s)] = i; group[i] = h[point(r, s)]; poly.push_back(point(1. / r, 1. / s, i)); } vector<point> hull = convexHull(poly); double lo = INF; for (int i = 0; i < (((int)(hull).size())); ++i) { if (EPS < lo - hull[i].y) { lo = hull[i].y; ans[group[hull[i].id]] = 1; } } int flag = 0; for (int i = 0; i < (n); ++i) { if (ans[group[i]] == 0) continue; if (flag) printf(" "); else flag = 1; printf("%d", i + 1); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; struct node { int s, r; int id; } a[200050], st[200050], b[200050]; bool cmp(node a, node b) { return a.s > b.s || (a.s == b.s && a.r > b.r); } int sig(double x) { return x > 1e-8 ? 1 : x < -1e-8 ? -1 : 0; } bool check(node a, node b, node c) { double k1 = (1.0 / c.r - 1.0 / b.r) / (1.0 / b.s - 1.0 / c.s); double k2 = (1.0 / b.r - 1.0 / a.r) / (1.0 / a.s - 1.0 / b.s); if (sig(k1 - k2) <= 0) return true; else return false; } int q[200050]; map<pair<int, int>, int> mp; 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].id = i; b[i] = a[i]; } sort(a, a + n, cmp); int mx = a[0].r, tail = 1; for (int i = 1; i < n; ++i) { if (a[i].r <= mx) continue; mx = a[i].r; a[tail++] = a[i]; } int top = 0; for (int i = 0; i < tail; ++i) { if (top < 2) { st[top++] = a[i]; } else { while (top >= 2 && !check(st[top - 2], st[top - 1], a[i])) top--; st[top++] = a[i]; } } tail = 0; for (int i = 0; i < top; ++i) { int x = st[i].id; mp[make_pair(b[x].s, b[x].r)] = 1; } for (int i = 0; i < n; ++i) { if (mp.find(make_pair(b[i].s, b[i].r)) != mp.end()) q[tail++] = i; } sort(q, q + tail); for (int i = 0; i < tail; ++i) { printf("%d", q[i] + 1); if (i == tail - 1) puts(""); else printf(" "); } }
#include <bits/stdc++.h> using namespace std; const int N = 200005; const double inf = 1e18; struct data { long long r, s; int id; } dat[N], tmp[N]; long long mx[N]; int idx, n; bool flag[N], flag2[N]; int p[N]; bool cmp(data a, data b) { if (a.r < b.r) return true; if (a.r == b.r && a.s < b.s) return true; return false; } double f(int a, int b) { return (double)dat[a].r * (dat[a].s - dat[b].s) / (double)(dat[a].s * (dat[b].r - dat[a].r)); } double f2(int a, int b) { return (double)dat[b].r * (dat[a].s - dat[b].s) / (double)(dat[b].s * (dat[b].r - dat[a].r)); } double getL(int ix) { int l = 1, r = ix - 1, m1, m2; if (l > r) return 0; double val1, val2, ret = -inf; while (r - l > 5) { m1 = (l + r) / 2; m2 = m1 + 1; val1 = f(m1, ix); val2 = f(m2, ix); if (val1 >= val2) { r = m2; } else { l = m1; } } for (int i = l; i <= r; i++) { ret = max(ret, f(i, ix)); } return ret; } double getR(int ix) { int l = ix + 1, r = idx - 1, m1, m2; if (l > r) return 0; double val1, val2, ret = inf; while (r - l > 5) { m1 = (l + r) / 2; m2 = m1 + 1; val1 = f2(ix, m1); val2 = f2(ix, m2); if (val1 >= val2) { l = m1; } else { r = m2; } } for (int i = l; i <= r; i++) { ret = min(ret, f2(ix, i)); } return ret; } int find(int x) { if (p[x] == x) return x; return p[x] = find(p[x]); } int main() { cin >> n; for (int i = 1; i <= n; i++) p[i] = i; for (int i = 1; i <= n; i++) { cin >> tmp[i].r >> tmp[i].s; tmp[i].id = i; } sort(tmp + 1, tmp + n + 1, cmp); tmp[n + 1].r = tmp[n + 1].s = 100000; mx[n + 1] = 0; idx = 1; for (int i = n; i >= 1; i--) { mx[i] = max(mx[i + 1], tmp[i].s); if (tmp[i].s == tmp[i + 1].s && tmp[i].r == tmp[i + 1].r) { flag[i] = true; p[tmp[i].id] = find(p[tmp[i + 1].id]); continue; } if (tmp[i].s <= mx[i + 1]) flag[i] = true; } for (int i = 1; i <= n; i++) { if (flag[i]) continue; dat[idx++] = tmp[i]; } vector<int> ans; for (int i = 1; i < idx; i++) { if (i == 1 || i == idx - 1) { flag2[dat[i].id] = true; } else if (getL(i) <= getR(i)) { flag2[dat[i].id] = true; } } int pa; for (int i = 1; i <= n; i++) { pa = find(p[tmp[i].id]); if (!flag2[pa]) continue; ans.push_back(tmp[i].id); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) { if (i > 0) cout << " "; cout << ans[i]; } cout << endl; 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> 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; multiset<long long> second; multiset<long long>::iterator it; 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 (i = 0; i < n; i++) second.insert(v1[i].first.second); for (i = 0; i < n; i++) { second.erase(second.find(v1[i].first.second)); if (second.size() == 0) { v.push_back(make_pair(make_pair(v1[i].first.first, v1[i].first.second), v1[i].second)); continue; } it = second.lower_bound(v1[i].first.second); if (it == second.end()) v.push_back(make_pair(make_pair(v1[i].first.first, v1[i].first.second), v1[i].second)); } 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; int sgn(int x) { if (x < 0) return -1; if (x == 0) return 0; return 1; } struct Frac { __int128 up; __int128 dw; Frac() { up = 0; dw = 1; } Frac(__int128 up_, __int128 dw_) { up = up_; dw = dw_; assert(dw > 0); } bool operator<(const Frac &other) const { __int128 a = up; __int128 b = dw; __int128 x = other.up; __int128 y = other.dw; return a * y < x * b; } bool operator==(const Frac &other) const { return (up * other.dw == other.up * dw); } Frac operator-(const Frac &other) const { __int128 a = up; __int128 b = dw; __int128 x = other.up; __int128 y = other.dw; return Frac(a * y - x * b, b * y); } Frac operator+(const Frac &other) const { __int128 a = up; __int128 b = dw; __int128 x = other.up; __int128 y = other.dw; return Frac(a * y + x * b, b * y); } Frac operator*(const Frac &other) const { __int128 a = up; __int128 b = dw; __int128 x = other.up; __int128 y = other.dw; return Frac(a * x, b * y); } }; struct Point { Frac x; Frac y; Point() {} Point(Frac x_, Frac y_) { x = x_; y = y_; } Point operator-(const Point &other) const { return Point(x - other.x, y - other.y); } Frac operator*(const Point &other) const { return x * other.y - y * other.x; } Frac dist(const Point &other) const { Frac dx = x - other.x; Frac dy = y - other.y; return dx * dy + dy * dy; } bool operator<(const Point &other) const { if (x == other.x) { return y < other.y; } else { return x < other.x; } } bool operator==(const Point &other) const { return x == other.x && y == other.y; } }; const Frac ZR = Frac(0, 1); const Frac INF = Frac(1e4, 1); vector<int> solve(vector<Point> a) { int n = (int)a.size(); int to = min_element(a.begin(), a.end()) - a.begin(); Point lf = a[to]; vector<int> ind; for (int i = 0; i < n; i++) { if (i != to) { ind.push_back(i); } } auto cmp = [&](int i, int j) { Point f = (a[i] - lf); Point s = (a[j] - lf); Frac ml = f * s; if (ml == ZR) { if (a[i].x == a[j].x) { return a[i].y < a[j].y; } else { return a[i].x < a[j].x; } } else { return ZR < ml; } }; sort(ind.begin(), ind.end(), cmp); auto can = [&](int i, int j, int k) { Point f = (a[j] - a[i]); Point s = (a[k] - a[j]); if (f * s < ZR) { return 0; } else { return 1; } }; vector<int> st = {to}; for (auto k : ind) { while ((int)st.size() >= 2) { if (can(st.rbegin()[1], st.rbegin()[0], k)) { break; } else { st.pop_back(); } } st.push_back(k); } return st; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr << fixed << setprecision(6); int n; cin >> n; vector<Point> a(n); for (auto &t : a) { int r, s; cin >> s >> r; t = Point(Frac(1, s), Frac(1, r)); } vector<Point> na = a; sort(na.begin(), na.end()); na.resize(unique(na.begin(), na.end()) - na.begin()); map<Point, vector<int>> rp; for (int i = 0; i < n; i++) { rp[a[i]].push_back(i); } auto ch = solve(na); Frac min_y = INF; for (int i = 0; i < (int)ch.size(); i++) { if (na[ch[i]].y < min_y) { min_y = na[ch[i]].y; } } Frac min_x = INF; for (int i = 0; i < (int)ch.size(); i++) { if (na[ch[i]].y == min_y && na[ch[i]].x < min_x) { min_x = na[ch[i]].x; } } int w = -1; for (int i = 0; i < (int)ch.size(); i++) { if (na[ch[i]].y == min_y && na[ch[i]].x == min_x) { w = i; } } vector<Point> ans; for (int i = 0; i <= w; i++) { ans.push_back(na[ch[i]]); } vector<int> res; for (auto p : ans) { for (auto ind : rp[p]) { res.push_back(ind); } } sort(res.begin(), res.end()); for (auto x : res) { cout << x + 1 << ' '; } cout << '\n'; }
#include <bits/stdc++.h> std::default_random_engine random_engine(0xdeadbeef); template <class T> inline T randint(T L, T R) { return std::uniform_int_distribution<T>(L, R)(random_engine); } using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int sgn(long long x) { return x < 0 ? -1 : 1; } struct pt { long long x, y; void normalize() { if (y < 0) x *= -1, y *= -1; long long g = gcd(abs(x), abs(y)); x /= g; y /= g; } pt operator+(const pt& o) const { pt ret; ret.x = x * o.y + o.x * y; ret.y = y * o.y; ret.normalize(); return ret; } pt operator-(const pt& o) const { pt ret; ret.x = x * o.y - o.x * y; ret.y = y * o.y; ret.normalize(); return ret; } pt operator*(const pt& o) const { pt ret; ret.x = x * o.x; ret.y = y * o.y; ret.normalize(); return ret; } bool operator==(const pt& o) const { return x == o.x && y == o.y; } bool operator!=(const pt& o) const { return !(*this == o); } bool operator<(const pt& o) const { if (*this == o) return false; if (x == 0) return true; if (o.x == 0) return false; long long a = x / y; long long b = o.x / o.y; if (a != b) return a < b; pt p; p.x = x - a * y, p.y = y; pt q; q.x = o.x - b * o.y, q.y = o.y; int sign = sgn(p.x) * sgn(q.x); swap(p.x, p.y); swap(q.x, q.y); p.normalize(); q.normalize(); if (sign == 1) return q < p; return p < q; } bool operator<=(const pt& o) const { return *this == o || *this < o; } }; int N; pair<pt, pt> A[200001]; pair<int, int> B[200000]; pair<int, int> C[200000]; bool negative(pair<pt, pt> a, pair<pt, pt> b) { if (sgn((b.second - a.second).x) * sgn((a.first - b.first).x) == -1) return true; if ((a.first - b.first).x > 0) return ((b.second - a.second) * a.first + (a.first - b.first) * a.second) .x <= 0; return ((b.second - a.second) * a.first + (a.first - b.first) * a.second).x >= 0; } bool good(pair<pt, pt> a, pair<pt, pt> b, pair<pt, pt> c) { if (b.first == c.first) return c.second < b.second; pt p = b.second - c.second; pt q = c.first - b.first; pt r = b.second - a.second; pt s = a.first - b.first; if (q.x < 0) p.x *= -1, q.x *= -1; if (s.x < 0) r.x *= -1, s.x *= -1; return p * s < r * q; } bool cmp(const pair<pt, pt>& a, const pair<pt, pt>& b) { if (a.first != b.first) return b.first < a.first; return b.second < a.second; } int main() { scanf("%d", &N); int a, b; for (int i = 0; i < N; i++) { scanf("%d%d", &a, &b); B[i].first = a, B[i].second = b; C[i] = B[i]; } sort(C, C + N); set<pair<int, int>> bad; pair<int, int> maxi = {0, 0}; for (int i = N - 1; i >= 0; i--) { if (maxi > make_pair(C[i].second, C[i].first)) bad.insert({C[i].first, C[i].second}); maxi = max(maxi, {C[i].second, C[i].first}); } int M = 0; A[M].first.x = 1000000000, A[M].first.y = 1; A[M].second.x = 0, A[M].second.y = 1; M++; for (int i = 0; i < N; i++) if (!bad.count({B[i].first, B[i].second})) { A[M].first.x = 1, A[M].first.y = B[i].first; A[M].second.x = 1, A[M].second.y = B[i].second; M++; } sort(A, A + M, cmp); vector<pair<pt, pt>> envelope; for (int i = 0; i < M; i++) { while (envelope.size() >= 1 && envelope.back().first == A[i].first && A[i].second <= envelope.back().second) envelope.pop_back(); while (envelope.size() >= 2 && good(envelope[envelope.size() - 2], envelope.back(), A[i])) envelope.pop_back(); envelope.push_back(A[i]); } set<pair<int, int>> good; for (size_t i = 1; i < envelope.size(); i++) good.insert({(int)envelope[i].first.y, (int)envelope[i].second.y}); for (int i = 0; i < N; i++) if (good.count({B[i].first, B[i].second})) printf("%d ", i + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; double add(double a, double b) { if (abs(a + b) < 1e-10 * (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) > 1e-10) return p.x < q.x; return p.y < q.y; } int pos[200000 + 10] = {0}; int judge(double x) { return x < -1e-10; } vector<P> ps; vector<P> convex_hull(int n) { int k = 0; sort(ps.begin(), ps.end(), 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) < 1e-10 && fabs(ps[i].y - ps[i - 1].y) < 1e-10) { pos[i] = pos[i - 1]; continue; } pos[i] = i; while (k > 1 && judge((qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]))) { k--; } qs[k++] = ps[i]; } qs.resize(k); return qs; } int main() { int n; scanf("%d", &n); double maxv = 1 << 30; for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); P q(100000 / x, 100000 / y); q.id = i; ps.push_back(q); maxv = min(maxv, 100000 / y); } vector<P> last = convex_hull(n); int vis[200000 + 10] = {0}; for (int i = 0; i < last.size(); i++) { vis[last[i].id] = 1; if (fabs(last[i].y - maxv) < 1e-10) { break; } } for (int i = 0; i < n; i++) { if (vis[ps[pos[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 comment(linker, "/STACK:100000000") using namespace std; template <class T> void read(T &x) { char c, mi = 0; while (c = getchar(), c <= 32) ; if (c == '-') mi = 1, x = 0; else if (c < 48 || c > 57) return void(x = c); else x = c - 48; while (c = getchar(), c > 32) x = 10 * x + c - 48; if (mi == 1) x = -x; } template <class T> void read(T &x, T &y) { read(x); read(y); } template <class T> void read(T &x, T &y, T &z) { read(x, y); read(z); } template <class T> void reada(T *a, int n) { for (int i = 0; i < n; ++i) read(a[i]); } template <class T> void write(T x) { static char s[20]; char pt = 0, mi = (x < 0); if (mi == 1) x = -x; while (!pt || x > 0) { s[++pt] = (char)(x % 10 + '0'); x /= 10; } if (mi == 1) putchar('-'); while (pt > 0) putchar(s[pt--]); } template <class T> void write(T x, T y) { write(x); putchar(' '); write(y); } template <class T> void write(T x, T y, T z) { write(x, y); putchar(' '); write(z); } template <class T> void writeln(T x) { write(x); puts(""); } template <class T> void writea(T *a, int n) { for (int i = 0; i < n; ++i) { write(a[i]); putchar(i + 1 == n ? '\n' : ' '); } } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> T qpom(T a, T b, T mod = 1000000007) { T r = 1; while (b > 0) { if (b & 1) r = r * a % mod; a = a * a % mod; b /= 2; } return r; } template <class T> T qpow(T a, T b) { T r = 1; while (b > 0) { if (b & 1) r *= a; a *= a; b /= 2; } return r; } template <class T> T imin(T a, T b) { return a < b ? a : b; } template <class T> T imax(T a, T b) { return a > b ? a : b; } template <class T> inline void rmin(T &a, const T &b) { if (a > b) a = b; } template <class T> inline void rmax(T &a, const T &b) { if (a < b) a = b; } template <class T> T sqr(const T &a) { return a * a; } int n; int s[200010], r[200010]; vector<pair<pair<int, int>, int> > V, U, D; set<pair<int, int> > all; bool ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) { pair<int, int> ab = make_pair(a.first * (b.second - a.second), a.second * (b.first - a.first)); pair<int, int> cb = make_pair(c.first * (b.second - c.second), c.second * (b.first - c.first)); return 1LL * ab.first * cb.second - 1LL * ab.second * cb.first > 0; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", &s[i], &r[i]); V.push_back(make_pair(make_pair(s[i], r[i]), i)); } sort(V.begin(), V.end()); for (int i = 0; i < V.size(); ++i) { while (!U.empty() && U.back().first.second <= V[i].first.second) { U.pop_back(); } U.push_back(V[i]); } V.swap(U); U.clear(); for (int i = 0; i < V.size(); ++i) { while (U.size() >= 2 && ccw(U[U.size() - 2].first, U[U.size() - 1].first, V[i].first)) { U.pop_back(); } U.push_back(V[i]); } vector<int> ans; V.swap(U); for (int i = 0; i < V.size(); ++i) { all.insert(V[i].first); } for (int i = 1; i <= n; ++i) { if (all.count(make_pair(s[i], r[i]))) { ans.push_back(i); } } writea(&ans[0], ans.size()); getchar(); getchar(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200200; const double eps = 1e-15; int i, j, k, n, m, ch; int fg[N]; double ab(double x) { if (x < 0) return -x; return x; } struct point { double x, y; int id; bool operator<(const point &n) const { if (ab(x - n.x) < eps) return y + eps < n.y; return x + eps < n.x; } } mx, my, A[N], B[N]; void R(int &x) { x = 0; ch = getchar(); while (ch < '0' || '9' < ch) ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); } void W(int x) { if (x >= 10) W(x / 10); putchar(x % 10 + '0'); } double Js(point a, point b, point c) { double x1 = b.x - a.x, y1 = b.y - a.y; double x2 = c.x - b.x, y2 = c.y - b.y; return x1 * y2 - x2 * y1; } int main() { R(n); mx.x = my.y = 1e9; for (i = 1; i <= n; i++) { int x, y; R(x); R(y); A[i].x = 1.0 / (1.0 * x); A[i].y = 1.0 / (1.0 * y); A[i].id = i; B[i] = A[i]; if (A[i].x + eps < mx.x || (ab(A[i].x - mx.x) < eps && A[i].y + eps < mx.y)) mx = A[i]; if (A[i].y + eps < my.y || (ab(A[i].y - my.y) < eps && A[i].x + eps < my.x)) my = A[i]; } for (i = 1; i <= n; i++) { if (!(A[i].x + eps < mx.x) && !(A[i].y + eps < mx.y) && (A[i].x > mx.x + eps || A[i].y > mx.y + eps)) continue; if (!(A[i].x + eps < my.x) && !(A[i].y + eps < my.y) && (A[i].x > my.x + eps || A[i].y > my.y + eps)) continue; A[++m] = A[i]; } sort(A + 1, A + m + 1); sort(B + 1, B + n + 1); j = 0; for (i = 1; i <= m; i++) { while (j >= 2 && Js(A[j - 1], A[j], A[i]) <= 0) j--; A[++j] = A[i]; } m = j; j = 1; for (i = 1; i <= n; i++) { while (j < m && A[j + 1].x + eps < B[i].x) j++; if (j == m) { if (ab(B[i].x - A[j].x) < eps && ab(B[i].y - A[j].y) < eps) fg[B[i].id] = 1; continue; } if (Js(A[j], B[i], A[j + 1]) == 0) fg[B[i].id] = 1; } for (i = 1; i <= n; i++) if (fg[i]) W(i), putchar(' '); puts(""); }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000003; int m; int n; int x[200001]; int y[200002]; int p[200002]; int l; int s[200002]; vector<int> v[200002]; bool cmp(int i, int j) { return x[i] > x[j] || (x[i] == x[j] && y[i] > y[j]); } bool cross(int a, int b, int c) { return (long long)(x[a] - x[c]) * (y[a] - y[b]) * x[b] * y[c] > (long long)(y[a] - y[c]) * (x[a] - x[b]) * x[c] * y[b]; } int main(int argc, char *argv[]) { cin >> n; for (int i = 0; i < n; ++i) scanf("%d %d", x + i, y + i); for (int i = 0; i < n; ++i) p[i] = i; sort(p, p + n, cmp); m = 1; s[0] = p[0]; for (int i = 1; i < n; ++i) { int j = p[i]; if (x[s[m - 1]] == x[j] && y[s[m - 1]] == y[j]) { v[s[m - 1]].push_back(j); continue; } if (y[j] <= y[s[m - 1]]) continue; while (m > 1 && cross(s[m - 2], s[m - 1], j)) --m; s[m++] = j; } for (int i = 0; i < m; ++i) { for (int j : v[s[i]]) s[m++] = j; } sort(s, s + m); for (int i = 0; i < m; ++i) printf("%d ", s[i] + 1); cout << endl; }
#include <bits/stdc++.h> using namespace std; struct Girl { double s, r; }; Girl girl[200000]; int p[200000]; int shell[200000]; int all[200000]; int num = 0; int total = 0; bool cmp(const int& a, const int& b) { return girl[a].s < girl[b].s || (girl[a].s == girl[b].s && girl[a].r > girl[b].r); } Girl operator-(const Girl& a, const Girl& b) { return (Girl){a.s - b.s, a.r - b.r}; } double cross(const Girl& a, const Girl& b) { return a.s * b.r - a.r * b.s; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lf %lf", &girl[i].s, &girl[i].r); girl[i].s = 1 / girl[i].s; girl[i].r = 1 / girl[i].r; p[i] = i; } sort(p, p + n, cmp); for (int i = 0; i < n; ++i) { if (!(num > 0 && ((girl[p[i]].s > girl[shell[num - 1]].s && girl[p[i]].r >= girl[shell[num - 1]].r) || (girl[p[i]].s >= girl[shell[num - 1]].s && girl[p[i]].r > girl[shell[num - 1]].r)))) { if (!(num > 0 && girl[p[i]].s == girl[shell[num - 1]].s && girl[p[i]].r == girl[shell[num - 1]].r)) { while ((num > 0 && girl[p[i]].s <= girl[shell[num - 1]].s && girl[p[i]].r <= girl[shell[num - 1]].r) || (num > 1 && cross(girl[shell[num - 1]] - girl[shell[num - 2]], girl[p[i]] - girl[shell[num - 2]]) <= 0)) { while (total > 0 && girl[all[total - 1]].s == girl[shell[num - 1]].s && girl[all[total - 1]].r == girl[shell[num - 1]].r) { total--; } num--; } shell[num++] = p[i]; } all[total++] = p[i]; } } sort(all, all + total); for (int i = 0; i < total; ++i) { if (i) { printf(" "); } printf("%d", all[i] + 1); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int mark[11111]; bool isok[11111]; int stk[211111], sz; int s[211111], r[211111]; bool jud(int idx) { int i = stk[sz - 2], j = stk[sz - 1]; return 1LL * (mark[j] - mark[i]) * j * mark[idx] * (i - idx) >= 1LL * (mark[idx] - mark[i]) * idx * mark[j] * (i - j); } int main() { int n; scanf("%d", &n); int ma = 0; for (int i = 1; i <= n; i++) { scanf("%d%d", &s[i], &r[i]); mark[s[i]] = max(mark[s[i]], r[i]); ma = max(ma, s[i]); } int lr = 0; for (int i = ma; i > 0; i--) { if (mark[i] <= lr) continue; while (sz > 1 && !jud(i)) sz--; stk[sz++] = i; lr = mark[i]; } while (sz) { isok[stk[sz - 1]] = 1; sz--; } for (int i = 1; i <= n; i++) { if (r[i] == mark[s[i]] && isok[s[i]]) printf("%d ", i); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; struct compet { double x, y; int ind; }; int n; int s[300000]; int r[300000]; double si[300000]; double ri[300000]; double epsilon = 0.000000000000000000000000000000001; int mins, minr; int orijent(compet a, compet b, compet c) { double d = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); if (d - 0 < epsilon && 0 - d < epsilon) { double db, dc; db = (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y); dc = (c.x - a.x) * (c.x - a.x) + (c.y - a.y) * (c.y - a.y); if (dc - db > epsilon) return 1; if (db - dc > epsilon) return -1; return 0; } if (d > epsilon) return 1; else return -1; } compet a[300000]; bool v[300000]; bool operator<(compet b, compet c) { return orijent(a[0], b, c) > 0; } stack<int> b; int next_to_top() { int pom, p; pom = b.top(); b.pop(); p = b.top(); b.push(pom); return p; } int graham() { v[a[0].ind] = true; b.push(0); b.push(1); b.push(2); for (int i = 3; i < n; i++) { while (b.size() >= 2 && orijent(a[next_to_top()], a[b.top()], a[i]) <= 0) b.pop(); b.push(i); } double xp = a[0].x; double yp = a[0].y; int ip = a[0].ind; v[ip] = true; while (b.size() > 0) { if (xp - a[b.top()].x > epsilon || (a[b.top()].x - xp < epsilon && yp - a[b.top()].y < epsilon && a[b.top()].y - yp < epsilon)) { xp = a[b.top()].x; yp = a[b.top()].y; v[a[b.top()].ind] = true; b.pop(); } else break; } } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", &s[i], &r[i]); si[i] = s[i]; si[i] = 1 / si[i]; ri[i] = r[i]; ri[i] = 1 / ri[i]; a[i].x = si[i]; a[i].y = ri[i]; a[i].ind = i; } if (n == 1) { printf("1"); return 0; } if (n == 2) { if (s[0] > s[1] || r[0] > r[1]) { printf("1 "); } if (s[1] > s[0] || r[1] > r[0]) { printf("2 "); } if (s[0] == s[1] && r[0] == r[1]) { printf("1 2"); return 0; } return 0; } int ind = 0; compet pom; for (int i = 1; i < n; i++) { if (a[ind].y - a[i].y > epsilon || (a[ind].y - a[i].y < epsilon && a[i].y - a[ind].y < epsilon && a[ind].x - a[i].x > epsilon)) ind = i; } pom = a[0]; a[0] = a[ind]; v[ind] = true; a[ind] = pom; sort(a + 1, a + n); graham(); for (int i = 1; i < n; i++) { if (v[a[i - 1].ind] && a[i].x - a[i - 1].x < epsilon && a[i - 1].x - a[i].x < epsilon && a[i].y - a[i - 1].y < epsilon && a[i - 1].y - a[i].y < epsilon) { v[a[i].ind] = true; } } for (int i = n - 2; i >= 0; i--) { if (v[a[i + 1].ind] && a[i].x - a[i + 1].x < epsilon && a[i + 1].x - a[i].x < epsilon && a[i].y - a[i + 1].y < epsilon && a[i + 1].y - a[i].y < epsilon) { v[a[i].ind] = true; } } for (int i = 0; i <= n; i++) { if (v[i]) printf("%d ", i + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200200; const double eps = 1e-15; int i, j, k, n, m, ch; int fg[N]; double ab(double x) { if (x < 0) return -x; return x; } struct point { double x, y; int id; bool operator<(const point &n) const { if (ab(x - n.x) < eps) return y + eps < n.y; return x + eps < n.x; } } mx, my, A[N], B[N]; void R(int &x) { x = 0; ch = getchar(); while (ch < '0' || '9' < ch) ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); } void W(int x) { if (x >= 10) W(x / 10); putchar(x % 10 + '0'); } double Js(point a, point b, point c) { double x1 = b.x - a.x, y1 = b.y - a.y; double x2 = c.x - b.x, y2 = c.y - b.y; return x1 * y2 - x2 * y1; } int main() { R(n); mx.x = my.y = 1e9; for (i = 1; i <= n; i++) { int x, y; R(x); R(y); A[i].x = 1.0 / (1.0 * x); A[i].y = 1.0 / (1.0 * y); A[i].id = i; B[i] = A[i]; if (A[i].x + eps < mx.x || (ab(A[i].x - mx.x) < eps && A[i].y + eps < mx.y)) mx = A[i]; if (A[i].y + eps < my.y || (ab(A[i].y - my.y) < eps && A[i].x + eps < my.x)) my = A[i]; } for (i = 1; i <= n; i++) { if (!(A[i].x + eps < mx.x) && !(A[i].y + eps < mx.y) && (A[i].x > mx.x + eps || A[i].y > mx.y + eps)) continue; if (!(A[i].x + eps < my.x) && !(A[i].y + eps < my.y) && (A[i].x > my.x + eps || A[i].y > my.y + eps)) continue; A[++m] = A[i]; } sort(A + 1, A + m + 1); sort(B + 1, B + n + 1); j = 0; for (i = 1; i <= m; i++) { while (j >= 2 && Js(A[j - 1], A[j], A[i]) <= 0) j--; A[++j] = A[i]; } m = j; j = 1; for (i = 1; i <= n; i++) { while (j < m && A[j + 1].x < B[i].x) j++; if (j == m) { if (B[i].x == A[j].x && B[i].y == A[j].y) fg[B[i].id] = 1; continue; } if (Js(A[j], B[i], A[j + 1]) == 0) fg[B[i].id] = 1; } for (i = 1; i <= n; i++) if (fg[i]) W(i), putchar(' '); puts(""); }
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> s[300100]; pair<int, int> r[300100]; int res[300300]; int s1[300300]; int r1[300300]; map<pair<int, int>, int> rep; int dp[94040]; void add(int a, int b, int x, int l = 1, int h = 1e4 + 2, int p = 1) { if (a == l && b == h) { dp[p] += x; return; } int m = (l + h) / 2; if (b <= m) { add(a, b, x, l, m, 2 * p); } else if (a > m) { add(a, b, x, m + 1, h, 2 * p + 1); } else { add(m + 1, b, x, m + 1, h, 2 * p + 1); add(a, m, x, l, m, 2 * p); } dp[p] = dp[2 * p] + dp[2 * p + 1]; } int cal(int a, int b, int x = 0, int l = 1, int h = 1e4 + 2, int p = 1) { if (a == l && b == h) { return dp[p]; } int m = (l + h) / 2; if (b <= m) { return cal(a, b, x, l, m, 2 * p); } else if (a > m) { return cal(a, b, x, m + 1, h, 2 * p + 1); } else { return cal(m + 1, b, x, m + 1, h, 2 * p + 1) + cal(a, m, x, l, m, 2 * p); } } map<pair<int, int>, int> ch; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &s[i].first); scanf("%d", &r[i].first); r[i].second = i; s[i].second = i; rep[make_pair(s[i].first, r[i].first)]++; s1[i] = s[i].first; r1[i] = r[i].first; } sort(s + 1, s + n + 1); for (int i = 1; i <= n;) { int j; for (j = i; j <= n; j++) { if (s[i].first != s[j].first) break; int in = s[j].second; res[in] += i - 1; if (r[in].first - 1 >= 1) res[in] -= cal(1, r[in].first - 1); } for (int k = i; k < j; k++) { int in = s[k].second; add(r[in].first, r[in].first, 1); } i = j; } sort(r + 1, r + n + 1); for (int i = 1; i <= n;) { int j; for (j = i; j <= n; j++) { if (r[i].first != r[j].first) break; int in = r[j].second; res[in] += i - 1; } i = j; } vector<pair<long long, long long> > v; for (int i = 1; i <= n; i++) { if (res[i] == n - rep[make_pair(s1[i], r1[i])] && !ch.count(make_pair(s1[i], r1[i]))) { ch[make_pair(s1[i], r1[i])] = 1; v.push_back(make_pair(s1[i], r1[i])); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); ch[v[0]]++; if (v.size() > 1) ch[v.back()]++; int m; double t; for (int i = 1; i < v.size() - 1; i++) { double bef = -1e18; int l = i + 1, r = v.size() - 1; while (l <= r) { m = (l + r) / 2; t = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); if (l == r) { bef = max(bef, t); break; } m++; double t1 = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); if (t >= t1) { r = m - 2; bef = max(bef, t); } else { l = m + 1; bef = max(bef, t1); } } m = i + 1; t = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); bef = max(bef, t); m = v.size() - 1; t = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); bef = max(bef, t); double aft = 1e18; l = 0, r = i - 1; while (l <= r) { int m = (l + r) / 2; t = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); if (l == r) { aft = min(aft, t); break; } m++; double t1 = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); if (t <= t1) { r = m - 2; aft = min(aft, t); } else { l = m + 1; aft = min(aft, t1); } } m = 0; t = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); aft = min(aft, t); m = i - 1; t = 1.0 * (1.0 * v[m].second - v[i].second) / (v[m].second * v[i].second) / (1.0 * v[i].first - v[m].first) * (1.0 * v[i].first * v[m].first); aft = min(aft, t); if (aft >= bef) { ch[v[i]]++; } } for (int i = 1; i <= n; i++) { if (ch[make_pair(s1[i], r1[i])] == 2) printf("%d ", i); } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, top, D, m; struct Point { int idx; long long x, y; bool operator<(const Point &rhs) const { return x > rhs.x || x == rhs.x && y > rhs.y; } } h[200200], p[200200]; bool cmp(Point a, Point b) { return a.idx < b.idx; } vector<int> save[200200], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) p[i].idx = i, scanf("%I64d%I64d", &p[i].x, &p[i].y); sort(p + 1, p + n + 1); for (int i = 1; i <= n; i++) if (p[i].x == p[m].x && p[i].y == p[m].y) save[p[m].idx].push_back(p[i].idx); else p[++m] = p[i], save[p[i].idx].push_back(p[i].idx); D = 1; for (int i = 1; i <= m; i++) if (p[i].y > p[D].y) D = i; h[top = 1] = p[1]; for (int i = 2; i <= D; i++) { while (top > 1) { Point a = h[top], b = h[top - 1], P = p[i]; if ((a.y - P.y) * P.x * b.y * (b.x - a.x) < b.x * (b.y - a.y) * (a.x - P.x) * P.y) top--; else break; } h[++top] = p[i]; } sort(h + 1, h + top + 1, cmp); for (int i = 1; i <= top; i++) { int sz = save[h[i].idx].size(); for (int j = 0; j <= sz - 1; j++) ans.push_back(save[h[i].idx][j]); } sort(ans.begin(), ans.end()); for (int i = 0; i <= ans.size() - 1; i++) printf("%d ", ans[i]); }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> s(n), r(n); for (int i = 0; i < n; i++) { cin >> s[i] >> r[i]; } vector<tuple<int, int, int>> T(n); for (int i = 0; i < n; i++) { T[i] = make_tuple(s[i], r[i], i); } sort(T.begin(), T.end(), greater<tuple<int, int, int>>()); vector<int> id(n); for (int i = 0; i < n; i++) { s[i] = get<0>(T[i]); r[i] = get<1>(T[i]); id[i] = get<2>(T[i]); } int mx = -1, ms = -1; vector<int> s2, r2, id2; vector<vector<int>> p; int n2 = 0; for (int i = 0; i < n; i++) { if (r[i] > mx) { mx = r[i]; ms = s[i]; s2.push_back(s[i]); r2.push_back(r[i]); id2.push_back(id[i]); p.push_back(vector<int>(0)); n2++; } else if (r[i] == mx && s[i] == ms) { p.back().push_back(id[i]); } } stack<int> st; st.push(0); if (n2 > 1) { st.push(1); } for (int i = 2; i < n2; i++) { while (st.size() >= 2) { int b = st.top(); st.pop(); int a = st.top(); st.pop(); long long A = (long long)s2[i] * r2[a] * (r2[b] - r2[i]) * (s2[b] - s2[a]); long long B = (long long)s2[a] * r2[i] * (r2[a] - r2[b]) * (s2[i] - s2[b]); if (A <= B) { st.push(a); st.push(b); break; } else { st.push(a); } } st.push(i); } vector<int> ans; while (!st.empty()) { int x = st.top(); st.pop(); ans.push_back(id2[x]); for (int y : p[x]) { ans.push_back(y); } } sort(ans.begin(), ans.end()); int cnt = ans.size(); for (int i = 0; i < cnt; i++) { cout << ans[i] + 1; if (i < cnt - 1) { cout << ' '; } } cout << endl; }
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long int)1e9 + 10; const long long int INFLL = (long long int)1e18 + 10; const long double EPS = 1e-8; const long double EPSLD = 1e-18; const long long int MOD = 1e9 + 7; template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); } long long int cross(pair<long long int, long long int> a, pair<long long int, long long int> b) { return a.first * b.second - a.second * b.first; } long long int ccw(pair<long long int, long long int> a, pair<long long int, long long int> b, pair<long long int, long long int> c) { pair<long long int, long long int> nb = pair<long long int, long long int>( (a.first - b.first) * c.first * b.second, a.second - b.second); pair<long long int, long long int> nc = pair<long long int, long long int>( (a.first - c.first) * b.first * c.second, a.second - c.second); if (cross(nb, nc) > 0) return +1; if (cross(nb, nc) < 0) return -1; return 0; } const long long int MAX_N = 200010; long long int n; pair<pair<long long int, long long int>, long long int> v[MAX_N]; pair<pair<long long int, long long int>, long long int> ch[MAX_N]; vector<long long int> ans; set<pair<long long int, long long int> > ss; int main() { scanf("%lld", &n); for (long long int i = (0); i < (long long int)(n); i++) scanf("%lld %lld", &v[i].first.first, &v[i].first.second); for (long long int i = (0); i < (long long int)(n); i++) v[i].second = i; sort(v, v + n); reverse(v, v + n); long long int k = 0; for (long long int i = 0; i < n; ch[k++] = v[i++]) while ( (k >= 2 && ccw(ch[k - 2].first, ch[k - 1].first, v[i].first) == -1) || (k >= 1 && ch[k - 1].first == v[i].first)) k--; for (long long int i = (0); i < (long long int)(k); i++) { if (i > 0 && ch[i].first.second <= ch[i - 1].first.second) break; ss.insert(ch[i].first); } for (long long int i = (0); i < (long long int)(n); i++) if (ss.find(v[i].first) != ss.end()) ans.emplace_back(v[i].second); sort((ans).begin(), (ans).end()); for (long long int i = (0); i < (long long int)(((long long int)(ans).size())); i++) printf("%lld%c", ans[i] + 1, i == ((long long int)(ans).size()) - 1 ? '\n' : ' '); return 0; }
#include <bits/stdc++.h> using namespace std; int n, s[200010], r[200010]; struct pt { double x, y; int ind; } t[200010]; bool operator<(const pt& a, const pt& b) { if (s[a.ind] == s[b.ind]) return r[a.ind] > r[b.ind]; return s[a.ind] > s[b.ind]; } double operator^(const pt& a, const pt& b) { return a.x * b.y - a.y * b.x; } bool ontheleft(const pt& a, const pt& b, const pt& c) { long long all1 = (long long)s[a.ind] * r[a.ind]; long long all2 = (long long)s[b.ind] * r[b.ind] * s[c.ind] * r[c.ind]; long long res = (all2 / ((long long)r[b.ind] * s[c.ind])) * (all1) - (all2 / (long long)r[b.ind]) * (all1 / s[a.ind]) - (all2 / (long long)s[c.ind]) * (all1 / r[a.ind]) - (all2 / ((long long)s[b.ind] * r[c.ind])) * (all1) + (all2 / (long long)s[b.ind]) * (all1 / r[a.ind]) + (all2 / (long long)r[c.ind]) * (all1 / s[a.ind]); res = -res; return res > 0; } int stk[200010], top; vector<int> addition[200010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &s[i], &r[i]); for (int i = 1; i <= n; i++) { t[i].x = 1.0 / s[i]; t[i].y = 1.0 / r[i]; t[i].ind = i; } sort(t + 1, t + n + 1); stk[top = 1] = 1; for (int i = 2; i <= n; i++) { if (s[t[i].ind] == s[t[stk[top]].ind] && r[t[i].ind] == r[t[stk[top]].ind]) { addition[t[stk[top]].ind].push_back(t[i].ind); continue; } if (r[t[i].ind] <= r[t[stk[top]].ind]) continue; while (top > 1 && ontheleft(t[stk[top - 1]], t[i], t[stk[top]])) top--; stk[++top] = i; } deque<int> ans; for (int i = 1; i <= top; i++) ans.push_back(t[stk[i]].ind); if (ans.size() >= 2) { int p1 = ans[0], p2 = ans[1]; if (s[p1] == s[p2] || r[p1] == r[p2]) ans.pop_front(); } if (ans.size() >= 2) { int p1 = ans[int(ans.size()) - 2], p2 = ans[int(ans.size()) - 1]; if (s[p1] == s[p2] || r[p1] == r[p2]) ans.pop_back(); } while (ans.size() >= 2) { int p1 = ans[int(ans.size()) - 2], p2 = ans[int(ans.size()) - 1]; if (r[p2] <= r[p1]) ans.pop_back(); else break; } int nowlen = ans.size(); for (int i = 0; i < nowlen; i++) { for (auto x : addition[ans[i]]) ans.push_back(x); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) printf("%d%c", ans[i], " \n"[i + 1 == ans.size()]); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct point { long long x, y; int no; } p[N], q[N], st[N], l, d; int n, cnt, ans[N], m, top; long long cross(point p0, point p1, point p2) { return p1.y * p2.x * (p0.x * p0.y - p0.x * p2.y - p0.y * p1.x + p1.x * p2.y) - p2.y * p1.x * (p0.x * p0.y - p0.y * p2.x - p0.x * p1.y + p1.y * p2.x); } bool lcmp(point p1, point p2) { if (p1.x > p2.x) return true; if (p1.x == p2.x) return p1.y > p2.y; return false; } bool dcmp(point p1, point p2) { if (p1.y > p2.y) return true; if (p1.y == p2.y) return p1.x > p2.x; return false; } bool cmp(point p1, point p2) { long long tmp = cross(d, p1, p2); if (!tmp) return p1.y > p2.y; return tmp < 0LL; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> p[i].x >> p[i].y; p[i].no = i; } sort(p + 1, p + n + 1, lcmp); l = p[1]; sort(p + 1, p + n + 1, dcmp); d = p[1]; sort(p + 1, p + n + 1, cmp); q[++m] = p[1]; for (int i = 2; i <= n; i++) { if (p[i - 1].x != p[i].x || p[i - 1].y != p[i].y) q[++m] = p[i]; if (q[m].x == l.x && q[m].y == l.y) break; } st[0] = q[1]; if (l.x != d.x || l.y != d.y) { st[++top] = q[2]; for (int i = 3; i <= m; i++) { while (top && cross(st[top - 1], st[top], q[i]) > 0LL) top--; st[++top] = q[i]; } } for (int i = 0, j = 1; i <= top && j <= n; i++) { while (j <= n && p[j].x != st[i].x || p[j].y != st[i].y) j++; if (j > n) break; while (j <= n && p[j].x == st[i].x && p[j].y == st[i].y) ans[cnt++] = p[j++].no; } sort(ans, ans + cnt); for (int i = 0; i < cnt - 1; i++) printf("%d ", ans[i]); printf("%d\n", ans[cnt - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 10; const long double INF = 1e15 + 10; const long double Epsilon = 1e-7; struct line { long double v, val_1, val_2; long long s, dp, id; }; line k[MAXN]; vector<long long> res; long long s[MAXN]; long long r[MAXN]; bool cmp1(line a, line b) { if (a.s == b.s) { return (a.v > b.v); } else { return (a.s < b.s); } } bool cmp2(line a, line b) { if (a.s == b.s) { return (a.v < b.v); } else { return (a.s < b.s); } } long double T(long long i, long long j, bool z) { if (k[i].v < k[j].v) { return INF; } if (abs(k[i].v - k[j].v) < Epsilon && abs(k[i].s - k[j].s) < Epsilon) { if (z) { return INF; } else { return 0; } } return (k[j].s - k[i].s) / (long double)(k[i].v - k[j].v); } int main() { ios_base ::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> s[i] >> r[i]; k[i].id = i; k[i].s = r[i]; k[i].v = -(r[i]) / (long double)(s[i]); } sort(k, k + n, cmp1); k[0].dp = 0; k[0].val_1 = INF; for (long long i = 1; i < n; i++) { k[i].dp = i - 1; bool h = false; while (T(k[i].dp, i, 1) - T(k[k[i].dp].dp, k[i].dp, 1) > Epsilon) { h = true; if (k[i].dp == k[k[i].dp].dp) { break; } k[i].dp = k[k[i].dp].dp; } if ((!h && abs(T(i - 1, i, 1) - INF) < Epsilon) || (abs(T(k[i].dp, i, 1) - INF) < Epsilon)) { k[i].dp = i; k[i].val_1 = INF; } else { k[i].val_1 = T(k[i].dp, i, 1); } } for (long long i = 0; i < n; i++) { k[i].s = -k[i].s; k[i].v = -k[i].v; } sort(k, k + n, cmp2); k[0].dp = 0; k[0].val_2 = 0; for (long long i = 1; i < n; i++) { k[i].dp = i - 1; while (T(k[k[i].dp].dp, k[i].dp, 0) - T(k[i].dp, i, 0) > Epsilon) { if (k[i].dp == k[k[i].dp].dp) { break; } k[i].dp = k[k[i].dp].dp; } k[i].val_2 = T(k[i].dp, i, 0); } for (long long i = 0; i < n; i++) { k[i].s = -k[i].s; k[i].v = -k[i].v; } for (long long i = 0; i < n; i++) { if (abs(k[i].val_2 - INF) < Epsilon) { continue; } if (k[i].val_1 - k[i].val_2 > 0 && ((k[i].val_1 * k[i].v) + k[i].s > Epsilon || (k[i].val_2 * k[i].v) + k[i].s > Epsilon)) { res.push_back(k[i].id + 1); } } sort(res.begin(), res.end()); for (long long i = 0; i < res.size(); i++) { cout << res[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; ; 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 bool cross(pt &a, pt &b, pt &c, pt &d) { 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; } 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.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; 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 = 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; struct po { long double x, y; void read() { double x0, y0; scanf("%lf%lf", &x0, &y0); x = 1. / x0, y = 1. / y0; } inline int operator<(const po &A) const { if (x == A.x) return y > A.y; return x < A.x; } po operator-(const po &A) const { return (po){x - A.x, y - A.y}; } long double operator*(const po &A) const { return x * A.y - y * A.x; } bool operator==(const po &A) const { return (A.x == x) && (A.y == y); } long double getang() { return y / x; } } a[200005], stk[200005]; int n; map<long double, int> app; map<po, vector<int> > biao; vector<int> ans; int main() { scanf("%d", &n); for (int i = (int)1; i <= (int)n; i++) { a[i].read(); biao[a[i]].push_back(i); } sort(a + 1, a + n + 1); int top = 0; for (int i = (int)1; i <= (int)n; i++) { if (a[i] == a[i + 1]) continue; if (a[i].x == a[i + 1].x) continue; if (app[a[i].y]) continue; app[a[i].y] = 1; while (top > 1) { long double K1 = (a[i] - stk[top - 1]).getang(); long double K2 = (a[i] - stk[top]).getang(); if (K2 > 1e-6 || K1 > 1e-6) break; if (K2 - K1 >= -1e-12) break; top--; } if (top) { long double U = (a[i] - stk[top]).getang(); if (U > 1e-6) continue; } stk[++top] = a[i]; } vector<int> A; for (int i = (int)1; i <= (int)top; i++) { A = biao[stk[i]]; for (int j = 0; j < (int)A.size(); j++) { ans.push_back(A[j]); } } sort(ans.begin(), ans.end()); for (int i = 0; i < (int)ans.size(); i++) printf("%d ", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T first) { return first * first; } const int maxn = 200011; vector<pair<long long, long long> > a, origin, ans_list; int s[maxn]; int n, top; bool gao(pair<long long, long long> &a, pair<long long, long long> &b, pair<long long, long long> &c) { return (c.second - a.second) * (c.first - b.first) * (a.first * b.second) < (c.first - a.first) * (c.second - b.second) * (a.second * b.first); } int main() { cin >> n; pair<long long, long long> tt; for (int i = 1; i <= n; i++) { cin >> tt.first >> tt.second; a.push_back(tt); origin.push_back(tt); } a.push_back(pair<long long, long long>(1e5 + 1, 0)); a.push_back(pair<long long, long long>(0, 1e5 + 1)); sort(a.begin(), a.end()); for (int i = 0; i <= n + 1; i++) { while (top > 1 && (a[s[top]].second == a[i].second || gao(a[s[top - 1]], a[s[top]], a[i]))) top--; s[++top] = i; } for (int i = 1; i <= top; i++) { ans_list.push_back(a[s[i]]); } sort(ans_list.begin(), ans_list.end()); for (int i = 0; i <= n - 1; i++) if (binary_search(ans_list.begin(), ans_list.end(), origin[i])) printf("%d ", i + 1); return 0; fclose(stdin); }
#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 Size = 2e5 + 5; struct Point { int x, y, id; bool operator<(const Point& p2) const { return make_pair(x, y) > make_pair(p2.x, p2.y); } } p[Size], s[Size]; set<pair<int, int> > st; pair<int, int> b[Size]; int cross(const Point& A, const Point& B, const Point& C) { return 1LL * B.y * C.x * (A.x - B.x) * (A.y - C.y) > 1LL * (A.y - B.y) * (A.x - C.x) * B.x * C.y; } int main() { int n, m; scanf("%d", &n); m = n; for (int i = 0; i < n; ++i) { scanf("%d%d", &p[i].x, &p[i].y); p[i].id = i + 1; b[i] = make_pair(p[i].x, p[i].y); } sort(p, p + n); int top = 0; for (int i = 0; i < n; ++i) { if (!top || s[top - 1].y < p[i].y) s[top++] = p[i]; } memcpy(p, s, sizeof(s)); n = top; top = 0; for (int i = 0; i < n; ++i) { while (top >= 2 && cross(s[top - 1], s[top - 2], p[i])) --top; s[top++] = p[i]; } for (int i = 0; i < top; ++i) { st.insert(make_pair(s[i].x, s[i].y)); } for (int i = 0; i < m; ++i) { if (st.count(b[i])) printf("%d ", i + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-16; struct CPoint { double x, y; int i; CPoint(double xx, double yy) : x(xx), y(yy) {} CPoint() {} void Read() { scanf("%lf%lf", &x, &y); } }; struct CLine { CPoint a, b; CLine(CPoint aa, CPoint bb) : a(aa), b(bb) {} CLine() {} void Read() { scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y); } }; CPoint operator+(CPoint a, CPoint b) { return CPoint(a.x + b.x, a.y + b.y); } CPoint operator-(CPoint a, CPoint b) { return CPoint(a.x - b.x, a.y - b.y); } CPoint operator*(CPoint a, double k) { return CPoint(k * a.x, k * a.y); } CPoint operator*(double k, CPoint a) { return CPoint(k * a.x, k * a.y); } double operator*(CPoint a, CPoint b) { return a.x * b.x + a.y * b.y; } CPoint operator/(CPoint a, double k) { return CPoint(a.x / k, a.y / k); } double operator^(CPoint a, CPoint b) { return a.x * b.y - a.y * b.x; } double cross(CPoint a, CPoint b) { return a.x * b.y - a.y * b.x; } double Length(CPoint p) { return sqrt(p * p); } CPoint unit(CPoint p) { return 1.0 / Length(p) * p; } double project(CPoint p, CPoint n) { return p * (unit(n)); } double area(CPoint a, CPoint b) { return a ^ b * 0.5; } bool isZero(double x) { return -EPS < x && x < EPS; } int Cmp(double x) { if (isZero(x)) { return 0; } if (x > 0) { return 1; } return -1; } double dist(CPoint p, CPoint q) { return Length(p - q); } double dist(CPoint p, CLine l) { return fabs((p - l.a) ^ (p - l.b)) / Length(l.a - l.b); } CPoint Rotate(CPoint a, CPoint b, double alpha) { CPoint p = b - a; return CPoint(a.x + (p.x * cos(alpha) - p.y * sin(alpha)), a.y + (p.x * sin(alpha) + p.y * cos(alpha))); } int sideOfLine(CPoint p, CLine l) { double res = (p - l.a) ^ (p - l.b); if (isZero(res)) { return 0; } else { return res > 0 ? 1 : -1; } } CLine Vertical(CPoint p, CLine l) { return CLine(p, p + (Rotate(l.b, l.a, PI / 2) - l.a)); } CPoint root(CPoint p, CLine l) { return l.a + project(p - l.a, l.b - l.a) * unit(l.b - l.a); } double angle(CLine l, CLine m) { return acos(fabs(project(l.b - l.a, m.b - m.a) / Length(l.b - l.a))); } bool PointOnSegment(CPoint p, CPoint a, CPoint b) { return Cmp(cross(p - a, b - a)) == 0 && Cmp((p - a) * (p - b)) <= 0; } CPoint GetIntersect(CLine l, CLine m, string &s) { if (isZero(cross(l.b - l.a, m.b - m.a))) { if (!sideOfLine(l.a, m)) { s = "LINE"; } else { s = "NONE"; } return CPoint(0, 0); } s = "POINT"; double t = cross(m.b - m.a, l.a - m.a) / cross(l.b - l.a, m.b - m.a); return l.a + (l.b - l.a) * t; } CPoint GetIntersect(CLine l, CLine m) { double t = cross(m.b - m.a, l.a - m.a) / cross(l.b - l.a, m.b - m.a); return l.a + (l.b - l.a) * t; } bool IsCross(CLine l, CLine m) { return sideOfLine(l.a, m) * sideOfLine(l.b, m) <= 0 && sideOfLine(m.a, l) * sideOfLine(m.b, l) <= 0; } int pos[300005]; bool cmp(CPoint a, CPoint b) { if (isZero(a.x - b.x)) { return a.y < b.y; } return a.x < b.x; } double cross(CPoint a, CPoint b, CPoint c) { return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); } int Graham(CPoint *Pts, CPoint *st, int n) { sort(Pts, Pts + n, cmp); int m = 0; for (int i = 0; i < n; i++) { if (i > 0 && Pts[i].x == Pts[i - 1].x && Pts[i].y == Pts[i - 1].y) { pos[i] = i - 1; continue; } pos[i] = i; while (m > 1 && Cmp(cross(st[m - 2], st[m - 1], Pts[i])) < 0) { m--; } st[m].i = Pts[i].i; st[m++] = Pts[i]; } int k = m; for (int i = n - 2; i >= 0; i--) { while (m > k && Cmp(cross(st[m - 2], st[m - 1], Pts[i]) < 0)) { m--; } st[m].i = Pts[i].i; st[m++] = Pts[i]; } return n > 1 ? m - 1 : m; } CPoint a[300005], b[300005]; bool v[300005]; int main() { int n; double minx = 10000.0, miny = 10000.0; memset(v, false, sizeof(v)); pos[0] = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { a[i].Read(); a[i].x = 100.0 / a[i].x; a[i].y = 100.0 / a[i].y; minx = min(minx, a[i].x); miny = min(miny, a[i].y); a[i].i = i; } int cnt = Graham(a, b, n); for (int i = 0; i < cnt; i++) { v[b[i].i] = true; if (isZero(b[i].y - miny)) { break; } } for (int i = 0; i < n; i++) { if (v[a[pos[i]].i]) { v[a[i].i] = true; } } 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; int n, maxx, maxy; struct Piont { int x, y, id; } p[3000001]; int last[3000001], q[3000001], t; double k[3000001]; bool cmp(Piont a, Piont b) { return (a.x > b.x) || (a.x == b.x && a.y > b.y); } bool ok[3000001]; inline double askline(Piont a, Piont b) { return (double)a.x * b.x * (b.y - a.y) / ((double)a.y * b.y * (b.x - a.x)); } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i].x >> p[i].y, p[i].id = i; if (maxy < p[i].y || (maxy == p[i].y && maxx < p[i].x)) maxx = p[i].x, maxy = p[i].y; } sort(p + 1, p + n + 1, cmp); q[t = 1] = 1; for (int i = 2; i <= n && maxx <= p[i].x; i++) { if (p[i].x == p[q[t]].x) { if (p[i].y == p[q[t]].y) last[p[i].id] = last[p[q[t]].id], last[p[q[t]].id] = p[i].id; continue; } while (t > 1 && k[t] > askline(p[q[t]], p[i])) t--; q[++t] = i; k[t] = askline(p[q[t - 1]], p[i]); } for (; t; --t) for (int i = p[q[t]].id; i; i = last[i]) ok[i] = 1; for (int i = 1; i <= n; i++) if (ok[i]) cout << i << ' '; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int maxn = 200010; int n; int s[maxn]; int r[maxn]; vector<pair<int, int> > p, v1, v2; map<pair<int, int>, bool> mp; long double intersect(pair<int, int> p1, pair<int, int> p2) { return 0.1 * p1.second * p2.second * (p2.first - p1.first) / p1.first / p2.first / (p1.second - p2.second); } void solve() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", s + i, r + i); p.push_back(make_pair(s[i], r[i])); } sort(p.begin(), p.end()); for (int i = 0; i < n; i++) { while (int((v1).size()) && v1.back().second <= p[i].second) v1.pop_back(); v1.push_back(p[i]); } for (int i = 0; i < int((v1).size()); i++) { while (int((v2).size()) > 1 && intersect(v2.back(), v1[i]) > intersect(v2[int((v2).size()) - 2], v2.back()) + 1e-9) v2.pop_back(); v2.push_back(v1[i]); } for (int i = 0; i < int((v2).size()); i++) mp[v2[i]] = 1; for (int i = 0; i < n; i++) if (mp[make_pair(s[i], r[i])]) printf("%d ", i + 1); } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long double Eps = 1e-22; struct Vector { long double x, y; Vector(long double _x = 0, long double _y = 0) : x(_x), y(_y){}; bool operator<(const Vector &_X) const { return x < _X.x || x == _X.x && y < _X.y; } bool operator==(const Vector &_X) const { return x == _X.x && y == _X.y; } Vector operator-(const Vector &_X) const { return Vector(x - _X.x, y - _X.y); } } v[N]; long double cross(const Vector &a, const Vector &b) { return a.x * b.y - a.y * b.x; } long double dot(const Vector &a, const Vector &b) { return a.x * b.x + a.y * b.y; } int main() { ios::sync_with_stdio(0); map<Vector, vector<int> > id; vector<int> ans; int n; cin >> n; for (int i = 0, x, y; i < n; ++i) cin >> x >> y, v[i] = Vector(1. / x, 1. / y), id[v[i]].push_back(i); sort(v, v + n, [](const Vector &x, const Vector &y) -> bool { return x.y < y.y || x.y == y.y && x.x < y.x; }); n = unique(v, v + n) - v; sort(v + 1, v + n, [](const Vector &x, const Vector &y) -> bool { long double t = cross(x - v[0], y - v[0]); return fabs(t) > Eps ? t > Eps : dot(x - v[0], x - v[0]) > dot(y - v[0], y - v[0]); }); int left = min_element(v, v + n) - v; if (left == 0) ans = id[v[0]]; else { vector<Vector> hull; hull.push_back(v[0]), hull.push_back(v[left]); for (int i = left + 1; i < n; ++i) { while (hull.size() > 2 && cross(hull[hull.size() - 1] - hull[hull.size() - 2], v[i] - hull[hull.size() - 2]) < Eps) hull.pop_back(); hull.push_back(v[i]); } for (int i = 0; i < (int)hull.size(); ++i) ans.insert(ans.end(), id[hull[i]].begin(), id[hull[i]].end()); } sort(ans.begin(), ans.end()); for (int i = 0; i < (int)ans.size(); ++i) cout << ans[i] + 1 << ' '; }
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 10; long long int x[mx], y[mx]; int ord[mx]; int hs[mx], h = 0; vector<int> g[mx]; int ans[mx]; int cross(int a, int o, int b) { long long int l = (x[o] - x[a]) * (y[o] - y[b]) * y[a] * x[b]; long long int r = (y[o] - y[a]) * (x[o] - x[b]) * x[a] * y[b]; if (l == r) return 0; if (l < r) return -1; return 1; } bool cmp1(int i, int j) { if (x[i] != x[j]) return x[i] < x[j]; if (y[i] != y[j]) return y[i] < y[j]; return i < j; } bool cmp(int i, int j) { int c = cross(i, ord[0], j); if (c == 0) { if (x[j] != x[i]) return x[j] < x[i]; return i < j; } return c > 0; } inline bool ccw(int a, int o, int b) { return (-cross(a, o, b)) >= 0; } int main() { int n, xi, yi; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", &xi, &yi); x[i] = xi, y[i] = yi, ord[i] = i; } sort(ord, ord + n, cmp1); int c = 0; int il = 0, id = 0; for (int i = 0; i < n;) { int ii = ord[i]; int xi = x[ii], yi = y[ii]; while (i < n && x[ord[i]] == xi && y[ord[i]] == yi) { g[ii].push_back(ord[i]); i++; } int j = ord[il]; if (xi > x[j] || (xi == x[j] && yi > y[j])) il = c; j = ord[id]; if (yi > y[j] || (yi == y[j] && xi > x[j])) id = c; ord[c++] = ii; } int dwn = ord[id]; swap(ord[0], ord[il]); sort(ord + 1, ord + c, cmp); for (int i = 0; i < c; i++) { while (h >= 2 && !ccw(hs[h - 2], hs[h - 1], ord[i])) h--; hs[h++] = ord[i]; if (ord[i] == dwn) break; } c = 0; for (int i = 0; i < h; i++) { int u = hs[i]; for (int j = 0; j < int(g[u].size()); j++) { ans[c++] = 1 + g[u][j]; } } sort(ans, ans + c); printf("%d", ans[0]); for (int i = 1; i < c; i++) printf(" %d", ans[i]); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int const N = 1e4 + 6; double const eps = 1e-25; double const INF = LLONG_MAX * 1.0 / 3.0; vector<pair<int, int>> a; vector<int> answer; int ok[N], maxi[N], n; double f(int si, int sj, int ri, int rj) { double a = 1.0 * (sj - si) * rj * ri; double b = 1.0 * (ri - rj) * sj * si; return a / b; } int main() { cin >> n; for (int i = 0; i < n; i++) { int f, s; cin >> f >> s; a.push_back(make_pair(f, s)); maxi[f] = max(maxi[f], s); } for (int i = N - 1; i > 0; i--) { if (!maxi[i]) continue; bool curAns = 1; double rig = 0.0; double lef = INF; for (int j = i - 1; j > 0; j--) { if (maxi[j] <= maxi[i]) continue; rig = max(rig, f(maxi[i], maxi[j], i, j)); } for (int j = i + 1; j < N; j++) { if (maxi[i] <= maxi[j]) { curAns = 0; break; } lef = min(lef, f(maxi[j], maxi[i], j, i)); } if (rig - lef > eps) curAns = 0; ok[i] = curAns; } for (int i = 0; i < a.size(); i++) { if (maxi[a[i].first] == a[i].second && ok[a[i].first]) answer.push_back(i); } for (int i = 0; i < answer.size(); i++) cout << answer[i] + 1 << " "; return 0; }
#include <bits/stdc++.h> using namespace std; long long getLL() { long long ret = 0; char c; while (1) { c = getchar(); if (c >= '0' && c <= '9') break; } while (1) { ret = ret * 10 + c - '0'; c = getchar(); if (c < '0' || c > '9') break; } return ret; } int getInt() { int ret = 0; char c; while (1) { c = getchar(); if (c >= '0' && c <= '9') break; } while (1) { ret = ret * 10 + c - '0'; c = getchar(); if (c < '0' || c > '9') break; } return ret; } const double eps = 1e-10; int dcmp(double x) { return (x < -eps) ? -1 : (x > eps); } struct Point { double x, y; int who; Point() {} Point(double _x, double _y, int _who) : x(_x), y(_y), who(_who){}; bool operator<(const Point &b) const { if (dcmp(x - b.x) == 0) return y < b.y; return x < b.x; } 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; } } A[1020304]; int n, Stack[1020304], can[1020304], sameas[1020304]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { double r, s; scanf("%lf%lf", &r, &s); A[i] = Point(10000.0 / r, 10000.0 / s, i); } sort(A + 1, A + n + 1); int Top = 0; vector<int> ans; for (int i = 1; i <= n; ++i) { if (i > 1 && dcmp(A[i].x - A[i - 1].x) == 0) continue; while (Top > 1 && (dcmp((A[i] - A[Stack[Top]]) * (A[i] - A[Stack[Top - 1]])) > 0)) --Top; Stack[++Top] = i; } for (int i = 1; i <= Top; ++i) if (i == 1 || dcmp(A[Stack[i]].y - A[Stack[i - 1]].y) < 0) can[Stack[i]] = true; for (int i = 1; i <= n; ++i) { if (dcmp(A[i].x - A[i - 1].x) == 0 && dcmp(A[i].y - A[i - 1].y) == 0) can[i] |= can[i - 1]; if (can[i]) ans.push_back(A[i].who); } sort(ans.begin(), ans.end()); for (auto x : ans) printf("%d ", x); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int maxn = 200010; int n; int s[maxn]; int r[maxn]; vector<pair<int, int> > p, v, v2; map<pair<int, int>, bool> mp; long double intersect(pair<int, int> p1, pair<int, int> p2) { return 0.1 * p1.second * p2.second * (p2.first - p1.first) / p1.first / p2.first / (p1.second - p2.second); } void solve() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", s + i, r + i); p.push_back(make_pair(s[i], r[i])); } sort(p.begin(), p.end()); for (int i = 0; i < n; i++) { while (int((v).size()) && v.back().second <= p[i].second) v.pop_back(); v.push_back(p[i]); } for (int i = 0; i < int((v).size()); i++) { while (int((v2).size()) > 1 && intersect(v2.back(), v[i]) > intersect(v2[int((v2).size()) - 2], v2.back()) + 1e-9) v2.pop_back(); v2.push_back(v[i]); } for (int i = 0; i < int((v2).size()); i++) mp[v2[i]] = 1; for (int i = 0; i < n; i++) if (mp[make_pair(s[i], r[i])]) printf("%d ", i + 1); } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char g = getchar(); while (g < '0' || g > '9') { if (g == '-') f = -1; g = getchar(); } while (g >= '0' && g <= '9') { x = (x << 1) + (x << 3) + g - 48; g = getchar(); } return f * x; } int n, q[200005], ne[200005]; long double k[200005]; bool f[200005]; struct node { int x, y, id; inline bool operator<(node a) const { return x > a.x || (a.x == x && y > a.y); } } p[200005]; inline long double slay(node& a, node& b) { return (long double)a.x * b.x * (b.y - a.y) / ((long double)a.y * b.y * (b.x - a.x)); } int main() { n = read(); int xx, yy = 0, t; for (int i = 1; i <= n; i++) { p[i].x = read(); p[i].y = read(); p[i].id = i; if (p[i].y > yy || (p[i].y == yy && p[i].x > xx)) { yy = p[i].y; xx = p[i].x; } } sort(p + 1, p + n + 1); t = 1; q[t] = 1; for (int i = 2; i <= n && xx <= p[i].x; ++i) { if (p[q[t]].x == p[i].x) { if (p[q[t]].y == p[i].y) ne[p[i].id] = ne[p[q[t]].id], ne[p[q[t]].id] = p[i].id; continue; } while (t > 1 && k[t] > slay(p[q[t]], p[i])) --t; q[++t] = i; k[t] = slay(p[q[t - 1]], p[i]); } while (t) { for (int i = p[q[t]].id; i; i = ne[i]) f[i] = 1; t--; } for (int i = 1; i <= n; i++) { if (f[i]) printf("%d ", i); } printf("\n"); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx2,avx") #pragma GCC optimize("unroll-loops") using namespace std; string YES[2] = {"NO", "YES"}; string Yes[2] = {"No", "Yes"}; string yes[2] = {"no", "yes"}; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); } template <class T> void scan(vector<T> &); template <class T> void scan(vector<T> &a) { for (auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } template <class T, class S> inline bool chmax(T &a, S b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class S> inline bool chmin(T &a, S b) { if (a > b) { a = b; return 1; } return 0; } vector<int> iota(int n) { vector<int> a(n); iota(begin(a), end(a), 0); return a; } template <typename T> vector<int> iota(vector<T> &a, bool greater = false) { vector<int> res(a.size()); iota(begin(res), end(res), 0); sort(begin(res), end(res), [&](int i, int j) { if (greater) return a[i] > a[j]; return a[i] < a[j]; }); return res; } vector<pair<long long, long long>> factor(long long x) { vector<pair<long long, long long>> ans; for (long long i = 2; i * i <= x; i++) if (x % i == 0) { ans.push_back({i, 1}); while ((x /= i) % i == 0) ans.back().second++; } if (x != 1) ans.push_back({x, 1}); return ans; } template <class T> vector<T> divisor(T x) { vector<T> ans; for (T i = 1; i * i <= x; i++) if (x % i == 0) { ans.push_back(i); if (i * i != x) ans.push_back(x / i); } return ans; } template <typename T> void zip(vector<T> &x) { vector<T> y = x; sort(begin(y), end(y)); for (int i = 0; i < x.size(); ++i) { x[i] = distance((y).begin(), lower_bound(begin(y), end(y), (x[i]))); } } int popcount(long long x) { return __builtin_popcountll(x); } struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); } } setup_io; int in() { int x; cin >> x; return x; } long long lin() { unsigned long long x; cin >> x; return x; } template <typename T> struct edge { int from, to; T cost; int id; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; using Tree = vector<vector<int>>; using Graph = vector<vector<int>>; template <class T> using Wgraph = vector<vector<edge<T>>>; Graph getG(int n, int m = -1, bool directed = false, int margin = 1) { Tree res(n); if (m == -1) m = n - 1; while (m--) { int a, b; cin >> a >> b; a -= margin, b -= margin; res[a].emplace_back(b); if (!directed) res[b].emplace_back(a); } return move(res); } template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) { Wgraph<T> res(n); if (m == -1) m = n - 1; while (m--) { int a, b; T c; cin >> a >> b >> c; a -= margin, b -= margin; res[a].emplace_back(b, c); if (!directed) res[b].emplace_back(a, c); } return move(res); } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) cout << e << " "; cout << endl; return os; } template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) { cout << "(" << p.first << ", " << p.second << ")"; return os; } template <class S, class T> string to_string(pair<S, T> p) { return "(" + to_string(p.first) + "," + to_string(p.second) + ")"; } template <class A> string to_string(A v) { if (v.empty()) return "{}"; string ret = "{"; for (auto &x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } void dump() { cerr << endl; } template <class Head, class... Tail> void dump(Head head, Tail... tail) { cerr << to_string(head) << " "; dump(tail...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int n) { return uniform_int_distribution<int>(0, n - 1)(rng); } template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; int main() { int n; IN(n); using T = tuple<long long, long long, int>; vector<pair<int, int>> w; vector<T> a; for (long long i = 0; i < n; ++i) { int s, r; IN(s, r); w.emplace_back(s, r); a.emplace_back(s, r, i + 1); } sort(begin(a), end(a)); vector<long long> ma(10101); for (long long i = 0; i < n; ++i) chmax(ma[get<0>(a[i])], get<1>(a[i])); for (long long i = 10000; i >= 0; --i) chmax(ma[i], ma[i + 1]); vector<int> ans; set<pair<int, int>> S; for (long long i = 0; i < n; ++i) { if (ma[get<0>(a[i]) + 1] >= get<1>(a[i]) or ma[get<0>(a[i])] > get<1>(a[i])) continue; if (i and get<0>(a[i - 1]) == get<0>(a[i]) and get<1>(a[i - 1]) == get<1>(a[i])) continue; while ((int)(ans).size() >= 2) { int j = ans[(int)(ans).size() - 2], k = ans[(int)(ans).size() - 1]; if (get<1>(a[i]) * get<0>(a[k]) * (get<0>(a[i]) - get<0>(a[j])) * (get<1>(a[j]) - get<1>(a[k])) > get<1>(a[k]) * get<0>(a[i]) * (get<0>(a[k]) - get<0>(a[j])) * (get<1>(a[j]) - get<1>(a[i]))) ans.pop_back(); else break; } ans.emplace_back(i); } for (auto i : ans) S.emplace(get<0>(a[i]), get<1>(a[i])); for (long long i = 0; i < n; ++i) { if (S.count(w[i])) cout << i + 1 << " "; } cout << '\n'; }
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> P[200020]; int MX, a, b, n, i, j; vector<int> ans, all[200020]; double L, R, S[12000], T[12000], X[200020], Y[200020]; bool f[200020]; int main() { cin >> n; int NN = n; for (i = 1; i <= n; i++) { scanf("%d%d", &a, &b); X[i] = a; Y[i] = b; P[i].first = make_pair(a, b); P[i].second = i; } sort(P + 1, P + n + 1); reverse(P + 1, P + n + 1); for (i = 1; i <= n; i++) { j = i; while (j <= n && P[j].first == P[i].first) j++; for (int k = i; k < j; k++) { all[P[i].second].push_back(P[k].second); } if (MX < P[i].first.second) ans.push_back(P[i].second); i = j - 1; for (int k = i; k < j; k++) MX = max(MX, P[k].first.second); } n = 0; sort(ans.begin(), ans.end()); for (j = 0; j < ans.size(); j++) { ++n; P[n].first.first = X[ans[j]]; P[n].first.second = Y[ans[j]]; P[n].second = ans[j]; } sort(P + 1, P + n + 1); for (i = 1; i <= n; i++) { T[i] = P[i].first.second; S[i] = P[i].first.first; } for (i = 1; i <= n; i++) { L = 0; R = 1000000000000; for (j = 1; j < i; j++) L = ((L) > ((T[j] - T[i]) * S[j] / ((S[i] - S[j]) * T[j])) ? (L) : ((T[j] - T[i]) * S[j] / ((S[i] - S[j]) * T[j]))); for (j = i + 1; j <= n; j++) R = ((R) < ((T[i] - T[j]) * S[j] / ((S[j] - S[i]) * T[j])) ? (R) : ((T[i] - T[j]) * S[j] / ((S[j] - S[i]) * T[j]))); if (L <= R) f[P[i].second] = 1; } vector<int> res; for (i = 1; i <= NN; i++) if (f[i]) { for (j = 0; j < all[i].size(); j++) res.push_back(all[i][j]); } sort(res.begin(), res.end()); for (j = 0; j < res.size(); j++) cout << res[j] << " "; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; long long qpow(long long a, long long b) { long long res = 1, base = a; while (b) { if (b % 2) res = res * base; base = base * base; b /= 2; } return res; } long long powmod(long long a, long long b) { long long res = 1, base = a; while (b) { if (b % 2) res = res * base % 1000000007; base = base * base % 1000000007; b /= 2; } return res; } struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} int operator^(const Point& b) const { return x * b.y - b.x * y; } Point operator-(const Point& b) const { return Point(x - b.x, y - b.y); } } p[400005], s[400005]; set<pair<int, int> > ss; vector<int> ans; pair<int, int> tpair[400005]; int n, cnt; int cmp(Point a, Point b) { if (a.x == b.x) return a.y > b.y; else return a.x > b.x; } bool check(Point a, Point b, Point c) { return (long long)(a.x - b.x) * (a.y - c.y) * c.x * b.y < (long long)(a.x - c.x) * (a.y - b.y) * b.x * c.y; } void work() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &p[i].x, &p[i].y); tpair[i] = make_pair(p[i].x, p[i].y); } sort(p + 1, p + n + 1, cmp); cnt = 0; for (int i = 1; i <= n; i++) if (!cnt || p[i].y > s[cnt - 1].y) s[cnt++] = p[i]; memcpy(p, s, sizeof s); int tcnt = cnt, cnt = 0; for (int i = 0; i < tcnt; i++) { while (cnt > 1 && check(s[cnt - 2], s[cnt - 1], p[i])) cnt--; s[cnt++] = p[i]; } for (int i = 0; i < cnt; i++) ss.insert(make_pair(s[i].x, s[i].y)); for (int i = 1; i <= n; i++) { if (ss.find(tpair[i]) != ss.end()) ans.push_back(i); } for (int i = 0; i < ans.size(); i++) printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' '); } int main() { work(); return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265359; template <typename T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T sqr(T x) { return x * x; } long long sign(long long x) { if (x > 0) return 1; else if (x == 0) return 0; else return -1; } struct R { long long n, d; R() { n = 0, d = 1; } R(long long x) { n = x, d = 1; } R(long long _n, long long _d) { n = _n, d = _d; if (d < 0) n = -n, d = -d; } R operator+(const R &r) const { return R(n * r.d + r.n * d, d * r.d); } R operator-(const R &r) const { return R(n * r.d - r.n * d, d * r.d); } R operator*(const R &r) const { return R(n * r.n, d * r.d); } R operator/(const R &r) const { return R(n * r.d, d * r.n); } bool operator<(const R &r) const { if (sign(n) != sign(r.n)) { return n < r.n; } else { if (sign(n) == -1) { return R(-r.n, r.d) < R(-n, d); } } long long x = n / d; long long y = r.n / r.d; if (x < y) return true; else if (x == y) { long long n1 = n % d; long long n2 = r.n % r.d; if (n1 == 0) { if (n2 == 0) return false; return true; } else if (n2 == 0) return false; return R(r.d, n2) < R(d, n1); } else { return false; } } bool operator==(const R &r) const { return !(*this < r) && !(r < *this); } }; struct line { long long a, b; int idx; line() {} bool operator<(const line &l) const { return make_pair(R(1, b) - R(1, a), R(1, a)) < make_pair(R(1, l.b) - R(1, l.a), R(1, l.a)); } R intersect(const line &l) const { return R((l.a - a) * (l.b * b), (l.a * b * a - l.b * b * a - l.a * l.b * a + l.a * l.b * b)); } }; int main() { int n; scanf("%d", &n); vector<line> a; for (int i = 1; i <= n; i++) { int x, y; scanf("%d %d", &x, &y); line l; l.a = x; l.b = y; l.idx = i; a.push_back(l); } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); vector<line> st; map<int, vector<int> > cc; int p = 0; for (int i = 0; i < n; i++) { int j = i; while (j < n && a[i].a == a[j].a && a[i].b == a[j].b) { j++; } for (int h = i; h < j; h++) cc[a[i].idx].push_back(a[h].idx); a[p++] = a[i]; i = j - 1; } a.resize(p); for (auto l : a) { while (!st.empty()) { if (R(1, st.back().b) - R(1, st.back().a) == R(1, l.b) - R(1, l.a)) st.pop_back(); else break; } while (st.size() > 1) { auto x1 = st[st.size() - 2].intersect(l); auto x2 = st.back().intersect(st[st.size() - 2]); if (x1 < x2) st.pop_back(); else break; } st.push_back(l); } vector<int> ans; for (int i = 0; i < st.size(); i++) { bool good = true; if (i) { good &= st[i - 1].intersect(st[i]) < R(1, 1); } if (i + 1 < st.size()) { good &= R(0, 1) < st[i].intersect(st[i + 1]); } if (good) { for (int x : cc[st[i].idx]) ans.push_back(x); } } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) { if (i) printf(" "); printf("%d", ans[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 9; int q[N], ne[N]; double k[N]; bool f[N]; char buf[N], *ie = buf + N, *ip = ie - 1; struct Point { int x, y, id; inline bool operator<(register Point a) const { return x > a.x || (x == a.x && y > a.y); } } p[N]; inline int read() { int res = 0, fh = 1; char ch = getchar(); while ((ch > '9' || ch < '0') && ch != '-') ch = getchar(); if (ch == '-') fh = -1, ch = getchar(); while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar(); return fh * res; } inline double Slope(register Point& i, register Point& j) { return (double)i.x * j.x * (j.y - i.y) / ((double)i.y * j.y * (j.x - i.x)); } int main() { int n = read(), t, ry = 0, rx; for (int i = 1; i <= n; ++i) { p[i].x = read(); p[i].y = read(); p[i].id = i; if (ry < p[i].y || (ry == p[i].y && rx < p[i].x)) ry = p[i].y, rx = p[i].x; } sort(p + 1, p + n + 1); q[t = 1] = 1; for (int i = 2; i <= n && rx <= p[i].x; ++i) { if (p[q[t]].x == p[i].x) { if (p[q[t]].y == p[i].y) ne[p[i].id] = ne[p[q[t]].id], ne[p[q[t]].id] = p[i].id; continue; } while (t > 1 && k[t] > Slope(p[q[t]], p[i])) --t; q[++t] = i; k[t] = Slope(p[q[t - 1]], p[i]); } for (; t; --t) for (int i = p[q[t]].id; i; i = ne[i]) f[i] = 1; for (int i = 1; i <= n; ++i) if (f[i]) printf("%d ", i); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point() {} point(int _x, int _y) : x(_x), y(_y) {} point operator-(const point &p) const { return point(x - p.x, y - p.y); } bool operator<(const point &p) const { if (p.x != x) return x > p.x; return y > p.y; } bool operator==(const point &p) const { return x == p.x && y == p.y; } int operator*(const point &p) const { return x * p.y - y * p.x; } }; int n, m, X, cnt, las, top[10005]; point p[200005], q[10005], ch[10005]; bool ans[10005], fi = true; inline bool judge(point A, point B, point C) { point p = C - B, q = B - A; return 1LL * A.x * C.y * q.y * p.x > 1LL * A.y * C.x * p.y * q.x; } inline int ConvexHull(point p[], int n) { int m = 0; for (int i = 1; i <= n; i++) { while (m > 1 && judge(ch[m - 1], ch[m], p[i])) --m; ch[++m] = p[i]; } return m; } void out(int x) { fi ? fi = false : printf(" "); printf("%d", x); return; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &p[i].x, &p[i].y); X = max(X, p[i].x); top[p[i].x] = max(top[p[i].x], p[i].y); } for (int i = X; i; i--) if (top[i] > las) q[++cnt] = point(i, las = top[i]); m = ConvexHull(q, cnt); for (int i = 1; i <= m; i++) ans[ch[i].x] = true; for (int i = 1; i <= n; i++) if (ans[p[i].x] && top[p[i].x] == p[i].y) out(i); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; const int inft = 1000000009; const int MAXN = 1000006; const double eps = 1e-15; inline bool iszero(double first) { return first <= eps && first >= -eps; } int sgn(double first) { return iszero(first) ? 0 : (first < 0 ? -1 : 1); } struct pt { int first, second; int nr; pt(double xx = 0, double yy = 0, int nnrr = -1) : first(xx), second(yy), nr(nnrr) {} }; bool operator<(const pt &a, const pt &b) { if (a.first != b.first) return a.first > b.first; return a.second > b.second; } bool praword(pt a, pt b, pt c) { return 1LL * a.second * b.first * c.first * c.second + 1LL * a.first * a.second * b.second * c.first + 1LL * a.first * b.first * b.second * c.second - (1LL * a.first * a.second * b.first * c.second + 1LL * a.first * b.second * c.first * c.second + 1LL * a.second * b.first * b.second * c.first) < 0; } vector<pt> otoczka(vector<pt> ab) { sort(ab.begin(), ab.end()); int l = ab.size(), i, j, k; vector<pt> wyn(l + 1); if (l < 3) return ab; j = 0; for (i = 0; i < l; i++) { if (i && ab[i].second <= wyn[j - 1].second) continue; while (j - 2 >= 0 && praword(wyn[j - 2], wyn[j - 1], ab[i])) j--; wyn[j++] = ab[i]; } return vector<pt>(wyn.begin(), wyn.begin() + j); } map<pair<int, int>, vector<int> > M; int main() { int n; scanf("%d", &n); vector<pt> A(n); for (int i = 0; i < (n); ++i) { int a, b; scanf("%d%d", &a, &b); A[i].nr = i; A[i].first = a; A[i].second = b; M[pair<int, int>(A[i].first, A[i].second)].push_back(i); } vector<pt> B = otoczka(A); vector<int> ANS; for (typeof((B).begin()) it = (B).begin(); it != (B).end(); ++it) for (typeof((M[pair<int, int>(it->first, it->second)]).begin()) i2 = (M[pair<int, int>(it->first, it->second)]).begin(); i2 != (M[pair<int, int>(it->first, it->second)]).end(); ++i2) ANS.push_back(*i2); sort((ANS).begin(), (ANS).end()); ANS.resize(unique((ANS).begin(), (ANS).end()) - ANS.begin()); for (typeof((ANS).begin()) it = (ANS).begin(); it != (ANS).end(); ++it) printf("%d ", *it + 1); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int sigma_size = 26; const int N = 100 + 50; const int MAXN = 200000 + 50; const int inf = 0x3fffffff; const double eps = 1e-8; const int HASH = 100007; const int mod = 1000000000 + 7; int n, tot; int ans[MAXN]; struct Point { int id; double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} } p[MAXN], poly[MAXN]; map<pair<double, double>, int> mp; vector<int> vec[MAXN]; 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 k) { return Point(k * a.x, k * a.y); } Point operator/(Point a, double k) { return Point(a.x / k, a.y / k); } int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } bool operator==(Point a, Point b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } void init() { tot = 0; mp.clear(); for (int i = 0; i < n; i++) vec[i].clear(); } bool cmp(Point a, Point b) { if (a.x == b.x) return a.y > b.y; return a.x > b.x; } bool cmp1(Point a, Point b) { if (a.y == b.y) return a.x > b.x; return a.y > b.y; } double cross(Point p1, Point p2, Point p0) { return (p0.x - p1.x) * (p0.y - p2.y) * p2.x * p1.y - (p0.x - p2.x) * (p0.y - p1.y) * p1.x * p2.y; } int Andrew(int n) { sort(p, p + n, cmp); int top = -1; for (int i = 0; i < n; i++) { while (top > 0 && cross(p[i], poly[top], poly[top - 1]) > 0) top--; poly[++top] = p[i]; } int num = top; for (int i = n - 2; i >= 0; i--) { while (top > num && cross(p[i], poly[top], poly[top - 1]) > 0) top--; poly[++top] = p[i]; } return top; } int main() { while (~scanf("%d", &n)) { init(); for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); pair<double, double> tmp = make_pair(x, y); if (mp.count(tmp) == 0) { mp[tmp] = tot; p[tot].x = tmp.first; p[tot].y = tmp.second; p[tot].id = tot; tot++; } vec[mp[tmp]].push_back(i + 1); } int num = 0; if (tot <= 2) { for (int i = 0; i < tot; i++) for (int j = 0; j < vec[i].size(); j++) ans[num++] = vec[i][j]; sort(ans, ans + num); for (int i = 0; i < num; i++) { if (i) printf(" "); printf("%d", ans[i]); } printf("\n"); continue; } int top = Andrew(tot); sort(poly, poly + top, cmp1); Point tmp = poly[0]; sort(poly, poly + top, cmp); int cnt = -1; for (int i = 0; i < top; i++) { while (cnt > 0 && cross(poly[i], p[cnt], p[cnt - 1]) > 0) cnt--; p[++cnt] = poly[i]; if (p[cnt] == tmp) break; } for (int i = 0; i <= cnt; i++) { for (int j = 0; j < vec[p[i].id].size(); j++) ans[num++] = vec[p[i].id][j]; } sort(ans, ans + num); num = unique(ans, ans + num) - ans; for (int i = 0; i < num; i++) { if (i) printf(" "); printf("%d", ans[i]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; char f(const pair<long long, long long> &a, const pair<long long, long long> &b, const pair<long long, long long> &c) { return (c.second - a.second) * (c.first - b.first) * a.first * b.second < (c.first - a.first) * (c.second - b.second) * a.second * b.first; } int main() { int n; scanf("%d", &n); vector<pair<long long, long long> > p(n); for (pair<long long, long long> &i : p) { scanf("%I64d%I64d", &i.first, &i.second); } vector<pair<long long, long long> > P = p, ch; p.emplace_back(0, 1e4 + 1); p.emplace_back(1e4 + 1, 0); sort((p).begin(), (p).end()); for (auto i : p) { while (ch.size() > 1 && (ch.back().second == i.second || f(ch[(ch.size() - 2)], ch.back(), i))) { ch.pop_back(); } ch.push_back(i); } for (int i = 0; i < n; ++i) if (binary_search((ch).begin(), (ch).end(), P[i])) { printf("%d ", i + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2000005; int n, top, pos, Maxa, Maxb, s[maxn], del[maxn]; vector<int> vec[maxn], ans; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } struct point { int x, y, Id; bool operator<(const point &a) const { return x != a.x ? x < a.x : y < a.y; } } p[maxn]; double A(int i, int j) { return (double)p[i].x * p[j].x * (p[i].y - p[j].y); } double B(int i, int j) { return (double)p[i].y * p[j].y * (p[i].x - p[j].x); } int main() { n = gi(); for (int i = 1; i <= n; ++i) p[i] = (point){gi(), gi(), i}; sort(p + 1, p + n + 1); pos = n + 1; for (int i = n; i >= 1; --i) { if (del[i]) continue; if (Maxb >= p[i].y) { if (Maxa == p[i].x && Maxb == p[i].y) vec[pos].push_back(i); del[i] = pos; } else { vec[i].push_back(i); Maxa = p[i].x; Maxb = p[i].y; pos = i; } } for (int i = 1; i <= n; ++i) { if (del[i]) continue; while (top > 1 && B(i, s[top]) * A(s[top], s[top - 1]) < B(s[top], s[top - 1]) * A(i, s[top])) --top; s[++top] = i; } for (int i = 1; i <= top; ++i) { for (int j = 0; j < vec[s[i]].size(); ++j) ans.push_back(p[vec[s[i]][j]].Id); } 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 pnt { int x, y, id; void in(int i) { scanf("%d %d", &x, &y); id = i; } bool operator<(const pnt &p) const { return x != p.x ? x > p.x : y > p.y; } bool operator==(const pnt &p) const { return x == p.x && y == p.y; } } p[200100], q[200100]; long long cross(pnt a, pnt b, pnt c) { return 1ll * b.y * c.x * (a.x - b.x) * (a.y - c.y) - 1ll * b.x * c.y * (a.y - b.y) * (a.x - c.x); } int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) p[i].in(i), q[i] = p[i]; sort(p, p + n); int m = unique(p, p + n) - p; vector<pnt> rlt; vector<int> ans; for (int i = 0, j = 0; i < m; i++) { while (j > 1 && cross(rlt[j - 2], rlt[j - 1], p[i]) < 0) rlt.pop_back(), j--; rlt.push_back(p[i]), j++; } int k = adjacent_find(rlt.begin(), rlt.end(), [&](pnt a, pnt b) { return a.y >= b.y; }) - rlt.begin(); if (k != rlt.size()) k++; sort(q, q + n); for (int i = 0, j = 0; i < k; i++) { while (!(q[j] == rlt[i])) j++; while (j < n && q[j] == rlt[i]) ans.push_back(q[j].id), j++; } sort(ans.begin(), ans.end()); for (auto x : ans) printf("%d ", x + 1); return 0; }
#include <bits/stdc++.h> using namespace std; struct Vector { long long x, y; Vector(long long _x = 0, long long _y = 0) : x(_x), y(_y) {} inline bool operator<(const Vector& rhs) const { return x != rhs.x ? x > rhs.x : y > rhs.y; } }; inline long long cross(Vector o, Vector a, Vector b) { return (a.y * b.x * o.x * o.y - a.y * o.x * b.x * b.y - o.y * b.x * a.x * a.y + a.x * b.x * a.y * b.y) - (a.x * b.y * o.x * o.y - a.x * o.y * b.x * b.y - o.x * b.y * a.x * a.y + a.x * b.x * a.y * b.y); } vector<int> ans; map<pair<long long, long long>, vector<int>> dic; vector<Vector> point, hull; int main() { int n, s, r; scanf("%d", &n); hull.reserve(n + 5); point.reserve(n + 5); for (int i = 1; i <= n; i++) { scanf("%d%d", &s, &r); dic[pair<long long, long long>(s, r)].push_back(i); } for (auto it = dic.begin(); it != dic.end(); it++) point.push_back(Vector(it->first.first, it->first.second)); sort(point.begin(), point.end()); for (int i = 0; i < (int)point.size(); i++) { while (hull.size() > 1 && cross(hull[(int)hull.size() - 2], hull[(int)hull.size() - 1], point[i]) < 0) hull.pop_back(); hull.push_back(point[i]); } int l = -1; r = -1; for (int i = 0; i < (int)hull.size(); i++) if (l == -1 || hull[l].x < hull[i].x || (hull[l].x == hull[i].x && hull[l].y < hull[i].y)) l = i; for (int i = 0; i < (int)hull.size(); i++) if (r == -1 || hull[r].y < hull[i].y || (hull[r].y == hull[i].y && hull[r].x < hull[i].x)) r = i; for (int i = l; i <= r; i++) { pair<long long, long long> p = pair<long long, long long>(hull[i].x, hull[i].y); for (int& id : dic[p]) ans.push_back(id); } sort(ans.begin(), ans.end()); for (int& id : ans) printf("%d ", id); puts(""); return 0; }
#include <bits/stdc++.h> template <class T> void Read(T &ret) { ret = 0; bool ok = 0, u = 0; for (;;) { int c = getchar(); if (c >= '0' && c <= '9') ret = (ret << 3) + (ret << 1) + c - '0', ok = 1; else if (c == '-') u = 1; else if (ok) { if (u) ret *= -1; return; } } } long long pow_mod(long long p, long long n, long long mod) { long long ret = 1; for (; n; n >>= 1) { if (n & 1) ret = ret * p % mod; p = p * p % mod; } return ret; } template <class T> bool chmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool chmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; } const int Max_N = 2e5 + 9; const int Max_M = 1e4 + 9; const double eps = 1e-24; int sgn(double x) { return (x > eps) - (x < -eps); } int _; struct Point { int X, Y; double x, y; Point() { X = Y = 0; x = y = 0; } Point(double tx, double ty) { x = tx; y = ty; } Point(std::pair<int, int> tmp) { X = tmp.first; Y = tmp.second; x = 1.0 / X; y = 1.0 / Y; } std::pair<int, int> query() { return std::make_pair(X, Y); } bool operator<(const Point &t) const { if (sgn(x - t.x) == 0) { return sgn(y - t.y) < 0; } return sgn(x - t.x) < 0; } } an[Max_N], bn[Max_N]; 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; } int ConvexHull(Point *p, int n, Point *ch) { std::sort(p, p + n); int r = 0; for (int i = 0; i < n; ++i) { while (r > 1 && sgn((ch[r - 1] - ch[r - 2]) ^ (p[i] - ch[r - 2])) <= 0) { --r; } ch[r++] = p[i]; } int mid = r; for (int i = n - 2; i >= 0; --i) { while (r > mid && sgn((ch[r - 1] - ch[r - 2]) ^ (p[i] - ch[r - 2])) <= 0) { --r; } ch[r++] = p[i]; } if (n > 1) --r; return r; } bool ans[Max_N]; std::vector<int> idx[Max_N]; std::map<std::pair<int, int>, int> map; std::map<std::pair<int, int>, int>::iterator it; int main() { int n, tot = 0; scanf("%d", &n); std::pair<int, int> tmp; for (int i = 0, x, y; i < n; ++i) { scanf("%d%d", &x, &y); tmp.first = x; tmp.second = y; it = map.find(tmp); if (it == map.end()) { map[tmp] = tot; idx[tot].push_back(i); ++tot; } else { idx[it->second].push_back(i); } } int m = 0; for (auto i : map) { an[m++] = Point(i.first); } int cnt = ConvexHull(an, m, bn); for (int i = 0; i < cnt; ++i) { if (i && sgn(bn[i].Y - bn[i - 1].Y) <= 0) break; for (auto j : idx[map[bn[i].query()]]) { ans[j] = true; } } for (int i = 0; i < n; ++i) if (ans[i]) { printf("%d ", i + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long double eps = 1e-17; struct pt { long double x, y; vector<int> id; pt() : x(0.0), y(0.0) {} pt(long double X, long double Y) : x(X), y(Y) {} bool operator<(const pt &other) const { return (x + eps < other.x || (fabs(x - other.x) < eps && y + eps < other.y)); } }; int n; vector<pt> points; map<pair<int, int>, int> idx; bool valid[N]; long double cross(pt a, pt b, pt c) { return ((a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y)); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int r, s; scanf("%d%d", &r, &s); int id = points.size(); if (idx.count(make_pair(r, s))) id = idx[make_pair(r, s)]; if (id == points.size()) { points.push_back(pt((long double)1.0 / r, (long double)1.0 / s)); idx[make_pair(r, s)] = id; } points[id].id.push_back(i); } sort(points.begin(), points.end()); vector<pt> down; for (auto xt : points) { while (down.size() > 1 && cross(down[down.size() - 2], xt, down.back()) > eps) down.pop_back(); down.push_back(xt); } for (int i = 0; i < down.size(); i++) { if (i && down[i].y + eps > down[i - 1].y) break; for (int xt : down[i].id) valid[xt] = 1; } for (int i = 0; i < n; i++) if (valid[i]) printf("%d ", i + 1); 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 bool operator>(const point t) const { return y * t.x - x * t.y < 0; } 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}; } }; inline bool cmp(point x, point y) { if (x.x != y.x) return x.x < y.x; else return x.y > y.y; } point p[300000]; vector<int> V[300000]; int q[300000]; int i, j, n, o, t; double mx, my; 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; sort(p + 1, p + n + 1, cmp); p[0] = (point){0, 100000, 0}, p[n + 1] = (point){100000, 0, 0}; 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; }