text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
struct node {
int num;
int x, y;
} a[200005], c[200005], b[200005];
vector<int> ret;
int n;
int m;
bool vis[200005];
bool cmp(node a, node b) {
if (a.x != b.x) return a.x < b.x;
return a.y > b.y;
}
bool judge(node p0, node p1, node p2) {
int k1 = p2.y, k2 = p1.y, k3 = p0.y, k4 = p2.x, k5 = p1.x, k6 = p0.x;
return 1ll * (k1 * k3 - k2 * k3) * (k4 * k6 - k4 * k5) >
1ll * (k1 * k2 - k1 * k3) * (k5 * k6 - k4 * k6);
}
void tubao() {
m = 1;
c[1] = a[1];
for (int i = 2; i <= n; i++) {
if (a[i].x == a[i - 1].x) continue;
while (m >= 2 && judge(a[i], c[m], c[m - 1])) m--;
c[++m] = a[i];
}
for (int i = 1; i <= m; i++) vis[c[i].num] = 1;
for (int i = 2; i <= m; i++) {
if (c[i - 1].y <= c[i].y) {
vis[c[i - 1].num] = 0;
} else
break;
}
for (int i = 2; i <= n; i++) {
if (a[i].y == a[i - 1].y && a[i].x == a[i - 1].x && vis[a[i - 1].num])
vis[a[i].num] = true;
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i].x, &a[i].y);
a[i].num = i;
}
sort(a + 1, a + n + 1, cmp);
tubao();
for (int i = 1; i <= n; i++) {
if (vis[i]) printf("%d ", i);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
if (a < b) a = b;
}
struct FastIO {
FastIO() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} fastio_beet;
static const int CCW_COUNTER_CLOCKWISE = 1;
static const int CCW_CLOCKWISE = -1;
static const int CCW_ONLINE_BACK = 2;
static const int CCW_ONLINE_FRONT = -2;
static const int CCW_ON_SEGMENT = 0;
static const int ICC_SEPERATE = 4;
static const int ICC_CIRCUMSCRIBE = 3;
static const int ICC_INTERSECT = 2;
static const int ICC_INSCRIBE = 1;
static const int ICC_CONTAIN = 0;
struct Point {
long double x, y;
Point() {}
Point(long double x, long double y) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(long double k) { return Point(x * k, y * k); }
Point operator/(long double k) { return Point(x / k, y / k); }
long double norm() { return x * x + y * y; }
long double abs() { return sqrt(norm()); }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < (1e-20) && fabs(y - p.y) < (1e-20);
}
};
struct EndPoint {
Point p;
int seg, st;
EndPoint() {}
EndPoint(Point p, int seg, int st) : p(p), seg(seg), st(st) {}
bool operator<(const EndPoint &ep) const {
if (p.y == ep.p.y) return st < ep.st;
return p.y < ep.p.y;
}
};
istream &operator>>(istream &is, Point &p) {
is >> p.x >> p.y;
return is;
}
ostream &operator<<(ostream &os, Point p) {
os << fixed << setprecision(12) << p.x << " " << p.y;
return os;
}
bool sort_x(Point a, Point b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
bool sort_y(Point a, Point b) { return a.y != b.y ? a.y < b.y : a.x < b.x; }
istream &operator>>(istream &is, vector<Point> &p) {
for (int i = 0; i < (int)p.size(); i++) is >> p[i];
return is;
}
struct Segment {
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
istream &operator>>(istream &is, Segment &s) {
is >> s.p1 >> s.p2;
return is;
}
struct Circle {
Point c;
long double r;
Circle() {}
Circle(Point c, long double r) : c(c), r(r) {}
};
istream &operator>>(istream &is, Circle &c) {
is >> c.c >> c.r;
return is;
}
long double norm(Point a) { return a.x * a.x + a.y * a.y; }
long double abs(Point a) { return sqrt(norm(a)); }
long double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
long double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
Point orth(Point p) { return Point(-p.y, p.x); }
bool isOrthogonal(Point a, Point b) {
return (fabs((dot(a, b)) - (0.0)) < (1e-20));
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
bool isOrthogonal(Segment s1, Segment s2) {
return (fabs((dot(s1.p2 - s1.p1, s2.p2 - s2.p1)) - (0.0)) < (1e-20));
}
bool isParallel(Point a, Point b) {
return (fabs((cross(a, b)) - (0.0)) < (1e-20));
}
bool isParallel(Point a1, Point a2, Point b1, Point b2) {
return isParallel(a1 - a2, b1 - b2);
}
bool isParallel(Segment s1, Segment s2) {
return (fabs((cross(s1.p2 - s1.p1, s2.p2 - s2.p1)) - (0.0)) < (1e-20));
}
Point project(Segment s, Point p) {
Point base = s.p2 - s.p1;
long double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
long double arg(Point p) { return atan2(p.y, p.x); }
Point polar(long double a, long double r) {
return Point(cos(r) * a, sin(r) * a);
}
int ccw(Point p0, Point p1, Point p2);
bool intersectSS(Point p1, Point p2, Point p3, Point p4);
bool intersectSS(Segment s1, Segment s2);
bool intersectPS(vector<Point> p, Segment l);
int intersectCC(Circle c1, Circle c2);
bool intersectSC(Segment s, Circle c);
long double getDistanceLP(Segment l, Point p);
long double getDistanceSP(Segment s, Point p);
long double getDistanceSS(Segment s1, Segment s2);
Point getCrossPointSS(Segment s1, Segment s2);
Point getCrossPointLL(Segment l1, Segment l2);
vector<Point> getCrossPointCL(Circle c, Segment l);
vector<Point> getCrossPointCC(Circle c1, Circle c2);
int contains(vector<Point> g, Point p);
vector<Point> andrewScan(vector<Point> s);
vector<Point> convex_hull(vector<Point> ps);
long double diameter(vector<Point> s);
bool isConvex(vector<Point> p);
long double area(vector<Point> s);
vector<Point> convexCut(vector<Point> p, Segment l);
Segment bisector(Point p1, Point p2);
Point translate(Point v, long double theta);
vector<Segment> corner(Segment l1, Segment l2);
vector<vector<int> > segmentArrangement(vector<Segment> &ss, vector<Point> &ps);
int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > (1e-20)) return CCW_COUNTER_CLOCKWISE;
if (cross(a, b) < -(1e-20)) return CCW_CLOCKWISE;
if (dot(a, b) < -(1e-20)) return CCW_ONLINE_BACK;
if (a.norm() < b.norm()) return CCW_ONLINE_FRONT;
return CCW_ON_SEGMENT;
}
bool intersectSS(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersectSS(Segment s1, Segment s2) {
return intersectSS(s1.p1, s1.p2, s2.p1, s2.p2);
}
bool intersectPS(vector<Point> p, Segment l) {
int n = p.size();
for (int i = 0; i < n; i++)
if (intersectSS(Segment(p[i], p[(i + 1) % n]), l)) return 1;
return 0;
}
int intersectCC(Circle c1, Circle c2) {
if (c1.r < c2.r) swap(c1, c2);
long double d = abs(c1.c - c2.c);
long double r = c1.r + c2.r;
if ((fabs((d) - (r)) < (1e-20))) return ICC_CIRCUMSCRIBE;
if (d > r) return ICC_SEPERATE;
if ((fabs((d + c2.r) - (c1.r)) < (1e-20))) return ICC_INSCRIBE;
if (d + c2.r < c1.r) return ICC_CONTAIN;
return ICC_INTERSECT;
}
bool intersectSC(Segment s, Circle c) { return getDistanceSP(s, c.c) <= c.r; }
int intersectCS(Circle c, Segment s) {
if (norm(project(s, c.c) - c.c) - c.r * c.r > (1e-20)) return 0;
long double d1 = abs(c.c - s.p1), d2 = abs(c.c - s.p2);
if (d1 < c.r + (1e-20) && d2 < c.r + (1e-20)) return 0;
if ((d1 < c.r - (1e-20) && d2 > c.r + (1e-20)) ||
(d1 > c.r + (1e-20) && d2 < c.r - (1e-20)))
return 1;
Point h = project(s, c.c);
if (dot(s.p1 - h, s.p2 - h) < 0) return 2;
return 0;
}
long double getDistanceLP(Segment l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
long double getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2);
return getDistanceLP(s, p);
}
long double getDistanceSS(Segment s1, Segment s2) {
if (intersectSS(s1, s2)) return 0.0;
return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
Point getCrossPointSS(Segment s1, Segment s2) {
for (int k = 0; k < 2; k++) {
if (getDistanceSP(s1, s2.p1) < (1e-20)) return s2.p1;
if (getDistanceSP(s1, s2.p2) < (1e-20)) return s2.p2;
swap(s1, s2);
}
Point base = s2.p2 - s2.p1;
long double d1 = abs(cross(base, s1.p1 - s2.p1));
long double d2 = abs(cross(base, s1.p2 - s2.p1));
long double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
Point getCrossPointLL(Segment l1, Segment l2) {
long double a = cross(l1.p2 - l1.p1, l2.p2 - l2.p1);
long double b = cross(l1.p2 - l1.p1, l1.p2 - l2.p1);
if (abs(a) < (1e-20) && abs(b) < (1e-20)) return l2.p1;
return l2.p1 + (l2.p2 - l2.p1) * (b / a);
}
vector<Point> getCrossPointCL(Circle c, Segment l) {
vector<Point> ps;
Point pr = project(l, c.c);
Point e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
if ((fabs((getDistanceLP(l, c.c)) - (c.r)) < (1e-20))) {
ps.emplace_back(pr);
return ps;
}
long double base = sqrt(c.r * c.r - norm(pr - c.c));
ps.emplace_back(pr + e * base);
ps.emplace_back(pr - e * base);
return ps;
}
vector<Point> getCrossPointCS(Circle c, Segment s) {
Segment l(s);
vector<Point> res = getCrossPointCL(c, l);
if (intersectCS(c, s) == 2) return res;
if (res.size() > 1u) {
if (dot(l.p1 - res[0], l.p2 - res[0]) > 0) swap(res[0], res[1]);
res.pop_back();
}
return res;
}
vector<Point> getCrossPointCC(Circle c1, Circle c2) {
vector<Point> p(2);
long double d = abs(c1.c - c2.c);
long double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
long double t = arg(c2.c - c1.c);
p[0] = c1.c + polar(c1.r, t + a);
p[1] = c1.c + polar(c1.r, t - a);
return p;
}
int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
for (int i = 0; i < n; i++) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
if (fabs(cross(a, b)) < (1e-20) && dot(a, b) < (1e-20)) return 1;
if (a.y > b.y) swap(a, b);
if (a.y < (1e-20) && (1e-20) < b.y && cross(a, b) > (1e-20)) x = !x;
}
return (x ? 2 : 0);
}
vector<Point> andrewScan(vector<Point> s) {
vector<Point> l;
if (s.size() < 3) return s;
sort(s.begin(), s.end());
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = s.size() - 3; i >= 0; i--) {
for (int n = l.size();
n >= 2 && (ccw(l[n - 2], l[n - 1], s[i]) != CCW_CLOCKWISE &&
ccw(l[n - 2], l[n - 1], s[i]) != CCW_ONLINE_FRONT);
n--) {
l.pop_back();
}
l.push_back(s[i]);
}
return l;
}
signed main() {
int n;
cin >> n;
vector<int> rs(n), ss(n);
for (int i = 0; i < n; i++) cin >> rs[i] >> ss[i];
using P = pair<int, int>;
set<P> uku;
int num = 0;
vector<Point> qs(n);
for (int i = 0; i < n; i++) {
if (uku.count(P(rs[i], ss[i]))) continue;
uku.emplace(rs[i], ss[i]);
qs[num].x = 1.0 / rs[i];
qs[num].y = 1.0 / ss[i];
num++;
}
qs.resize(num);
qs.emplace_back(1e18, 0);
qs.emplace_back(0, 1e18);
qs = andrewScan(qs);
using P = pair<int, int>;
set<P> cand;
for (auto p : qs) {
if (p.x == 0 || p.y == 0) continue;
int a = round(1.0 / p.x);
int b = round(1.0 / p.y);
cand.emplace(a, b);
}
vector<int> ans;
for (int i = 0; i < n; i++)
if (cand.count(P(rs[i], ss[i]))) ans.emplace_back(i);
for (int i = 0; i < (int)ans.size(); i++) {
if (i) cout << " ";
cout << ans[i] + 1;
}
cout << endl;
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 = 0, sz = rlt.size();
for (k = 1; k < sz; k++)
if (rlt[k - 1].y >= rlt[k].y) break;
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;
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 << ' ';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > p;
int po[200200];
bool cmp(int g, int h) {
return (p[g].first > p[h].first) ||
(p[g].first == p[h].first && p[g].second > p[h].second);
}
int main() {
int n;
scanf("%d", &n);
vector<int> num;
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
p.push_back(make_pair(x, -y));
num.push_back(i);
}
sort(num.begin(), num.end(), cmp);
for (int i = 0; i < n; i++) po[num[i]] = i;
vector<int> c;
for (int i = 0; i < n; i++) {
while (c.size() && p[num[i]].first == p[c.back()].first &&
p[num[i]].second != p[c.back()].second)
c.pop_back();
if (c.size() && p[num[i]].first != p[c.back()].first &&
p[num[i]].second >= p[c.back()].second)
continue;
if (c.size() && p[num[i]].first == p[c.back()].first &&
p[num[i]].second == p[c.back()].second)
continue;
while (c.size() > 1) {
int g = c[c.size() - 2];
int h = c[c.size() - 1];
int j = num[i];
long long k1 = p[h].second * p[j].first;
long long k2 = p[h].first * p[j].second;
if (k1 * (p[h].first - p[g].first) * (p[j].second - p[g].second) -
k2 * (p[h].second - p[g].second) * (p[j].first - p[g].first) <
0)
c.pop_back();
else
break;
}
c.push_back(num[i]);
}
int m = c.size();
for (int i = 0; i < m; i++) {
int it = c[i];
for (int j = po[c[i]] - 1; j >= 0; j--)
if (p[num[j]].first == p[c[i]].first &&
p[num[j]].second == p[c[i]].second)
c.push_back(num[j]);
else
break;
for (int j = po[c[i]] + 1; j < n; j++)
if (p[num[j]].first == p[c[i]].first &&
p[num[j]].second == p[c[i]].second)
c.push_back(num[j]);
else
break;
}
sort(c.begin(), c.end());
for (int i = 0; i < c.size(); i++)
printf("%d%c", c[i] + 1, " \n"[i == c.size() - 1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const double eps = 1e-9;
int s[maxn], r[maxn];
double a[maxn], b[maxn];
int st[maxn];
vector<int> equiv[maxn];
map<pair<int, int>, int> rep;
bool f[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d %d", &s[i], &r[i]);
vector<int> o;
for (int i = 0; i < n; ++i) {
if (rep.find(make_pair(s[i], r[i])) != rep.end())
equiv[rep[make_pair(s[i], r[i])]].push_back(i);
else
o.push_back(i), rep[make_pair(s[i], r[i])] = i;
}
for (int i : o) a[i] = 1.0 * (r[i] - s[i]) / s[i] / r[i], b[i] = 1.0 / r[i];
sort(o.begin(), o.end(), [&](const int &i, const int &j) {
return tie(a[i], b[i]) > tie(a[j], b[j]);
});
int p = 0;
for (int i = 0; i < o.size(); ++i) {
int z = o[i];
while (p >= 2) {
int x = st[p - 1], y = st[p - 2];
if ((b[y] - b[z]) * 1ll * (a[x] - a[y]) <
(b[y] - b[x]) * 1ll * (a[z] - a[y]))
--p;
else
break;
}
st[p++] = z;
}
vector<int> ans;
int z = 0;
for (int i = 0; i < p - 1; ++i) {
int l = st[i], r = st[i + 1];
double x = 1.0 * (b[l] - b[r]) / (a[r] - a[l]);
if (x < 0.0 || fabs(x) < eps) f[l] = true;
}
for (int i = p - 1; i > 0; --i) {
int l = st[i - 1], r = st[i];
double x = 1.0 * (b[l] - b[r]) / (a[r] - a[l]);
if (x > 1.0 || fabs(x - 1) < eps) f[r] = true;
}
for (int i = 0; i < p; ++i)
if (!f[st[i]]) {
ans.push_back(st[i]);
for (int j = 0; j < equiv[st[i]].size(); ++j)
ans.push_back(equiv[st[i]][j]);
}
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); ++i) printf("%d ", ans[i] + 1);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
pair<pair<int, int>, int> arr[N];
int s[N];
int sz;
vector<int> ans;
set<pair<int, int> > ss;
bool useless(pair<int, int> lft, pair<int, int> mid, pair<int, int> rgt) {
return 1LL * (lft.second - mid.second) * (rgt.first - mid.first) *
rgt.second * lft.first >
1LL * (mid.second - rgt.second) * (mid.first - lft.first) *
lft.second * rgt.first;
}
bool lol(pair<int, int> lft, pair<int, int> rgt) {
long long num = 1LL * (lft.second - rgt.second) * lft.first * rgt.first;
long long den = 1LL * (rgt.first - lft.first) * lft.second * rgt.second;
return !num || ((num / llabs(num)) != (den / llabs(den)));
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &arr[i].first.first, &arr[i].first.second);
arr[i].second = i;
}
sort(arr + 1, arr + 1 + n);
sz = 0;
for (int i = 1; i <= n; ++i) {
while (sz >= 1 && arr[s[sz]].first.first == arr[i].first.first &&
arr[s[sz]].first.second <= arr[i].first.second) {
--sz;
}
while (sz >= 2 &&
useless(arr[s[sz - 1]].first, arr[s[sz]].first, arr[i].first)) {
--sz;
}
s[++sz] = i;
}
for (int i = 1; i <= sz; ++i) {
if (i < sz) {
if (lol(arr[s[i]].first, arr[s[i + 1]].first)) {
continue;
}
}
ss.insert(arr[s[i]].first);
}
for (int i = 1; i <= n; ++i) {
if (ss.find(arr[i].first) != ss.end()) {
ans.emplace_back(arr[i].second);
}
}
sort(ans.begin(), ans.end());
for (int x : ans) {
printf("%d ", x);
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
int id;
bool operator<(point a) const { return x != a.x ? x < a.x : y < a.y; }
} p[200010];
int n, tot;
int s[200010], top;
std::vector<int> ans, vec[200010];
inline double calc(int a, int b) {
return (p[a].y - p[b].y) / (p[a].x - p[b].x);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int r, s;
scanf("%d%d", &r, &s);
p[i] = (point){(double)1.0 / r, (double)1.0 / s, i};
}
sort(p + 1, p + 1 + n);
tot = 1;
for (int i = 2; i <= n; i++)
if (p[i].x != p[tot].x)
p[++tot] = p[i];
else if (p[i].y == p[tot].y)
vec[p[tot].id].push_back(p[i].id);
s[1] = 1;
top = 1;
for (int i = 2; i <= tot; i++) {
while (top > 1 && calc(s[top - 1], s[top]) > calc(s[top - 1], i)) top--;
s[++top] = i;
}
ans.push_back(p[s[1]].id);
for (auto i : vec[p[s[1]].id]) ans.push_back(i);
for (int i = 2; i <= top; i++) {
if (calc(s[i - 1], s[i]) < 0) {
ans.push_back(p[s[i]].id);
for (int j : vec[p[s[i]].id]) ans.push_back(j);
}
}
sort(ans.begin(), ans.end());
for (auto i : ans) printf("%d ", i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
int id;
Point() {}
Point(double x, double y) {
this->x = x;
this->y = y;
}
void read(int id) {
int s, b;
scanf("%d%d", &s, &b);
x = 1000000.0 / s;
y = 1000000.0 / b;
this->id = id;
}
};
const double eps = 1e-16;
int dcmp(double x) {
if (fabs(x) < eps)
return 0;
else
return x < 0 ? -1 : 1;
}
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); }
Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); }
bool operator<(const Point& a, const Point& b) {
return a.x < b.x || (dcmp(a.x - b.x) == 0 && a.y < b.y);
}
bool operator==(const Point& a, const Point& b) {
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }
double Length(Point A) { return sqrt(Dot(A, A)); }
double Angle(Point A, Point B) {
return acos(Dot(A, B) / Length(A) / Length(B));
}
double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }
double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); }
struct Line {
Point v, p;
Line() {}
Line(Point v, Point p) {
this->v = v;
this->p = p;
}
Point point(double t) { return v + p * t; }
};
Point Rotate(Point A, double rad) {
return Point(A.x * cos(rad) - A.y * sin(rad),
A.x * sin(rad) + A.y * cos(rad));
}
Point AngleBisector(Point p, Point v1, Point v2) {
double rad = Angle(v1, v2);
return Rotate(v1, dcmp(Cross(v1, v2)) * 0.5 * rad);
}
bool LineCoincide(Point p1, Point p2, Point p3) {
return dcmp(Cross(p2 - p1, p3 - p1)) == 0;
}
bool LineParallel(Point v, Point w) { return Cross(v, w) == 0; }
bool LineVertical(Point v, Point w) { return Dot(v, w) == 0; }
Point GetLineIntersection(Point P, Point v, Point Q, Point w) {
Point u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
}
double DistanceToLine(Point P, Point A, Point B) {
Point v1 = B - A, v2 = P - A;
return fabs(Cross(v1, v2)) / Length(v1);
}
double DistanceToSegment(Point P, Point A, Point B) {
if (A == B) return Length(P - A);
Point v1 = B - A, v2 = P - A, v3 = P - B;
if (dcmp(Dot(v1, v2)) < 0)
return Length(v2);
else if (dcmp(Dot(v1, v3)) > 0)
return Length(v3);
else
return fabs(Cross(v1, v2)) / Length(v1);
}
Point GetLineProjection(Point P, Point A, Point B) {
Point v = B - A;
return A + v * (Dot(v, P - A) / Dot(v, v));
}
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
bool SegmentProperIntersection2(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return max(a1.x, a2.x) >= min(b1.x, b2.x) &&
max(b1.x, b2.x) >= min(a1.x, a2.x) &&
max(a1.y, a2.y) >= min(b1.y, b2.y) &&
max(b1.y, b2.y) >= min(a1.y, a2.y) && dcmp(c1) * dcmp(c2) <= 0 &&
dcmp(c3) * dcmp(c4) <= 0;
}
bool OnSegment(Point p, Point a1, Point a2) {
return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
}
double PolygonArea(Point* p, int n) {
double area = 0;
for (int i = 1; i < n - 1; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
int isPointInPolygon(Point o, Point* p, int n) {
int wn = 0;
for (int i = 0; i < n; i++) {
if (OnSegment(o, p[i], p[(i + 1) % n])) return -1;
int k = dcmp(Cross(p[(i + 1) % n] - p[i], o - p[i]));
int d1 = dcmp(p[i].y - o.y);
int d2 = dcmp(p[(i + 1) % n].y - o.y);
if (k > 0 && d1 <= 0 && d2 > 0) wn++;
if (k < 0 && d2 <= 0 && d1 > 0) wn--;
}
if (wn != 0) return 1;
return 0;
}
const int N = 200005;
int to[N];
int ConvexHull(Point* p, int n, Point* ch) {
sort(p, p + n);
int m = 0;
memset(to, -1, sizeof(to));
for (int i = 0; i < n; i++) {
to[i] = i;
if (i && p[i] == p[i - 1]) {
to[i] = to[i - 1];
continue;
}
while (m > 1 && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0)
m--;
ch[m++] = p[i];
}
int k = m;
for (int i = n - 2; i >= 0; i--) {
while (m > k && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0)
m--;
ch[m++] = p[i];
}
if (n > 1) m--;
return m;
}
Point a[N + 10], ch[N + 10];
bool vis[N + 10];
int n, m;
double mi = 1e18;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
a[i].read(i);
}
m = ConvexHull(a, n, ch);
for (int i = 0; i < m; i++) mi = min(mi, ch[i].y);
for (int i = 0; i < m; i++) {
vis[ch[i].id] = 1;
if (ch[i].y == mi) break;
}
for (int i = 0; i < n; i++)
if (vis[a[to[i]].id]) vis[a[i].id] = 1;
for (int i = 0; i < n; i++)
if (vis[i]) {
printf("%d", i + 1);
if (i == n - 1)
puts("");
else
putchar(' ');
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t det(const pair<int, int> &a, const pair<int, int> &b,
const pair<int, int> &c) {
return int64_t(c.second - a.second) * (c.first - b.first) * a.first *
b.second -
int64_t(c.first - a.first) * (c.second - b.second) * a.second *
b.first;
}
int main() {
int n;
cin >> n;
vector<pair<int, int> > p;
p.reserve(n + 2);
for (int i = 0; i < n; ++i) {
int second, first;
scanf("%d%d", &second, &first);
p.emplace_back(second, first);
}
vector<pair<int, int> > P = p;
p.emplace_back(0, 10001);
p.emplace_back(10001, 0);
sort((p).begin(), (p).end());
vector<pair<int, int> > ch;
int k = -1;
ch.reserve(n + 2);
for (auto q : p) {
for (; k > 0 && (ch[k].second == q.second || det(ch[k - 1], ch[k], q) < 0);
--k)
ch.pop_back();
ch.push_back(q);
++k;
}
sort((ch).begin(), (ch).end());
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 double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const long long mod = (long long)(1e9 + 7);
const int MAX_N = 200010;
const double eps = 1e-7;
int n, m;
int vis[MAX_N];
inline int sgn(double x) {
if (fabs(x) <= eps)
return 0;
else if (x > 0)
return 1;
else
return -1;
}
struct Point {
int tx, ty, id;
double x, y;
Point() {}
Point(double _x, double _y) : x(_x), y(_y) {}
Point operator-(const Point& rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
double cross(const Point& rhs) const { return x * rhs.y - y * rhs.x; }
bool operator<(const Point& rhs) const {
if (!sgn(x - rhs.x)) return y < rhs.y;
return x < rhs.x;
}
} P[MAX_N], V[MAX_N], leftCorner;
int andrew() {
sort(P, P + n);
int k = 0;
for (int i = 0; i < n; ++i) {
if (i && !sgn(P[i].x - P[i - 1].x)) continue;
while (k > 1 && sgn((V[k - 1] - V[k - 2]).cross(P[i] - V[k - 2])) < 0) k--;
V[k++] = P[i];
}
return k;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int x, y;
scanf("%d%d", &x, &y);
P[i].tx = x, P[i].ty = y, P[i].id = i + 1;
P[i].x = 100000.0 / x, P[i].y = 100000.0 / y;
}
memset(vis, 0, sizeof(vis));
m = andrew();
for (int i = 0; i < m; ++i) {
if (!i || sgn(V[i].y - V[i - 1].y) < 0) vis[V[i].id] = 1;
}
for (int i = 0; i < n; ++i) {
if (i && !sgn(P[i].x - P[i - 1].x) && !sgn(P[i].y - P[i - 1].y) &&
vis[P[i - 1].id]) {
vis[P[i].id] = 1;
}
}
for (int i = 1; i <= n; ++i) {
if (vis[i]) printf("%d ", i);
}
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
bool t = false;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = true, ch = getchar();
while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
return t ? -x : x;
}
map<pair<int, int>, int> M;
int n, top;
struct Node {
int x, y, id;
long double xx, yy;
} p[300300], S[300300];
bool operator<(Node a, Node b) {
if (a.y != b.y) return a.y < b.y;
return a.x > b.x;
}
bool cmp(Node a, Node b) { return a.id < b.id; }
long double K(Node a, Node b) { return (a.xx - b.xx) / (a.yy - b.yy); }
bool vis[300300];
int main() {
n = read();
for (int i = 1; i <= n; ++i) p[i].x = read(), p[i].y = read(), p[i].id = i;
for (int i = 1; i <= n; ++i) p[i].xx = 1e9 / p[i].x;
for (int i = 1; i <= n; ++i) p[i].yy = 1e9 / p[i].y;
sort(&p[1], &p[n + 1]);
S[top = 1] = (Node){0, 0, 0, 0, 1e18};
for (int i = 1; i <= n; ++i) {
if (p[i].y == p[i - 1].y) continue;
while (top > 1 && K(p[i], S[top]) > K(S[top], S[top - 1]) + 1e-15) --top;
S[++top] = p[i];
}
sort(&p[1], &p[n + 1], cmp);
for (int i = 1; i <= top; ++i) M[make_pair(S[i].x, S[i].y)] = 1;
for (int i = 1; i <= n; ++i)
if (M.find(make_pair(p[i].x, p[i].y)) != M.end()) printf("%d ", i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
return a < 0 ? -a : a;
}
template <typename t, typename t1>
t min1(t a, t1 b) {
return a < b ? a : b;
}
template <typename t, typename... arg>
t min1(t a, arg... arr) {
return min1(a, min1(arr...));
}
template <typename t, typename t1>
t max1(t a, t1 b) {
return a > b ? a : b;
}
template <typename t, typename... arg>
t max1(t a, arg... arr) {
return max1(a, max1(arr...));
}
inline int jud(double a, double b) {
if (abs(a) < eps && abs(b) < eps)
return 0;
else if (abs1(a - b) / abs1(a) < eps)
return 0;
if (a < b) return -1;
return 1;
}
template <typename t>
inline int jud(t a, t b) {
if (a < b) return -1;
if (a == b) return 0;
return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
int be = 0, en = na - 1;
if (*a <= *(a + na - 1)) {
if (f_lb == 0)
while (be < en) {
int mid = (be + en + 1) / 2;
if (jud(*(a + mid), val) != 1)
be = mid;
else
en = mid - 1;
}
else
while (be < en) {
int mid = (be + en) / 2;
if (jud(*(a + mid), val) != -1)
en = mid;
else
be = mid + 1;
}
if (f_small && jud(*(a + be), val) == 1) be--;
if (!f_small && jud(*(a + be), val) == -1) be++;
} else {
if (f_lb)
while (be < en) {
int mid = (be + en + 1) / 2;
if (jud(*(a + mid), val) != -1)
be = mid;
else
en = mid - 1;
}
else
while (be < en) {
int mid = (be + en) / 2;
if (jud(*(a + mid), val) != 1)
en = mid;
else
be = mid + 1;
}
if (!f_small && jud(*(a + be), val) == -1) be--;
if (f_small && jud(*(a + be), val) == 1) be++;
}
return be;
}
template <class T>
inline T lowb(T num) {
return num & (-num);
}
inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(unsigned long long nValue) {
return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitnum(long long nValue) {
return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitmaxl(unsigned int a) {
if (a == 0) return 0;
return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
if (a == 0) return 0;
return 32 - __builtin_clz(a);
}
inline int bitmaxl(unsigned long long a) {
int temp = a >> 32;
if (temp) return 32 - __builtin_clz(temp) + 32;
return bitmaxl(int(a));
}
inline int bitmaxl(long long a) {
int temp = a >> 32;
if (temp) return 32 - __builtin_clz(temp) + 32;
return bitmaxl(int(a));
}
long long pow(long long n, long long m, long long mod = 0) {
if (m < 0) return 0;
long long ans = 1;
long long k = n;
while (m) {
if (m & 1) {
ans *= k;
if (mod) ans %= mod;
}
k *= k;
if (mod) k %= mod;
m >>= 1;
}
return ans;
}
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
if (mod == -1) mod = 1000000007;
a += b;
while (a >= mod) a -= mod;
while (a < 0) a += mod;
}
template <class t>
void output1(t arr) {
for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] << ' ';
cerr << endl;
}
template <class t>
void output2(t arr) {
for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]);
}
const int maxn = 300100;
int n;
pair<pair<int, int>, int> orig[maxn];
pair<double, double> p[maxn];
typename set<pair<double, double> >::iterator sit;
int getjud(pair<int, int> &b, pair<int, int> &a) {
if (b.first > a.first && b.second >= a.second) return 1;
if (b.first >= a.first && b.second > a.second) return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &orig[i].first.first, &orig[i].first.second);
orig[i].second = i;
}
sort(orig, orig + n);
int lst = 0;
for (int i = 0; i < n; i++) {
while (lst && getjud(orig[i].first, orig[lst - 1].first)) lst--;
orig[lst++] = orig[i];
}
for (int i = 0; i < lst; i++)
p[i] = make_pair(10000.0 / orig[i].first.first, 1.0 / orig[i].first.second);
set<pair<double, double> > s1, s2;
for (int i = 0; i < lst; i++) {
if (i == 0 || orig[i].first != orig[i - 1].first) s1.insert(p[i]);
}
priority_queue<pair<double, pair<double, double> >,
vector<pair<double, pair<double, double> > >,
greater<pair<double, pair<double, double> > > >
pq;
for (auto it = s1.begin(); it != s1.end(); it++) {
auto it1 = it;
it1++;
if (it1 == s1.end()) break;
pq.push(
make_pair((it1->first - it->first) / (it->second - it1->second), *it1));
}
s2.insert(*s1.begin());
for (; pq.size();) {
pair<double, pair<double, double> > temp = pq.top();
pq.pop();
auto it = s1.find(temp.second);
if (it == s1.end()) continue;
if (it == s1.begin()) continue;
auto rit = it;
rit--;
double t = (it->first - rit->first) / (rit->second - it->second);
if (jud(t, temp.first) != 0) continue;
if (rit == s1.begin()) {
s2.insert(*it);
s1.erase(rit);
continue;
}
s1.erase(rit);
rit = it;
rit--;
t = (it->first - rit->first) / (rit->second - it->second);
pq.push(make_pair(t, *it));
}
int ans[maxn], lans = 0;
;
for (int i = 0; i < lst; i++)
if (s2.find(p[i]) != s2.end()) {
ans[lans++] = orig[i].second;
}
sort(ans, ans + lans);
for (int i = 0; i < lans; i++) printf("%d ", ans[i] + 1);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long r[200002], s[200002];
int l[200002], g[200002];
int bestl[200002], bestr[200002];
int main(void) {
int n;
scanf("%d", &n);
vector<tuple<int, int, int> > f;
for (int i = 0; i < n; i++) {
scanf("%lld %lld", r + i, s + i);
f.emplace_back(s[i], r[i], i);
}
sort(f.rbegin(), f.rend());
set<pair<int, int> > ss;
memset(g, -1, sizeof g);
vector<int> w;
int m = -1;
for (int i = 0; i < n; i++) {
int s, t, id;
tie(s, t, id) = f[i];
if (t <= m) {
if (ss.count(make_pair(s, t))) g[id] = g[get<2>(f[i - 1])];
continue;
}
g[id] = id;
m = t;
w.push_back(id);
ss.insert(make_pair(s, t));
}
l[w[0]] = true;
l[w.back()] = true;
m = w.size();
bestr[m - 1] = m - 1;
for (int i = m - 2; i >= 0; i--) {
int b = w[i];
int a = w[i + 1];
int c = bestr[i + 1];
bestr[i] = c;
if ((r[c] - r[b]) * s[c] * r[a] * (s[b] - s[a]) <
(r[a] - r[b]) * s[a] * r[c] * (s[b] - s[c]))
bestr[i] = a;
}
bestl[0] = 0;
for (int i = 1; i < m; i++) {
int b = w[i];
int a = w[i - 1];
int c = bestl[i - 1];
bestl[i] = c;
if ((r[c] - r[b]) * s[c] * r[a] * (s[b] - s[a]) >
(r[a] - r[b]) * s[a] * r[c] * (s[b] - s[c]))
bestl[i] = a;
}
for (int i = 1; i < int(w.size()) - 1; i++) {
int b = w[i];
int a = bestl[i];
int c = bestr[i];
if ((r[c] - r[b]) * s[c] * r[a] * (s[a] - s[b]) <=
(r[b] - r[a]) * s[a] * r[c] * (s[b] - s[c])) {
l[b] = true;
}
}
vector<int> v;
for (int i = 0; i < n; i++)
if (g[i] != -1 and l[g[i]]) v.push_back(i + 1);
for (auto a : v) cout << a << " ";
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200010;
const double INF = 1e15;
const double EPS = 1e-16;
int sig(double x) { return (x < -EPS) ? -1 : (x > EPS) ? 1 : 0; }
struct Point {
double x, y;
int id;
Point(double x = 0, double y = 0) : x(x), y(y) { id = 0; }
};
Point operator+(const Point a, const Point b) {
return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point a, const Point b) {
return Point(a.x - b.x, a.y - b.y);
}
double operator*(const Point a, const Point b) { return a.x * b.y - a.y * b.x; }
double operator^(const Point a, const Point b) { return a.x * b.x + a.y * b.y; }
Point operator*(const Point a, const double x) {
return Point(a.x * x, a.y * x);
}
Point operator/(const Point a, const double x) {
return Point(a.x / x, a.y / x);
}
double cross(const Point &a, const Point &b) { return (a.x * b.y - a.y * b.x); }
double dot(const Point &a, const Point &b) { return (a.x * b.x + a.y * b.y); }
double dis2(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool operator==(const Point a, const Point b) {
return (fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS);
}
bool operator<(const Point a, const Point b) {
return a.x < b.x || (fabs(a.x - b.x) < EPS && a.y < b.y);
}
int N;
Point p[maxN], stk[maxN];
int pos[maxN];
bool ans[maxN];
int cnt;
bool check(double x) { return x < 0 || fabs(x) < EPS; }
int MakeHull(Point *ps, int n) {
int cnt;
sort(ps, ps + n);
cnt = 0;
for (int i = 0; i < n; i++) {
if (i > 0 && ps[i] == ps[i - 1]) {
pos[i] = pos[i - 1];
continue;
}
pos[i] = i;
while (cnt > 1 && check(cross(stk[cnt - 1] - stk[cnt - 2],
ps[i] - stk[cnt - 2])) == true)
cnt--;
stk[cnt++] = ps[i];
}
int k = cnt;
for (int i = n - 2; i >= 0; i--) {
while (cnt > k && check(cross(stk[cnt - 1] - stk[cnt - 2],
ps[i] - stk[cnt - 2])) == true)
cnt--;
stk[cnt++] = ps[i];
}
if (n > 1) cnt--;
return cnt;
}
int main() {
double s, r;
double minix = INF;
double miniy = INF;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%lf%lf", &s, &r);
p[i].x = 1000000 / s;
p[i].y = 1000000 / r;
p[i].id = i;
miniy = min(miniy, p[i].y);
minix = min(minix, p[i].x);
}
int tot = MakeHull(p, N);
for (int i = 0; i < tot; i++) {
ans[stk[i].id] = true;
if (fabs(stk[i].y - miniy) < EPS) break;
}
for (int i = 0; i < N; i++) {
if (ans[p[pos[i]].id] == true) ans[p[i].id] = true;
}
for (int i = 0; i < N; i++)
if (ans[i] == true) printf("%d ", i + 1);
printf("\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MaxN(300003);
int a[MaxN], b[MaxN], S[MaxN], top;
map<pair<int, int>, int> F;
struct node {
double x, y;
inline bool operator<(const node &T) const {
return x == T.x ? y < T.y : x < T.x;
}
} p[MaxN];
double cross(const node &p1, const node &p2) {
return (p1.x * p2.x * (p2.y - p1.y)) / (p1.y * p2.y * (p2.x - p1.x));
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
p[i].x = a[i], p[i].y = b[i];
}
sort(p + 1, p + 1 + n);
for (int i = 1; i <= n; i++) {
if (p[i].x == p[i + 1].x) continue;
while (top > 1 &&
cross(p[S[top - 1]], p[S[top]]) < cross(p[S[top - 1]], p[i]))
--top;
S[++top] = i;
}
for (int i = 1; i <= top; i++)
if (i == top || cross(p[S[i]], p[S[i + 1]]) < 0)
F[pair<int, int>(p[S[i]].x, p[S[i]].y)] = 1;
for (int i = 1; i <= n; i++)
if (F.count(pair<int, int>(a[i], b[i]))) printf("%d ", i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
int n;
int r[N], s[N];
pair<long long, long long> a[N];
pair<long long, long long> b[N];
void solve() {
cin >> n;
for (int i = 0; i < n; ++i) {
int x, y;
scanf("%d%d", &x, &y);
r[i] = y;
s[i] = x;
a[i] = make_pair(y, x);
}
sort(a, a + n);
int mv = -1;
int m = 0;
for (int i = n - 1; i >= 0; --i) {
if (a[i].second <= mv) {
continue;
}
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 (int i = 0; i < st.size(); ++i) {
ss.insert(make_pair(st[i].first, st[i].second));
}
for (int i = 0; i < n; ++i) {
if (ss.count(make_pair(r[i], s[i]))) {
printf("%d ", i + 1);
}
}
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Member {
int s;
int r;
int id;
};
Member arr[2 * 100000];
int main(int argc, char** argv) {
cout.sync_with_stdio(false);
cin.sync_with_stdio(false);
istream* pinp;
{ pinp = &cin; }
istream& icp = *pinp;
int i, j = 0;
int num;
icp >> num;
i = num;
while (i--) {
icp >> arr[j].s;
icp >> arr[j].r;
arr[j].id = j + 1;
j++;
}
std::sort(begin(arr), begin(arr) + num,
[](Member& a, Member& b) { return a.r > b.r; });
int start = 0;
int maxS = -1;
int maxSIdx;
int localMax = -1;
int localIdx;
list<int> nums;
for (int k = 0; k < num; k++) {
if (arr[k].s > localMax) {
localMax = arr[k].s;
localIdx = k;
}
if (k == num - 1 || arr[k + 1].r != arr[k].r) {
if (localMax > maxS) {
while (nums.size() >= 2) {
auto it = nums.rbegin();
Member* m2 = &arr[*it];
Member* m1 = &arr[*(++it)];
while (m1->r == m2->r) {
auto next = ++it;
if (next == nums.rend()) break;
m1 = &arr[*next];
}
if (m1->r == m2->r) break;
Member* m3 = &arr[localIdx];
double rs32 =
(double(m3->r) * m2->r * (double(m3->s) - double(m2->s))) /
(double(m3->s) * m2->s * (double(m2->r) - double(m3->r)));
double rs21 =
(double(m1->r) * m2->r * (double(m2->s) - double(m1->s))) /
(double(m1->s) * m2->s * (double(m1->r) - double(m2->r)));
if (rs21 < rs32) {
while (arr[nums.back()].r == m2->r) nums.pop_back();
} else {
break;
}
}
for (int s = start; s <= k; s++) {
if (arr[s].s == localMax) {
nums.push_back(s);
}
}
maxS = localMax;
maxSIdx = localIdx;
}
localMax = -1;
start = k + 1;
}
}
vector<pair<int, int>> res;
for (auto it : nums) {
res.push_back({it, arr[it].id});
}
std::sort(begin(res), end(res), [](pair<int, int>& a, pair<int, int>& b) {
return a.second < b.second;
});
bool test = false;
for (auto m : res) {
if (!test)
cout << m.second << " ";
else
cout << arr[m.first].id << " " << arr[m.first].r << " " << arr[m.first].s
<< " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ans[200200];
struct point {
int x, y, id;
point(int x = 0, int y = 0, int id = 0) : x(x), y(y), id(id) {}
inline int operator*(point a) { return x * a.x + y * a.y; }
inline int operator^(point a) { return x * a.y - y * a.x; }
inline point operator+(point a) { return point(x + a.x, y + a.y, id); }
inline point operator-(point a) { return point(x - a.x, y - a.y, id); }
inline bool operator<(const point &a) const {
return x != a.x ? x < a.x : y < a.y;
}
inline bool operator>(const point &a) const {
return x != a.x ? x > a.x : y > a.y;
}
};
point a[200200], h[200200], aa[200200];
int M;
bool multi(point a, point b, point c) {
return 1LL * (b.x - a.x) * (b.y - c.y) * a.y * c.x <
1LL * (c.x - b.x) * (a.y - b.y) * a.x * c.y;
}
void make_conv(int n) {
if (n == 1) {
M = 2;
h[1] = aa[1];
return;
}
h[1] = aa[1];
h[2] = aa[2];
M = 3;
for (int i = 3; i <= n; i++) {
while (M > 2 and multi(h[M - 2], h[M - 1], aa[i])) M--;
h[M++] = aa[i];
}
}
int main() {
int n;
scanf("%d", &n);
int mx = 0;
int mm = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i].x, &a[i].y);
a[i].id = i;
}
sort(a + 1, a + n + 1);
int ga = 1;
aa[1] = a[n];
int yy = a[n].y, xx = a[n].x;
for (int i = n - 1; i >= 1; i--) {
if (a[i].x < xx and a[i].y > yy) {
aa[++ga] = a[i];
xx = a[i].x;
yy = a[i].y;
}
}
reverse(aa + 1, aa + ga + 1);
make_conv(ga);
int an = 0;
int j = 1;
for (int i = 1; i < M; i++) {
bool fl = 0;
for (j; j <= n; j++) {
if (a[j].x == h[i].x and a[j].y == h[i].y)
ans[++an] = a[j].id, fl = 1;
else if (fl)
break;
}
}
sort(ans + 1, ans + an + 1);
for (int i = 1; i <= an; i++) cout << ans[i] << ' ';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
struct Point {
int id;
int c;
double x, y;
Point(double x = 0, double y = 0, int c = 0, int id = 0)
: x(x), y(y), c(c), id(id) {}
};
const double EPS = 1e-8;
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); }
Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); }
bool operator<(const Point& a, const Point& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
int Sgn(long double x) {
if (fabs(x) < EPS)
return 0;
else
return x < 0 ? -1 : 1;
}
bool operator==(const Point& a, const Point& b) {
return Sgn(a.x - b.x) == 0 && Sgn(a.y - b.y) == 0;
}
long double Cross(Point A, Point B) {
return (long double)A.x * B.y - A.y * B.x;
}
vector<int> v[N];
int ConvexHull(Point* p, int n, Point* ch) {
sort(p, p + n);
int m = 0;
for (int i = 0; i < n; i++) {
p[m++] = p[i];
if (Sgn(p[i + 1].x - p[i].x) == 0) {
int j = i + 1;
for (j = i + 1; j < n; j++) {
if (Sgn(p[j].x - p[i].x) != 0) {
i = j - 1;
break;
} else if (Sgn(p[j].y - p[i].y) == 0) {
v[p[i].id].push_back(p[j].id);
}
}
if (j == n) i = n;
}
}
m = 0;
for (int i = 0; i < n; i++) {
while (m > 1 && (Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) < 0) m--;
ch[m++] = p[i];
}
return m;
}
int n, ans[N];
Point p[N], ch[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0, x, y; i < n; i++) {
cin >> x >> y;
p[i].id = i + 1;
p[i].x = 1.0 / x;
p[i].y = 1.0 / y;
}
n = ConvexHull(p, n, ch);
for (int i = 0; i < n; i++) p[i] = ch[i];
int i;
ans[p[0].id] = 1;
for (int id : v[p[0].id]) ans[id] = 1;
for (i = 1; i < n; i++) {
if (Sgn((p[i].y - p[i - 1].y) / (p[i].x - p[i - 1].x)) < 0) {
ans[p[i].id] = 1;
for (int id : v[p[i].id]) ans[id] = 1;
} else
break;
}
for (int i = 1; i < N; i++) {
if (ans[i]) cout << i << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
struct pt {
double x, y;
};
bool cmp(pt a, pt b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
bool cw(pt a, pt b, pt c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0;
}
bool ccw(pt a, pt b, pt c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
}
void convex_hull(vector<pt>& a) {
if (a.size() == 1) return;
sort(a.begin(), a.end(), &cmp);
pt p1 = a[0], p2 = a.back();
vector<pt> up, down;
up.push_back(p1);
down.push_back(p1);
for (size_t i = 1; i < a.size(); ++i) {
if (i == a.size() - 1 || cw(p1, a[i], p2)) {
while (up.size() >= 2 && !cw(up[up.size() - 2], up[up.size() - 1], a[i]))
up.pop_back();
up.push_back(a[i]);
}
if (i == a.size() - 1 || ccw(p1, a[i], p2)) {
while (down.size() >= 2 &&
!ccw(down[down.size() - 2], down[down.size() - 1], a[i]))
down.pop_back();
down.push_back(a[i]);
}
}
a.clear();
for (size_t i = 0; i < up.size(); ++i) a.push_back(up[i]);
for (size_t i = down.size() - 2; i > 0; --i) a.push_back(down[i]);
}
int main() {
int n;
cin >> n;
vector<pt> ch;
std::vector<std::pair<int, int> > pl;
map<std::pair<int, int>, int> ans;
int x, y;
for (int i = 0; i < n; i++) {
cin >> x >> y;
pl.push_back(make_pair(x, y));
pt a;
a.x = 1. / (double)(x);
a.y = 1. / (double)(y);
ch.push_back(a);
}
convex_hull(ch);
for (int i = 0; i < ch.size(); i++) {
}
int l = ch.size();
double minx = 10;
int indx, indy;
double miny = 10;
for (int i = 0; i < l; i++) {
if (ch[i].x < minx) {
minx = ch[i].x;
indx = i;
}
if (ch[i].y < miny) {
miny = ch[i].y;
indy = i;
}
}
int t = 0;
while ((abs((ch[indy].y) - ch[(indy + 1) % l].y) < 0.000000001) &&
(t < 2 * l)) {
t++;
indy = (indy + 1) % l;
}
t = 0;
while ((abs((ch[indx].x) - ch[(indx + l - 1) % l].x) < 0.000000001) &&
(t < 2 * l)) {
t++;
indx = (indx + l - 1) % l;
}
int ind = indy;
ans[make_pair((int)(1. / ch[ind].x + 0.2), (int)(1. / ch[ind].y + 0.2))] = 1;
while (ind != indx) {
ind = (ind + 1) % l;
ans[make_pair((int)(1. / ch[ind].x + 0.2), (int)(1. / ch[ind].y + 0.2))] =
1;
}
for (int i = 0; i < n; i++) {
if (ans[pl[i]] == 1) cout << (i + 1) << " ";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int r[N], s[N], srt[N], mark[N];
vector<int> a;
int g[N];
int FIND(int x) { return g[x] == x ? g[x] : g[x] = FIND(g[x]); }
void UNION(int x, int y) { g[FIND(x)] = FIND(y); }
bool cmp(int x, int y) {
if (r[x] != r[y]) return r[x] > r[y];
return s[x] > s[y];
}
bool leftTurn(int i, int j, int k) {
return 1LL * (r[j] - r[k]) * (s[i] - s[j]) * r[i] * s[k] >
1LL * (s[j] - s[k]) * (r[i] - r[j]) * s[i] * r[k];
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &r[i], &s[i]);
for (int i = 0; i < n; i++) srt[i] = g[i] = i;
sort(srt, srt + n, cmp);
for (int i = 0; i < n; i++) {
if (i && r[srt[i]] == r[srt[i - 1]] && s[srt[i]] == s[srt[i - 1]]) {
UNION(srt[i], srt[i - 1]);
continue;
}
while (a.size() >= 2 && leftTurn(a[a.size() - 2], a[a.size() - 1], srt[i]))
a.pop_back();
a.push_back(srt[i]);
}
while (a.size() >= 2 && r[a[a.size() - 2]] >= r[a[a.size() - 1]] &&
s[a[a.size() - 2]] >= s[a[a.size() - 1]])
a.pop_back();
for (auto &&x : a) mark[FIND(x)] = 1;
for (int i = 0; i < n; i++)
if (mark[FIND(i)] == 1) printf("%d ", i + 1);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
map<pair<int, int>, vector<int> > mp;
const long double eps = 1e-22;
struct point {
int X, Y;
long double first, second;
point() { X = Y = first = second = .0; }
point(long double a, long double b) { first = a, second = b; }
inline void init(int a, int b) {
X = a, Y = b;
first = 1.0 / X;
second = 1.0 / Y;
}
inline long double operator*(point p) {
return first * p.second - second * p.first;
}
inline point operator-(point p) {
return point(first - p.first, second - p.second);
}
inline long double dis(point p) {
return (((first - p.first) * (first - p.first))) +
(((second - p.second) * (second - p.second)));
}
inline pair<int, int> PII() { return pair<int, int>(X, Y); }
};
point o;
point l;
inline bool ocmp(const point &a, const point &b) {
return make_pair(a.second, a.first) < make_pair(b.second, b.first);
}
inline bool lcmp(const point &a, const point &b) {
return make_pair(a.first, a.second) < make_pair(b.first, b.second);
}
inline bool scmp(const point &a, const point &b) {
long double cross = ((point)a - o) * ((point)b - o);
if (fabs(cross) <= eps) return o.dis(a) < o.dis(b);
return cross < eps;
}
vector<point> v;
vector<point> hull;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int(i) = (0); (i) < (n); ++(i)) {
int a, b;
cin >> a >> b;
mp[{a, b}].push_back(i + 1);
}
if (mp.size() == 1) {
for (int(i) = (1); (i) < (n + 1); ++(i)) cout << i << ' ';
cout << endl;
return 0;
}
for (__typeof((mp).begin()) q = (mp).begin(); q != (mp).end(); ++q) {
pair<int, int> p = q->first;
int first = p.first, second = p.second;
point P;
P.init(first, second);
v.push_back(P);
}
o = *min_element(v.begin(), v.end(), ocmp);
l = *min_element(v.begin(), v.end(), lcmp);
if (o.PII() == l.PII()) {
for (auto &(a) : (mp[o.PII()])) cout << a << ' ';
cout << endl;
return 0;
}
sort(v.begin(), v.end(), scmp);
int po = 2;
for (int(i) = (0); (i) < (2); ++(i)) hull.push_back(v[i]);
vector<int> ans;
while (po < v.size() && hull.back().PII() != l.PII()) {
while (hull.size() > 1 && (hull[hull.size() - 1] - hull[hull.size() - 2]) *
(v[po] - hull[hull.size() - 2]) >
eps)
hull.pop_back();
hull.push_back(v[po++]);
}
for (auto &(p) : (hull))
for (auto &(a) : (mp[p.PII()])) ans.push_back(a);
sort(ans.begin(), ans.end());
for (auto &(a) : (ans)) cout << a << ' ';
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
struct info {
int s, r, id;
info(int s = 0, int r = 0, int id = 0) : s(s), r(r), id(id) {}
bool operator<(const info& b) const {
if (s != b.s) return s < b.s;
return r > b.r;
}
};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long myabs(long long x) { return x > 0 ? x : -x; }
struct fract {
long long n, d;
fract(long long num = 0, long long den = 1) {
assert(0 < den && den < 100000000000000000LL);
long long g = gcd(myabs(num), myabs(den));
n = num / g;
d = den / g;
}
fract operator+(const fract& b) const {
return fract(n * b.d + d * b.n, d * b.d);
}
fract operator-(const fract& b) const {
return fract(n * b.d - d * b.n, d * b.d);
}
fract operator*(const fract& b) const { return fract(n * b.n, d * b.d); }
};
struct point {
fract x, y;
point(fract x = 0, fract y = 0) : x(x), y(y) {}
point operator+(const point& b) const { return point(x + b.x, y + b.y); }
point operator-(const point& b) const { return point(x - b.x, y - b.y); }
fract cross(const point& b) const { return x * b.y - y * b.x; }
};
bool isConvex(int r1, int s1, int r2, int s2, int r3, int s3) {
point A(fract(r2 - r1, r2), fract(s2 - s1, s2));
point B(fract(r3 - r1, r3), fract(s3 - s1, s3));
return (A.cross(B).n >= 0);
}
bool isPositive(int r1, int s1, int r2, int s2) {
assert(s2 > s1);
return (r2 - r1) * (s2 - s1) < 0;
}
int main() {
int n;
scanf("%d", &n);
vector<info> runner(n);
map<pair<int, int>, vector<int> > id;
for (int i = 0; i < (n); i++) {
scanf("%d%d", &runner[i].s, &runner[i].r);
runner[i].id = i + 1;
id[make_pair(runner[i].s, runner[i].r)].push_back(i + 1);
}
sort(runner.begin(), runner.end());
vector<info> v;
for (int i = 0; i < (n); i++) {
if (i == 0 || runner[i - 1].s != runner[i].s) v.push_back(runner[i]);
}
runner = v;
n = v.size();
for (int i = 0; i < (n); i++) swap(runner[i].s, runner[i].r);
sort(runner.begin(), runner.end());
v.clear();
for (int i = 0; i < (n); i++) {
if (i == 0 || runner[i - 1].s != runner[i].s) v.push_back(runner[i]);
}
for (int i = 0; i < (n); i++) swap(runner[i].s, runner[i].r);
sort(runner.begin(), runner.end());
vector<info> st;
for (int i = 0; i < (v.size()); i++) {
info cur = v[i];
int k = st.size();
while (k >= 2 && !isConvex(st[k - 2].r, st[k - 2].s, st[k - 1].r,
st[k - 1].s, cur.r, cur.s)) {
st.pop_back();
k = st.size();
}
while (k >= 1 && !isPositive(st[k - 1].r, st[k - 1].s, cur.r, cur.s)) {
st.pop_back();
k = st.size();
}
st.push_back(cur);
}
vector<int> res;
for (int i = 0; i < (st.size()); i++) {
vector<int>& cv = id[make_pair(st[i].r, st[i].s)];
for (vector<int>::iterator it = cv.begin(); it != cv.end(); it++)
res.push_back(*it);
}
sort(res.begin(), res.end());
for (int i = 0; i < (res.size()); i++) printf("%d ", res[i]);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b) {
long long res = 1;
a %= 1000000007;
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
long long gcd(long long x, long long y) {
while (y) {
long long t = x % y;
x = y;
y = t;
}
return x;
}
long long inv(long long x) { return powmod(x, 1000000007 - 2); }
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, m, P;
struct point {
int x, y, id;
bool operator<(const point &p) const {
return make_pair(x, y) > make_pair(p.x, p.y);
}
} p[401000], s[401000];
int top;
set<pair<int, int> > res;
pair<int, int> b[401000];
map<int, int> mp;
bool cross(point a, point b, point c) {
return 1LL * b.y * c.x * (a.x - b.x) * (a.y - c.y) <
1LL * c.y * b.x * (a.y - b.y) * (a.x - c.x);
}
void solve() {
scanf("%d", &n), m = n;
int top = 0;
for (int i = 0; i < n; i++) {
p[i].x = read(), p[i].y = read();
p[i].id = i + 1;
b[i] = make_pair(p[i].x, p[i].y);
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
if (!top || p[i].y > s[top - 1].y) s[top++] = p[i];
}
for (int i = 0; i < top; i++) p[i] = s[i];
n = top, top = 0;
for (int i = 0; i < n; i++) {
while (top > 1 && cross(s[top - 2], s[top - 1], p[i])) top--;
s[top++] = p[i];
}
for (int i = 0; i < top; i++) mp[s[i].x * 10000 + s[i].y] = 1;
for (int i = 0; i < m; i++)
if (mp[b[i].first * 10000 + b[i].second]) printf("%d ", i + 1);
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200011;
struct Point {
int x, y;
Point() {}
Point(int x, int y) : x(x), y(y) {}
Point operator-(const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
bool operator<(const Point &rhs) const {
return x > rhs.x || (x == rhs.x && y < rhs.y);
}
bool operator==(const Point &rhs) const { return x == rhs.x && y == rhs.y; }
int cross(const Point &rhs) const { return x * rhs.y - y * rhs.x; }
} p[N], old[N];
Point s[N];
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long cross(Point a, Point b, Point c) {
return (long long)(a.x - b.x) * (b.y - c.y) * c.x * a.y -
(long long)(b.x - c.x) * (a.y - b.y) * a.x * c.y;
}
int main() {
ios ::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
old[i].x = p[i].x;
old[i].y = p[i].y;
}
sort(p, p + n);
int top = 0;
for (int i = 0; i < n; i++) {
if (i != 0 && p[i] == p[i - 1]) continue;
if (top > 0 && p[i].y <= s[top - 1].y) continue;
while ((top >= 1 && p[i].x == s[top - 1].x && p[i].y > s[top - 1].y) ||
(top >= 2 && cross(s[top - 2], s[top - 1], p[i]) < 0))
top--;
s[top++] = p[i];
}
set<Point> st;
for (int i = 0; i < top; i++) st.insert(s[i]);
for (int i = 0; i < n; i++)
if (st.find(old[i]) != st.end()) cout << i + 1 << ' ';
cout << '\n';
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
struct R {
R() : first(0), second(0) {}
R(long long _x, long long _y) : first(_x), second(_y) {}
long long first, second;
};
inline R operator+(const R& a, const R& b) {
return R({a.first * b.second + b.first * a.second, a.second * b.second});
}
inline R operator-(const R& a, const R& b) {
auto ans = R({a.first * b.second - b.first * a.second, a.second * b.second});
if (ans.second < 0) {
ans.first = -ans.first;
ans.second = -ans.second;
}
return ans;
}
inline R operator*(const R& a, const R& b) {
return R({a.first * b.first, a.second * b.second});
}
inline bool operator<(const R& a, const R& b) { return (a - b).first < 0; }
inline bool operator==(const R& a, const R& b) {
return a.first == b.first && a.second == b.second;
}
template <class T>
pair<T, T> operator-(const pair<T, T>& a, const pair<T, T>& b) {
return make_pair(a.first - b.first, a.second - b.second);
}
template <class T>
T vec(const pair<T, T>& a, const pair<T, T>& b) {
return a.first * b.second - b.first * a.second;
}
template <class T>
T vec(const pair<pair<T, T>, int>& a, const pair<pair<T, T>, int>& b) {
return vec(a.first, b.first);
}
inline long long gcd(long long a, long long b) {
for (; b; swap(a, b)) a %= b;
return a;
}
inline long long aaa(long long a) {
if (a < 0)
return -a;
else
return a;
}
inline R neg(const R& a) { return R(-a.first, a.second); }
inline R sw(const R& a) { return R(a.second, a.first); }
bool cmp(R p1, R p2) {
long long d1 = p1.first / p1.second;
long long d2 = p2.first / p2.second;
if (d1 != d2) return d1 < d2;
p1.first %= p1.second;
p2.first %= p2.second;
if (!p1.first && !p2.first) return 0;
if (!p1.first) return 1;
if (!p1.second) return 0;
bool ans = cmp(sw(p2), sw(p1));
return ans;
}
inline bool bad(pair<R, R> a, pair<R, R> b) {
auto p1 = a.first * b.second;
auto p2 = b.first * a.second;
if (p1.first < 0 && p2.first > 0) return 1;
if (p1.first > 0 && p2.first < 0) return 0;
long long g1 = gcd(aaa(p1.first), aaa(p1.second));
long long g2 = gcd(aaa(p2.first), aaa(p2.second));
if (p1.first / g1 == p2.first / g2 && p1.second / g1 == p2.second / g2)
return 0;
if (p1.first < 0 && p2.first < 0)
return cmp(neg(p2), neg(p1));
else
return cmp(p1, p2);
}
int a, b, c, d, n, m, k;
pair<pair<int, int>, int> mas[200002];
int fen[200002];
inline void upd(int first, int val) {
for (; first >= 0; first = (first & (first + 1)) - 1) fen[first] += val;
}
inline int fnd(int first) {
int ans = 0;
for (; first <= 200000; first |= first + 1) ans += fen[first];
return ans;
}
int main() {
scanf("%d", &n);
vector<int> ny;
for (int _n((n)-1), i(0); i <= _n; i++) {
scanf("%d%d", &mas[i].first.first, &mas[i].first.second);
mas[i].second = i;
ny.push_back(mas[i].first.second);
}
sort((ny).begin(), (ny).end());
ny.resize(unique((ny).begin(), (ny).end()) - ny.begin());
sort(mas, mas + n);
vector<pair<int, int>> cool;
for (int i = (n - 1), _b = (0); i >= _b; i--) {
if (i != n - 1 && mas[i + 1].first == mas[i].first) continue;
int t =
lower_bound((ny).begin(), (ny).end(), mas[i].first.second) - ny.begin();
if (!fnd(t)) cool.push_back(mas[i].first);
upd(t, 1);
}
vector<pair<R, R>> pnt;
for (int _n(((int)((cool).size())) - 1), i(0); i <= _n; i++) {
R first({1LL, (long long)cool[i].first});
R second({1LL, (long long)cool[i].second});
auto t = make_pair(first, second);
pnt.push_back(t);
}
sort((pnt).begin(), (pnt).end());
vector<pair<R, R>> hull;
for (int _n(((int)((pnt).size())) - 1), i(0); i <= _n; i++) {
if (i && pnt[i - 1].first == pnt[i].first) continue;
auto t = pnt[i];
while (hull.size() > 1 && bad(hull.back() - hull[(int)((hull).size()) - 2],
t - hull[(int)((hull).size()) - 2]))
hull.pop_back();
hull.push_back(t);
}
sort((hull).begin(), (hull).end());
vector<int> res;
for (int _n((n)-1), i(0); i <= _n; i++) {
R first({1LL, (long long)mas[i].first.first});
R second({1LL, (long long)mas[i].first.second});
auto t = make_pair(first, second);
if (binary_search((hull).begin(), (hull).end(), t)) {
res.push_back(mas[i].second);
}
}
sort((res).begin(), (res).end());
for (int _n(((int)((res).size())) - 1), i(0); i <= _n; i++) {
if (i) printf(" ");
printf("%d", res[i] + 1);
}
printf("\n");
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
double INF = 1000000000000.0;
struct node {
int a, b, id;
} p[N];
int v[N], jd[N];
bool cmp(node a, node b) { return a.a == b.a ? (a.b > b.b) : a.a > b.a; }
int top, sta1[N], top1;
int sta[N];
double calk(int x, int y) {
return (1.0 * p[x].a * p[y].a * (p[y].b - p[x].b)) /
(1.0 * p[x].b * p[y].b * (p[y].a - p[x].a));
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].a, &p[i].b);
for (int i = 1; i <= n; ++i) p[i].id = i;
sort(p + 1, p + n + 1, cmp);
int mn = p[1].b;
for (int i = 2; i <= n; ++i) {
if (p[i].b <= mn)
v[i] = 1;
else
mn = p[i].b;
}
sta[++top] = 1;
for (int i = 1; i <= n; ++i) {
if (v[i]) continue;
while (top > 1 && calk(sta[top], sta[top - 1]) > calk(i, sta[top])) {
top--;
}
sta[++top] = i;
}
for (int i = 1; i <= top; ++i) {
if (jd[p[sta[i]].id]) continue;
jd[p[sta[i]].id] = 1;
for (int j = sta[i] + 1;
j <= n && p[j].a == p[sta[i]].a && p[j].b == p[sta[i]].b; ++j)
jd[p[j].id] = 1;
}
for (int i = 1; i <= n; ++i)
if (jd[i]) printf("%d ", i);
}
|
#include <bits/stdc++.h>
using namespace std;
struct point {
long x, y, rk, lx, ly, rx, ry;
} a[300006];
long n;
set<long> ans;
vector<point> stk;
bool cmp1(point a, point b) { return (a.x < b.x || (a.x == b.x && a.y < b.y)); }
bool cmp2(point a, point b) { return (a.rk > b.rk); }
int mult(unsigned long long x1, unsigned long long y1, unsigned long long x2,
unsigned long long y2, unsigned long long x3, unsigned long long y3) {
unsigned long long tmp1, tmp2;
tmp1 = x3 * y2 * (x1 - x2) * (y1 - y3);
tmp2 = x2 * y3 * (x1 - x3) * (y1 - y2);
if (tmp1 > tmp2) return 1;
if (tmp1 == tmp2) return 0;
return -1;
}
int main() {
long i, j, bj1, bj2, l, r;
scanf("%ld", &n);
for (i = 1; i <= n; ++i) {
scanf("%ld %ld", &a[i].x, &a[i].y);
a[i].rk = i;
}
sort(a + 1, a + 1 + n, cmp1);
bj1 = a[n].x;
bj2 = a[n].y;
for (i = n - 1; i; --i) {
if (a[i].y <= bj2 && !(a[i].x == bj1 && a[i].y == bj2))
a[i].rk = 0;
else {
bj1 = a[i].x;
bj2 = a[i].y;
}
}
sort(a + 1, a + 1 + n, cmp2);
while (!a[n].rk) --n;
sort(a + 1, a + 1 + n, cmp1);
ans.clear();
l = 1;
while (l <= n && a[l].x == a[1].x && a[l].y == a[1].y) {
ans.insert(a[l].rk);
++l;
}
r = n;
while (r && a[r].x == a[n].x && a[r].y == a[n].y) {
ans.insert(a[r].rk);
--r;
}
if (n > 2) {
a[l].lx = a[1].x;
a[l].ly = a[1].y;
stk.clear();
stk.push_back(a[1]);
stk.push_back(a[l]);
for (i = l + 1; i <= r; ++i) {
while (!stk.empty() && stk[stk.size() - 1].x == a[i].x &&
stk[stk.size() - 1].y == a[i].y)
stk.pop_back();
while (stk.size() > 1) {
if (mult(stk[stk.size() - 2].x, stk[stk.size() - 2].y,
stk[stk.size() - 1].x, stk[stk.size() - 1].y, a[i].x,
a[i].y) > 0)
stk.pop_back();
else
break;
}
a[i].lx = stk[stk.size() - 1].x;
a[i].ly = stk[stk.size() - 1].y;
stk.push_back(a[i]);
}
a[r].rx = a[n].x;
a[r].ry = a[n].y;
stk.clear();
stk.push_back(a[n]);
stk.push_back(a[r]);
for (i = r - 1; i >= l; --i) {
while (!stk.empty() && stk[stk.size() - 1].x == a[i].x &&
stk[stk.size() - 1].y == a[i].y)
stk.pop_back();
while (stk.size() > 1) {
if (mult(stk[stk.size() - 2].x, stk[stk.size() - 2].y,
stk[stk.size() - 1].x, stk[stk.size() - 1].y, a[i].x,
a[i].y) < 0)
stk.pop_back();
else
break;
}
a[i].rx = stk[stk.size() - 1].x;
a[i].ry = stk[stk.size() - 1].y;
stk.push_back(a[i]);
}
for (i = 2; i < n; ++i)
if (mult(a[i].lx, a[i].ly, a[i].x, a[i].y, a[i].rx, a[i].ry) <= 0)
ans.insert(a[i].rk);
}
set<long>::iterator ia;
for (ia = ans.begin(); ia != ans.end(); ++ia) printf("%ld ", *ia);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, tot = 1;
struct data {
int x, y, num;
} a[200005], b[200005];
int s[200005];
int ans[200005];
bool cmp(data p, data q) {
if (p.x == q.x) return p.y < q.y;
return p.x < q.x;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
a[i].num = i;
scanf("%d%d", &a[i].x, &a[i].y);
}
sort(a + 1, a + n + 1, cmp);
int xk = a[n].x, yk = a[n].y;
b[1] = a[n];
for (int i = n - 1; i >= 1; i--) {
if (a[i].y < yk) continue;
if (a[i].y == yk && a[i].x != xk) continue;
yk = a[i].y;
xk = a[i].x;
tot++;
b[tot] = a[i];
}
bool judge = 1;
for (int i = 2; i <= tot; i++)
if (b[i].x != b[i - 1].x) {
judge = 0;
break;
}
if (judge) {
for (int i = 1; i <= tot; i++) ans[i] = b[i].num;
sort(ans + 1, ans + tot + 1);
for (int i = 1; i <= tot; i++) printf("%d ", ans[i]);
return 0;
}
int head = 0;
for (int i = 1; i <= tot; i++) {
if (b[i].x == b[i - 1].x) continue;
if (head < 2) {
head++;
s[head] = i;
continue;
}
while (1) {
if (head == 1) break;
int x = b[i].x, y = b[i].y, x1 = b[s[head]].x, y1 = b[s[head]].y;
int x2 = b[s[head - 1]].x, y2 = b[s[head - 1]].y;
long long now1 = x1 * y1 - x1 * y2 - x * y1 + x * y2;
now1 *= x2 * y;
long long now2 = x2 * y - x1 * y - x2 * y1 + x1 * y1;
now2 *= x * y2;
if (now1 >= now2) break;
head--;
}
head++;
s[head] = i;
}
int totans = 0;
for (int i = 1; i <= head; i++) {
int j = s[i];
while (b[j].x == b[s[i]].x) {
ans[++totans] = b[j].num;
j++;
}
}
sort(ans + 1, ans + totans + 1);
for (int i = 1; i <= totans; i++) printf("%d ", ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7, mul = 1e5;
const int maxn = 200000 + 10;
int dcmp(long double x) {
if (fabsl(x) < eps) return 0;
return x > 0 ? 1 : -1;
}
struct pt {
long double x, y;
bool operator<(const pt &rhs) const {
if (!dcmp(x - rhs.x)) return y < rhs.y;
return x < rhs.x;
}
};
pt operator+(const pt &a, const pt &b) { return (pt){a.x + b.x, a.y + b.y}; }
pt operator-(const pt &a, const pt &b) { return (pt){a.x - b.x, a.y - b.y}; }
pt operator*(const pt &a, const long double &d) {
return (pt){d * a.x, d * a.y};
}
bool operator==(const pt &a, const pt &b) {
return !dcmp(a.x - b.x) && !dcmp(a.y - b.y);
}
long double dot(const pt &a, const pt &b) { return a.x * b.x + a.y * b.y; }
long double cross(const pt &a, const pt &b) { return a.x * b.y - a.y * b.x; }
long double cross(const pt &a, const pt &b, const pt &c) {
return cross(b - a, c - a);
}
pt st[maxn];
void convex_hull(vector<pt> &v, vector<pt> &p) {
p.clear();
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
int n = v.size();
int sz = 0;
for (int i = 0; i < n; i++) {
while (sz >= 2 && dcmp(cross(st[sz - 2], st[sz - 1], v[i])) < 0) sz--;
st[sz++] = v[i];
}
for (int i = 0; i < sz; i++) p.push_back(st[i]);
sz = 0;
for (int i = 0; i < n; i++) {
while (sz >= 2 && dcmp(cross(st[sz - 2], st[sz - 1], v[i]) > 0)) sz--;
st[sz++] = v[i];
}
for (int i = sz - 1; i >= 0; i--) {
if (i == sz - 1 && st[i] == p.back()) continue;
if (i == 0 && st[i] == p[0]) continue;
p.push_back(st[i]);
}
}
vector<pt> a, b;
set<pair<int, int> > ans;
int x[maxn], y[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
a.push_back((pt){mul / x[i], mul / y[i]});
}
convex_hull(a, b);
for (int i = 0; i < b.size(); i++) {
if (i && dcmp(b[i - 1].y - b[i].y) <= 0) break;
int x0 = int(mul / b[i].x + 0.5), y0 = int(mul / b[i].y + 0.5);
ans.insert((pair<int, int>){x0, y0});
}
for (int i = 1; i <= n; i++)
if (ans.count((pair<int, int>){x[i], y[i]})) printf("%d ", i);
printf("\n");
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
struct Node {
double a, b;
int id;
} poi[200200];
bool cmp(Node a, Node b) { return a.a < b.a || a.a == b.a && a.b < b.b; }
int fa[200200];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int sta[200200], top;
Node en[200200];
double sl(Node x, Node y) { return (x.b - y.b) / (x.a - y.a); }
bool book[200200];
int main() {
scanf("%d", &n);
int a, b;
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a, &b);
poi[i].a = 100.00 / a;
poi[i].b = 100.00 / b;
poi[i].id = i;
fa[i] = i;
}
sort(poi + 1, poi + n + 1, cmp);
int tn = n, n = 0;
for (int i = 1; i <= tn; ++i) {
if (poi[i].a == poi[n].a && poi[i].b == poi[n].b) {
fa[find(poi[i].id)] = find(poi[n].id);
continue;
}
if (poi[i].a == poi[n].a) continue;
poi[++n] = poi[i];
}
for (int i = 1; i <= n; ++i) {
if (!top) {
sta[++top] = i;
continue;
}
while (top > 1 &&
sl(poi[i], poi[sta[top - 1]]) < sl(poi[sta[top]], poi[sta[top - 1]]))
top--;
sta[++top] = i;
}
for (int i = 1; i <= top; ++i) en[i] = poi[sta[i]];
book[find(en[1].id)] = 1;
for (int i = 1; i < top; ++i)
if (sl(en[i], en[i + 1]) < 0)
book[find(en[i].id)] = book[find(en[i + 1].id)] = 1;
for (int i = 1; i <= tn; ++i)
if (book[find(i)]) printf("%d ", i);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct point {
ll x, y;
bool operator<(point b) const {
return make_pair(x, y) > make_pair(b.x, b.y);
}
};
int n;
vector<point> a, p;
ll det(point a, point b, point c) {
return (a.x - b.x) * (b.y - c.y) * c.x * a.y -
(b.x - c.x) * (a.y - b.y) * a.x * c.y;
}
vector<point> CH;
void Push(point p) {
while (CH.size() >= 2 && det(*++CH.rbegin(), *CH.rbegin(), p) < 0)
CH.pop_back();
CH.push_back(p);
}
set<point> sol;
void EXEC() {
cin >> n;
for (int i = 0; i < n; ++i) {
int S, R;
cin >> S >> R;
a.push_back({S, R});
}
p = a;
sort(p.begin(), p.end());
for (int i = 0; i < p.size(); ++i)
if (!i || p[i].x != p[i - 1].x) {
Push(p[i]);
}
while (CH.size() >= 2 && CH.rbegin()->y <= (++CH.rbegin())->y) CH.pop_back();
for (auto i : CH) sol.insert(i);
for (int i = 0; i < n; ++i)
if (sol.count(a[i])) printf("%d ", i + 1);
printf("\n");
}
int main() {
EXEC();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
map<pair<int, int>, int> mp;
int n, q[200000 + 5], Ans[200000 + 5], top, flag[200000 + 5];
struct hito {
double a, b;
int id;
} s[200000 + 5];
bool cmp(const hito& x, const hito& y) {
return x.a == y.a ? x.b < y.b : x.a < y.a;
}
inline double Calc(int x, int y) {
return (s[x].b - s[y].b) / (s[x].a - s[y].a);
}
int main() {
n = read();
int num = 0;
for (int i = 1; i <= n; ++i) {
int x = read(), y = read();
if (mp[make_pair(x, y)])
flag[i] = mp[make_pair(x, y)];
else
mp[make_pair(x, y)] = i, s[++num] = (hito){1. / x, 1. / y, i};
}
sort(s + 1, s + num + 1, cmp);
double mn = 1e9;
for (int i = 1; i <= num; ++i)
if (s[i].b < mn) {
while (top > 1 && Calc(q[top], q[top - 1]) > Calc(i, q[top])) --top;
q[++top] = i;
mn = s[i].b;
}
for (int i = 1; i <= top; ++i) Ans[s[q[i]].id] = 1;
for (int i = 1; i <= n; ++i)
if (flag[i] ? Ans[flag[i]] : Ans[i]) printf("%d ", i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
pair<pair<long long, long long>, int> comp[200002], comp2[200002];
long long cross(pair<long long, long long> x, pair<long long, long long> y,
pair<long long, long long> z) {
return (x.first * z.first - y.first * z.first) *
(x.second * y.second - x.second * z.second) -
(x.second * z.second - y.second * z.second) *
(x.first * y.first - x.first * z.first);
}
bool cmp(pair<pair<long long, long long>, int> x,
pair<pair<long long, long long>, int> y) {
return x.first == y.first;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%I64d %I64d", &comp[i].first.first, &comp[i].first.second);
comp[i].second = i;
}
sort(comp, comp + n);
int unik = 1;
comp2[0] = comp[0];
for (int i = 0; i < n - 1; i++) {
if (comp[i].first != comp[i + 1].first) comp2[unik++] = comp[i + 1];
}
vector<int> hull;
for (int i = 0; i < unik; i++) {
while (hull.size() >= 2 &&
cross(comp2[hull[hull.size() - 2]].first, comp2[hull.back()].first,
comp2[i].first) > 0)
hull.pop_back();
hull.push_back(i);
}
vector<int> ans;
while (hull.size() >= 2) {
pair<long long, long long> bef = comp2[hull[hull.size() - 2]].first;
pair<long long, long long> now = comp2[hull.back()].first;
if (bef.second <= now.second) break;
ans.push_back(hull.back());
hull.pop_back();
}
ans.push_back(hull.back());
set<pair<long long, long long> > s;
for (int i = 0; i < ans.size(); i++) s.insert(comp2[ans[i]].first);
vector<int> ans2;
for (int i = 0; i < n; i++)
if (s.count(comp[i].first)) ans2.push_back(comp[i].second);
sort(ans2.begin(), ans2.end());
for (int i = 0; i < ans2.size(); i++) printf("%d ", ans2[i] + 1);
printf("\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
struct Point {
long long x, y;
bool operator<(const Point &p) const {
if (x != p.x)
return x > p.x;
else
return y > p.y;
}
} 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++) {
while (stnum > 1 && check(pt[stk[stnum - 1]], pt[stk[stnum - 2]], pt[i]))
stnum--;
stk[stnum++] = i;
while (stnum > 1 && pt[stk[stnum - 1]].y <= pt[stk[stnum - 2]].y) stnum--;
}
while (stnum > 1 && pt[stk[stnum - 1]].y <= pt[stk[stnum - 2]].y) stnum--;
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;
struct people {
long long a, b, id;
} p[300010];
long long n, s[300010], t;
bool v[300010], ans[300010];
bool cmp(people a, people b) { return a.a == b.a ? a.b > b.b : a.a > b.a; }
long double check(people a, people b) {
return (long double)a.a * b.a * (b.b - a.b) / (b.a - a.a) / b.b / a.b;
}
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) scanf("%lld%lld", &p[i].a, &p[i].b), p[i].id = i;
sort(p + 1, p + n + 1, cmp);
s[1] = 1, t = 1;
long long maxb = p[1].b;
for (int i = 2; i <= n; i++)
if (p[i].b <= maxb)
v[i] = 1;
else
maxb = p[i].b;
for (int i = 2; i <= n; i++) {
if (v[i] || check(p[i], p[s[t]]) > 0) continue;
while (t > 1 && check(p[i], p[s[t]]) < check(p[s[t - 1]], p[s[t]])) t--;
s[++t] = i;
}
for (int i = 1; i <= t; i++) {
ans[p[s[i]].id] = 1;
for (int j = s[i] + 1; j <= n && p[s[i]].a == p[j].a && p[s[i]].b == p[j].b;
j++)
ans[p[j].id] = 1;
}
for (int i = 1; i <= n; i++)
if (ans[i]) printf("%d ", i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double A = 1e4;
const double eps = 1e-12;
bool eq(double x, double y) { return fabs(x - y) < eps; }
bool ls(double x, double y) { return x < y && !eq(x, y); }
bool lseq(double x, double y) { return x < y || eq(x, y); }
struct Point {
int idx;
double x, y;
Point() : idx(), x(), y() {}
Point(double _x, double _y) : idx(-1), x(_x), y(_y) {}
void scan(int i) {
idx = i;
scanf("%lf%lf", &x, &y);
x = A / x;
y = A / y;
}
Point operator+(Point a) { return Point(x + a.x, y + a.y); }
Point operator-(Point a) const { return Point(x - a.x, y - a.y); }
Point operator*(double k) { return Point(x * k, y * k); }
Point operator/(double k) { return Point(x / k, y / k); }
double operator%(Point a) { return x * a.x + y * a.y; }
double operator*(Point a) { return x * a.y - y * a.x; }
double sqLen() { return *this % *this; }
bool operator<(const Point &a) const {
if (!eq(x, a.x)) return x < a.x;
return ls(y, a.y);
}
bool operator==(const Point &a) const { return eq(x, a.x) && eq(y, a.y); }
};
const int N = (int)2e5 + 200;
int n, oldn;
Point a[N];
Point minP;
bool ans[N];
int ans2[N];
bool cmp(const Point &a, const Point &b) {
Point v = a - minP;
Point u = b - minP;
double x = v * u;
if (!eq(x, 0)) return x > 0;
return ls(v.sqLen(), u.sqLen());
}
void solve() {
minP = a[0];
for (int i = 0; i < n; i++)
if (a[i] < minP) minP = a[i];
sort(a, a + n, cmp);
Point h[N];
int sz = 1;
h[0] = a[0];
for (int i = 1; i < n; i++) {
while (sz >= 2 && ls(0, (a[i] - h[sz - 1]) * (h[sz - 1] - h[sz - 2]))) sz--;
h[sz++] = a[i];
}
int idx = 1;
while (idx < sz && ls((h[idx] - h[idx - 1]).y, 0)) idx++;
for (int i = 0; i < idx; i++) ans[h[i].idx] = 1;
for (int i = 1; i <= oldn; i++)
if (ans[i] || (ans2[i] != -1 && ans[ans2[i]])) printf("%d ", i);
printf("\n");
return;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) a[i].scan(i + 1);
sort(a, a + n);
ans2[a[0].idx] = -1;
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
int p = a[i - 1].idx;
if (ans2[p] == -1)
ans2[a[i].idx] = p;
else
ans2[a[i].idx] = ans2[p];
} else
ans2[a[i].idx] = -1;
}
oldn = n;
n = unique(a, a + n) - a;
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
map<pair<long long int, long long int>, vector<int> > M;
vector<pair<long long int, long long int> > A;
pair<long long int, long long int> lower_left;
bool ans[MAXN];
bool sorter1(const pair<long long int, long long int> &x,
const pair<long long int, long long int> &y) {
return (x > y);
}
bool sorter2(const pair<long long int, long long int> &x,
const pair<long long int, long long int> &y) {
long long int num1 = (lower_left.first - x.first) * x.second * y.first *
(lower_left.second - y.second);
long long int num2 = x.first * (lower_left.second - x.second) *
(lower_left.first - y.first) * y.second;
if (num1 != num2)
return num1 > num2;
else
return (x > y);
}
vector<pair<long long int, long long int> > find_hull(
vector<pair<long long int, long long int> > &A) {
sort(A.begin(), A.end(), sorter1);
lower_left = A[0];
sort(A.begin() + 1, A.end(), sorter2);
if (A.size() < 3) return A;
vector<pair<long long int, long long int> > ans(A.begin(), A.begin() + 2);
int sz = 2;
for (int i = 2; i < A.size(); ++i) {
lower_left = ans[sz - 2];
while (sz >= 2 && sorter2(A[i], ans[sz - 1])) {
ans.pop_back();
sz--;
if (sz >= 2) lower_left = ans[sz - 2];
}
ans.push_back(A[i]);
sz++;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
pair<long long int, long long int> temp;
for (int i = 0; i < n; ++i) {
cin >> temp.first >> temp.second;
M[temp].push_back(i);
}
for (map<pair<long long int, long long int>, vector<int> >::iterator it =
M.begin();
it != M.end(); ++it)
A.push_back(it->first);
A = find_hull(A);
lower_left = A[0];
for (int i = 0; i < M[lower_left].size(); ++i) {
ans[M[lower_left][i]] = true;
}
for (int i = 1; i < A.size(); ++i) {
if (A[i].second > A[i - 1].second) {
for (int j = 0; j < M[A[i]].size(); ++j) {
ans[M[A[i]][j]] = true;
}
} else
break;
}
for (int i = 0; i < n; ++i) {
if (ans[i]) cout << i + 1 << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
inline int cmp(double a, double b) {
return (a < b - EPS) ? -1 : ((a > b + EPS) ? 1 : 0);
}
struct Point {
double x, y;
int id;
Point(double x = 0.0, double y = 0.0, int id = 0) : x(x), y(y), id(id) {}
Point operator+(Point a) { return Point(x + a.x, y + a.y); }
Point operator-(Point a) { return Point(x - a.x, y - a.y); }
Point operator*(double k) { return Point(x * k, y * k); }
Point operator/(double k) { return Point(x / k, y / k); }
double operator*(Point a) { return x * a.x + y * a.y; }
double operator%(Point a) { return x * a.y - y * a.x; }
int cmp(Point q) const {
if (int t = ::cmp(x, q.x)) return t;
return ::cmp(y, q.y);
}
bool operator>(Point q) const { return cmp(q) > 0; }
bool operator<(Point q) const { return cmp(q) < 0; }
bool operator==(Point q) const { return cmp(q) == 0; }
bool operator>=(Point q) const { return cmp(q) >= 0; }
bool operator<=(Point q) const { return cmp(q) <= 0; }
bool operator!=(Point q) const { return cmp(q) != 0; }
Point conj() { return Point(x, -y); }
double norm() { return x * x + y * y; }
double len() { return sqrt(norm()); }
Point rotate(double alpha) {
double cosa = cos(alpha), sina = sin(alpha);
return Point(x * cosa - y * sina, x * sina + y * cosa);
}
};
double area2(Point a, Point b, Point c) { return a % b + b % c + c % a; }
int ccw(Point a, Point b, Point c) { return cmp((b - a) % (c - a), 0); }
void ConvexHull(vector<Point> &pts) {
sort(pts.begin(), pts.end());
pts.erase(unique(pts.begin(), pts.end()), pts.end());
vector<Point> up, dn;
for (int i = 0; i < pts.size(); i++) {
while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) >= 0)
up.pop_back();
while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) <= 0)
dn.pop_back();
up.push_back(pts[i]);
dn.push_back(pts[i]);
}
pts = dn;
for (int i = (int)up.size() - 2; i >= 1; i--) pts.push_back(up[i]);
}
int bit[10111];
const int MN = 200111;
bool can[MN];
void update(int u, int val) {
while (u <= 10000) {
bit[u] = max(bit[u], val);
u += ((u) & (-(u)));
}
}
int get(int u) {
int res = 0;
while (u > 0) {
res = max(res, bit[u]);
u -= ((u) & (-(u)));
}
return res;
}
pair<int, int> input[MN];
int main() {
ios ::sync_with_stdio(false);
int n;
while (scanf("%d", &n) == 1) {
vector<Point> a;
memset(bit, 0, sizeof bit);
for (int i = (1), _b = (n); i <= _b; i++) {
int x, y;
scanf("%d%d", &x, &y);
a.push_back(Point(1.0 / x, 1.0 / y, i));
input[i] = make_pair(10001 - x, y);
update(input[i].first, input[i].second);
}
for (int i = (1), _b = (n); i <= _b; i++) {
if (get(input[i].first - 1) >= input[i].second)
can[i] = false;
else if (get(input[i].first) > input[i].second)
can[i] = false;
else
can[i] = true;
}
ConvexHull(a);
set<int> res;
int sz = a.size();
Point O(0, 0, 0);
for (int i = 0, _a = (sz); i < _a; i++) {
Point y = a[i];
Point x = a[(i - 1 + sz) % sz];
Point xx = a[(i - 2 + sz + sz) % sz];
Point z = a[(i + 1) % sz];
Point zz = a[(i + 2) % sz];
if (ccw(x, y, z) * ccw(x, y, O) <= 0 && ccw(x, y, xx) * ccw(x, y, O) <= 0)
res.insert(a[i].id);
if (ccw(y, z, x) * ccw(y, z, O) <= 0 && ccw(y, z, zz) * ccw(y, z, O) <= 0)
res.insert(a[i].id);
}
set<pair<int, int> > all;
for (int x : res)
if (can[x]) all.insert(input[x]);
for (int i = (1), _b = (n); i <= _b; i++)
if (all.count(input[i])) cout << i << ' ';
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, int> mp;
int n, top, q[200010], tt;
long long mx;
struct Vec {
long long x0, x1, y0, y1;
int id;
} a[200010];
inline int Read() {
char c = getchar();
int num = 0;
while ('0' > c || c > '9') c = getchar();
while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
return (num);
}
bool Cmp(Vec a, Vec b) {
return ((a.x1 > b.x1) || (a.x1 == b.x1 && a.y1 > b.y1));
}
long double operator*(Vec a, Vec b) {
return ((long double)a.x0 * b.y0 * a.y1 * b.x1 -
(long double)a.y0 * b.x0 * a.x1 * b.y1);
}
Vec operator-(Vec a, Vec b) {
return ((Vec){a.x0 * b.x1 - a.x1 * b.x0, a.x1 * b.x1,
a.y0 * b.y1 - a.y1 * b.y0, a.y1 * b.y1});
}
int main() {
n = Read();
for (int i = 1; i <= n; i++)
a[i].x0 = a[i].y0 = 1, a[i].x1 = Read(), a[i].y1 = Read(), a[i].id = i;
sort(a + 1, a + 1 + n, Cmp);
q[top = 1] = 1;
for (int i = 2; i <= n; i++)
if (a[i].x1 != a[i - 1].x1) {
while (top > 1 && (a[i] - a[q[top]]) * (a[q[top]] - a[q[top - 1]]) > 1e-7)
top--;
q[++top] = i;
}
for (int i = 1; i <= top; i++)
if (a[q[i]].y1 > mx) tt = i, mx = a[q[i]].y1;
top = tt;
for (int i = 1; i <= top; i++) mp[make_pair(a[q[i]].x1, a[q[i]].y1)] = 1;
top = 0;
for (int i = 1; i <= n; i++)
if (mp[make_pair(a[i].x1, a[i].y1)]) q[++top] = a[i].id;
sort(q + 1, q + 1 + top);
for (int i = 1; i <= top; i++) printf("%d ", q[i]);
puts("");
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
struct Node {
double a, b;
int id;
} poi[200200];
bool cmp(Node a, Node b) { return a.a < b.a || a.a == b.a && a.b < b.b; }
int fa[200200];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int sta[200200], top;
Node en[200200];
double sl(Node x, Node y) { return (x.b - y.b) / (x.a - y.a); }
bool book[200200];
int main() {
scanf("%d", &n);
int a, b;
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a, &b);
poi[i].a = 100.00 / a;
poi[i].b = 100.00 / b;
poi[i].id = i;
fa[i] = i;
}
sort(poi + 1, poi + n + 1, cmp);
int tn = n, n = 0;
for (int i = 1; i <= tn; ++i) {
if (poi[i].a == poi[n].a && poi[i].b == poi[n].b) {
fa[find(poi[i].id)] = find(poi[n].id);
continue;
}
if (poi[i].a == poi[n].a) continue;
poi[++n] = poi[i];
}
for (int i = 1; i <= n; ++i) {
if (!top) {
sta[++top] = i;
continue;
}
while (top > 1 &&
sl(poi[i], poi[sta[top - 1]]) < sl(poi[sta[top]], poi[sta[top - 1]]))
top--;
sta[++top] = i;
}
for (int i = 1; i <= top; ++i) {
en[i] = poi[sta[i]];
}
book[find(en[1].id)] = 1;
for (int i = 1; i < top; ++i)
if (sl(en[i], en[i + 1]) < 0) {
book[find(en[i].id)] = book[find(en[i + 1].id)] = 1;
}
for (int i = 1; i <= tn; ++i)
if (book[find(i)]) printf("%d ", i);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200010;
const double INF = 1e15;
const double EPS = 1e-16;
int sig(double x) { return (x < -EPS) ? -1 : (x > EPS) ? 1 : 0; }
bool cmp(double x) { return x < 0 || fabs(x) < EPS; }
struct Point {
double x, y;
int id;
Point(double x = 0, double y = 0) : x(x), y(y) { id = 0; }
};
Point operator+(const Point a, const Point b) {
return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point a, const Point b) {
return Point(a.x - b.x, a.y - b.y);
}
double operator*(const Point a, const Point b) { return a.x * b.y - a.y * b.x; }
double operator^(const Point a, const Point b) { return a.x * b.x + a.y * b.y; }
Point operator*(const Point a, const double x) {
return Point(a.x * x, a.y * x);
}
Point operator/(const Point a, const double x) {
return Point(a.x / x, a.y / x);
}
bool operator==(const Point a, const Point b) {
return (fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS);
}
bool operator<(const Point a, const Point b) {
return a.x < b.x || (fabs(a.x - b.x) < EPS && a.y < b.y);
}
double cross(const Point &a, const Point &b) { return (a.x * b.y - a.y * b.x); }
double dot(const Point &a, const Point &b) { return (a.x * b.x + a.y * b.y); }
double dis2(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int N;
Point p[maxN], stk[maxN];
int pos[maxN];
bool ans[maxN];
int cnt;
bool compare1(const Point a, const Point b) {
double dir = cross((a - stk[1]), (b - stk[1]));
if (sig(dir) == 0) return dis2(a, stk[1]) < dis2(b, stk[1]);
return dir > 0;
}
int compare(Point x, Point y) { return (x - stk[1]) * (y - stk[1]) > 0; }
int MakeHull(Point *ps, int n) {
int cnt;
sort(ps, ps + n);
cnt = 0;
for (int i = 0; i < n; i++) {
if (i > 0 && p[i] == p[i - 1]) {
pos[i] = pos[i - 1];
continue;
}
pos[i] = i;
while (cnt > 1 && cmp(cross(stk[cnt - 1] - stk[cnt - 2],
ps[i] - stk[cnt - 2])) == true)
cnt--;
stk[cnt++] = ps[i];
}
int k = cnt;
for (int i = n - 2; i >= 0; i--) {
while (cnt > k && cmp(cross(stk[cnt - 1] - stk[cnt - 2],
ps[i] - stk[cnt - 2]) == true))
cnt--;
stk[cnt++] = ps[i];
}
if (n > 1) cnt--;
return cnt;
}
int main() {
double s, r;
double minix = INF;
double miniy = INF;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%lf%lf", &s, &r);
p[i].x = 1000000 / s;
p[i].y = 1000000 / r;
p[i].id = i;
miniy = min(miniy, p[i].y);
minix = min(minix, p[i].x);
}
int tot = MakeHull(p, N);
for (int i = 0; i < tot; i++) {
ans[stk[i].id] = true;
if (fabs(stk[i].y - miniy) < EPS) break;
}
for (int i = 0; i < N; i++) {
if (ans[p[pos[i]].id] == true) ans[p[i].id] = true;
}
for (int i = 0; i < N; i++)
if (ans[i] == true) printf("%d ", i + 1);
printf("\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct pt {
long double x, y;
basic_string<int> id;
bool operator<(pt b) const {
if (x != b.x) return x < b.x;
return y < b.y;
}
};
bool ispod(pt a, pt b) { return a.x <= b.x && a.y <= b.y; }
long double det(pt a, pt b, pt c) {
return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;
}
int n, nn, m, h;
pt a[200005], b[200005], c[200005];
map<pair<int, int>, int> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
if (mp.count({x, y}))
a[mp[{x, y}]].id += i;
else {
a[nn].x = (long double)1 / x;
a[nn].y = (long double)1 / y;
a[nn].id = {i};
mp[{x, y}] = nn;
nn++;
}
}
sort(a, a + nn);
for (int i = 0; i < nn; i++) {
while (h >= 2 && det(c[h - 2], c[h - 1], a[i]) < -1e-16) h--;
c[h++] = a[i];
}
{
basic_string<int> sol;
for (int i = 0; i < h; i++) sol += c[i].id;
sort(sol.begin(), sol.end());
for (int x : sol) cerr << x << ' ';
cerr << '\n';
}
while (h >= 2 && ispod(c[h - 2], c[h - 1])) h--;
basic_string<int> sol;
for (int i = 0; i < h; i++) sol += c[i].id;
sort(sol.begin(), sol.end());
for (int x : sol) cout << x << ' ';
cout << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
struct D {
int v1;
int v2;
vector<int> *i;
bool operator<(const D &b) const {
if (v1 != b.v1) return v1 < b.v1;
return v2 < b.v2;
}
} inp[1000010];
map<D, int> rev;
vector<int> ans;
vector<int> anp;
long long cross(long long a, long long b, long long c, long long d) {
return a * d - b * c;
}
int main() {
scanf("%d", &n);
int s = 0;
for (int i = 0; i < n; i++) {
scanf("%d%d", &inp[s].v1, &inp[s].v2);
if (rev.count(inp[s])) {
inp[rev[inp[s]]].i->push_back(i);
} else {
inp[s].i = new vector<int>();
inp[s].i->push_back(i);
rev[inp[s]] = s;
s++;
}
}
sort(inp, inp + s);
int maa = -1;
for (int i = s - 1; i >= 0; i--) {
if (inp[i].v2 > maa) {
maa = inp[i].v2;
if (ans.size() < 2)
ans.push_back(i);
else {
while (ans.size() >= 2) {
D &p1 = inp[ans.back()], &p2 = inp[ans[ans.size() - 2]];
if ((long long)inp[i].v1 * p2.v2 * (p2.v1 - p1.v1) *
(inp[i].v2 - p1.v2) -
(long long)inp[i].v2 * p2.v1 * (p2.v2 - p1.v2) *
(inp[i].v1 - p1.v1) <=
0)
break;
ans.pop_back();
}
ans.push_back(i);
}
}
}
for (int i = 0; i < ans.size(); i++) {
for (int j = 0; j < inp[ans[i]].i->size(); j++)
anp.push_back((*inp[ans[i]].i)[j]);
}
sort(anp.begin(), anp.end());
for (int i = 0; i < anp.size(); i++) {
printf("%d%c", anp[i] + 1, " \n"[i == anp.size() - 1]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
int id;
Point() {}
Point(double x, double y) {
this->x = x;
this->y = y;
}
void read(int id) {
int s, b;
scanf("%d%d", &s, &b);
x = 1000000.0 / s;
y = 1000000.0 / b;
this->id = id;
}
};
const double eps = 1e-16;
int dcmp(double x) {
if (fabs(x) < eps)
return 0;
else
return x < 0 ? -1 : 1;
}
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); }
Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); }
bool operator<(const Point& a, const Point& b) {
return a.x < b.x || (dcmp(a.x - b.x) == 0 && a.y < b.y);
}
bool operator==(const Point& a, const Point& b) {
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }
double Length(Point A) { return sqrt(Dot(A, A)); }
double Angle(Point A, Point B) {
return acos(Dot(A, B) / Length(A) / Length(B));
}
double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }
double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); }
struct Line {
Point v, p;
Line() {}
Line(Point v, Point p) {
this->v = v;
this->p = p;
}
Point point(double t) { return v + p * t; }
};
Point Rotate(Point A, double rad) {
return Point(A.x * cos(rad) - A.y * sin(rad),
A.x * sin(rad) + A.y * cos(rad));
}
Point AngleBisector(Point p, Point v1, Point v2) {
double rad = Angle(v1, v2);
return Rotate(v1, dcmp(Cross(v1, v2)) * 0.5 * rad);
}
bool LineCoincide(Point p1, Point p2, Point p3) {
return dcmp(Cross(p2 - p1, p3 - p1)) == 0;
}
bool LineParallel(Point v, Point w) { return Cross(v, w) == 0; }
bool LineVertical(Point v, Point w) { return Dot(v, w) == 0; }
Point GetLineIntersection(Point P, Point v, Point Q, Point w) {
Point u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
}
double DistanceToLine(Point P, Point A, Point B) {
Point v1 = B - A, v2 = P - A;
return fabs(Cross(v1, v2)) / Length(v1);
}
double DistanceToSegment(Point P, Point A, Point B) {
if (A == B) return Length(P - A);
Point v1 = B - A, v2 = P - A, v3 = P - B;
if (dcmp(Dot(v1, v2)) < 0)
return Length(v2);
else if (dcmp(Dot(v1, v3)) > 0)
return Length(v3);
else
return fabs(Cross(v1, v2)) / Length(v1);
}
Point GetLineProjection(Point P, Point A, Point B) {
Point v = B - A;
return A + v * (Dot(v, P - A) / Dot(v, v));
}
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
bool SegmentProperIntersection2(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return max(a1.x, a2.x) >= min(b1.x, b2.x) &&
max(b1.x, b2.x) >= min(a1.x, a2.x) &&
max(a1.y, a2.y) >= min(b1.y, b2.y) &&
max(b1.y, b2.y) >= min(a1.y, a2.y) && dcmp(c1) * dcmp(c2) <= 0 &&
dcmp(c3) * dcmp(c4) <= 0;
}
bool OnSegment(Point p, Point a1, Point a2) {
return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
}
double PolygonArea(Point* p, int n) {
double area = 0;
for (int i = 1; i < n - 1; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
int isPointInPolygon(Point o, Point* p, int n) {
int wn = 0;
for (int i = 0; i < n; i++) {
if (OnSegment(o, p[i], p[(i + 1) % n])) return -1;
int k = dcmp(Cross(p[(i + 1) % n] - p[i], o - p[i]));
int d1 = dcmp(p[i].y - o.y);
int d2 = dcmp(p[(i + 1) % n].y - o.y);
if (k > 0 && d1 <= 0 && d2 > 0) wn++;
if (k < 0 && d2 <= 0 && d1 > 0) wn--;
}
if (wn != 0) return 1;
return 0;
}
const int N = 200005;
int to[N];
int ConvexHull(Point* p, int n, Point* ch) {
sort(p, p + n);
int m = 0;
memset(to, -1, sizeof(to));
for (int i = 0; i < n; i++) {
to[i] = i;
if (i && p[i] == p[i - 1]) {
to[i] = to[i - 1];
continue;
}
while (m > 1 && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0)
m--;
ch[m++] = p[i];
}
int k = m;
for (int i = n - 2; i >= 0; i--) {
while (m > k && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0)
m--;
ch[m++] = p[i];
}
if (n > 1) m--;
return m;
}
int n;
Point p[N], ch[N];
int vis[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) p[i].read(i + 1);
int m = ConvexHull(p, n, ch);
double Min = 1e18;
for (int i = 0; i < m; i++) Min = min(Min, ch[i].y);
for (int i = 0; i < m; i++) {
vis[ch[i].id] = 1;
if (dcmp(Min - ch[i].y) == 0) break;
}
for (int i = 0; i < n; i++)
if (vis[p[to[i]].id]) vis[p[i].id] = 1;
for (int i = 1; i <= n; i++)
if (vis[i]) printf("%d ", i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, dummy;
long long cmp(pair<int, int> p, pair<int, int> a, pair<int, int> b) {
return (long long)a.second * b.first * (p.first - a.first) *
(p.second - b.second) -
(long long)a.first * b.second * (p.second - a.second) *
(p.first - b.first);
}
int main() {
ios::sync_with_stdio(false);
cin >> N;
vector<pair<int, int> > input(N);
for (int i = 0; i < (N); ++i) cin >> input[i].first >> input[i].second;
vector<pair<int, int> > points(input);
sort((points).begin(), (points).end());
vector<pair<int, int> > ret1, ret2;
for (int i = 0; i < (N); ++i) {
while (((int)(ret1).size()) && ret1.back().second <= points[i].second)
ret1.pop_back();
ret1.push_back(points[i]);
}
for (int i = 0; i < (((int)(ret1).size())); ++i) {
while (((int)(ret2).size()) > 1 &&
cmp(ret2[((int)(ret2).size()) - 2], ret2.back(), ret1[i]) > 0)
ret2.pop_back();
ret2.push_back(ret1[i]);
}
set<pair<int, int> > pset((ret2).begin(), (ret2).end());
for (int i = 0; i < N; i++)
if (pset.count(input[i])) cout << i + 1 << " ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct point {
int X, Y;
double x, y;
point() { X = Y = x = y = .0; }
point(double a, double b) { x = a, y = b; }
inline void init(int a, int b) {
X = a, Y = b;
x = 1.0 / X;
y = 1.0 / Y;
}
inline double operator*(point p) { return x * p.y - y * p.x; }
inline point operator-(point p) { return point(x - p.x, y - p.y); }
inline double dis(point p) {
return ((x - p.x) * (x - p.x)) + ((y - p.y) * (y - p.y));
}
inline pair<int, int> PII() { return pair<int, int>(X, Y); }
};
point o;
point l;
inline bool ocmp(const point &a, const point &b) {
return make_pair(a.y, a.x) < make_pair(b.y, b.x);
}
inline bool lcmp(const point &a, const point &b) {
return make_pair(a.x, a.y) < make_pair(b.x, b.y);
}
inline bool scmp(const point &a, const point &b) {
double cross = ((point)a - o) * ((point)b - o);
if (fabs(cross) <= 1e-18) return o.dis(a) < o.dis(b);
return cross < 1e-18;
}
vector<point> v;
vector<point> hull;
map<pair<int, int>, vector<int>> indx;
void CH() {
o = *min_element(v.begin(), v.end(), ocmp);
l = *min_element(v.begin(), v.end(), lcmp);
if (o.PII() == l.PII()) {
for (int p : indx[o.PII()]) {
cout << p << " ";
}
cout << endl;
return;
}
sort(v.begin(), v.end(), scmp);
if ((int)v.size() == 1) {
hull.push_back(v.front());
return;
}
for (int i = 0; i < 2; i++) hull.push_back(v[i]);
int po = 2;
while (po < (int)v.size() && hull.back().PII() != l.PII()) {
while (hull.size() > 1 && (hull[hull.size() - 1] - hull[hull.size() - 2]) *
(v[po] - hull[hull.size() - 2]) >
1e-18)
hull.pop_back();
hull.push_back(v[po++]);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
indx[make_pair(x, y)].push_back(i + 1);
}
if ((int)indx.size() == 1) {
for (auto p : indx) {
for (int x : p.second) cout << x << " ";
cout << endl;
}
return 0;
}
for (auto p : indx) {
int x = p.first.first;
int y = p.first.second;
point P;
P.init(x, y);
v.push_back(P);
}
CH();
vector<int> ans;
for (point p : hull) {
for (int x : indx[p.PII()]) {
ans.push_back(x);
}
}
sort(ans.begin(), ans.end());
for (int x : ans) cout << x << " ";
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
pair<pair<long long, long long>, int> comp[200002];
bool cross(pair<long long, long long> a, pair<long long, long long> b,
pair<long long, long long> c) {
return (a.second * b.second - a.second * c.second) *
(b.first * c.first - a.first * c.first) <
(a.second * c.second - b.second * c.second) *
(a.first * c.first - a.first * b.first) ||
c.second >= b.second;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%I64d %I64d", &comp[i].first.first, &comp[i].first.second);
comp[i].second = i;
}
comp[n] = make_pair(make_pair(0, 0), n);
sort(comp, comp + n);
vector<int> hull;
for (int i = 0; i < n; i++) {
while (hull.size() >= 2 && cross(comp[hull[hull.size() - 2]].first,
comp[hull.back()].first, comp[i].first))
hull.pop_back();
hull.push_back(i);
}
vector<pair<long long, long long> > ans;
while (hull.size() >= 2) {
pair<long long, long long> bef = comp[hull[hull.size() - 2]].first;
pair<long long, long long> now = comp[hull.back()].first;
if (bef.second <= now.second && bef != now) break;
ans.push_back(comp[hull.back()].first);
hull.pop_back();
}
ans.push_back(comp[hull.back()].first);
set<pair<long long, long long> > super;
while (!ans.empty()) {
super.insert(ans.back());
ans.pop_back();
}
vector<int> tans;
for (int i = 0; i < n; i++) {
if (super.find(comp[i].first) != super.end()) {
tans.push_back(comp[i].second);
}
}
sort(tans.begin(), tans.end());
for (int i = 0; i < tans.size(); i++) printf("%d ", tans[i] + 1);
printf("\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e4 + 100;
const double E = 0.0000000001;
struct {
double r;
vector<int> index;
;
} compet[MN];
int ans[MN];
int ansPos = 0;
double lo[MN];
double hi[MN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < MN; ++i) {
compet[i].r = 0;
hi[i] = 1;
}
for (int i = 0; i < n; ++i) {
int s, r;
scanf("%d %d", &s, &r);
if (compet[s].r == (double)r) {
compet[s].index.push_back(i + 1);
} else if (compet[s].r < r) {
compet[s].r = r;
compet[s].index.clear();
compet[s].index.push_back(i + 1);
}
}
for (int i = 0; i < MN; ++i) {
if (compet[i].index.size() == 0) continue;
double q = 1 / compet[i].r;
double w = 1 / (double)i - 1 / compet[i].r;
double qq, ww;
for (int j = i + 1; j < MN; ++j) {
if (compet[j].index.size() == 0) continue;
qq = q - 1 / compet[j].r;
ww = w - 1 / (double)j + 1 / compet[j].r;
if (abs(ww) < E) {
if (qq > 0) {
hi[i] = -1;
} else {
hi[j] = -1;
}
} else {
qq /= -ww;
if (ww > 0) {
hi[i] = min(hi[i], qq);
lo[j] = max(lo[j], qq);
} else {
lo[i] = max(lo[i], qq);
hi[j] = min(hi[j], qq);
}
}
}
if (hi[i] > lo[i] + E ||
(abs(hi[i] - lo[i]) < E && lo[i] > 0 && lo[i] < 1)) {
for (int x : compet[i].index) {
ans[ansPos++] = x;
}
}
}
sort(ans, ans + ansPos);
for (int i = 0; i < ansPos; ++i) {
printf("%d ", ans[i]);
}
printf("\n");
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
pair<int, int> p[MAX];
vector<pair<int, int> > v;
int a[MAX], b[MAX];
pair<long long, long long> intersect(pair<int, int> a, pair<int, int> b) {
return make_pair(a.first * (b.second - a.second),
a.second * (b.first - a.first));
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.first * b.second < a.second * b.first);
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int tn = n;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
a[i] = p[i].first;
b[i] = p[i].second;
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
while (!v.empty() && v.back().second <= p[i].second) v.pop_back();
v.push_back(p[i]);
}
n = v.size();
for (int i = 0; i < n; i++) p[i] = v[i];
v.clear();
for (int i = 0; i < n; i++) {
while (v.size() > 1 &&
cmp(intersect(p[i], v.back()), intersect(v[v.size() - 2], v.back())))
v.pop_back();
v.push_back(p[i]);
}
set<pair<int, int> > s;
for (int i = 0; i < v.size(); i++) s.insert(v[i]);
vector<int> ans;
for (int i = 0; i < tn; i++)
if (s.count(make_pair(a[i], b[i]))) ans.push_back(i + 1);
for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string minEquivalent(string s) {
if (s.length() % 2) return s;
string s1 = minEquivalent(s.substr(0, s.length() / 2));
string s2 = minEquivalent(s.substr(s.length() / 2, s.length() / 2));
if (s1 < s2)
return s1 + s2;
else
return s2 + s1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string a, b;
cin >> a >> b;
if (minEquivalent(a) == minEquivalent(b)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool havasar(string ::iterator s1, int n, string::iterator s2, int m) {
if (n != m) return 0;
if (n == 1) return (*s1) == (*s2);
bool mark = true;
string::iterator s3 = s1, s4 = s2;
for (int i = 0; i < n; i++) {
if ((*s1) != (*s2)) {
mark = false;
break;
}
s1++;
s2++;
}
s1 = s3;
s2 = s4;
if (mark) return true;
if (n % 2 == 1) return false;
int tn = n / 2;
int tm = m / 2;
int kn = n - tn;
int km = m - tm;
return ((havasar(s1, tn, s2, tm) && havasar(s1 + tn, kn, s2 + tm, km)) ||
(havasar(s1, tn, s2 + tm, km) && havasar(s1 + tn, kn, s2, tm)));
}
int main() {
string s1, s2;
cin >> s1 >> s2;
cout << (havasar(s1.begin(), s1.size(), s2.begin(), s2.size()) ? "YES" : "NO")
<< endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int sdf = 0;
bool equi(string a, string b) {
int l = a.size();
if (l % 2 == 1) return a == b;
if (a == b)
return 1;
else
return (equi(a.substr(0, l / 2), b.substr(l / 2, l / 2)) &&
equi(b.substr(0, l / 2), a.substr(l / 2, l / 2))) ||
(equi(a.substr(0, l / 2), b.substr(0, l / 2)) &&
equi(b.substr(l / 2, l / 2), a.substr(l / 2, l / 2)));
}
int main() {
string a, b;
cin >> a >> b;
if (equi(a, b))
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
long long p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
char a[200010], b[200010];
int isEq(char* x, char* y, int l) {
if (l & 1) {
return strncmp(x, y, l) == 0;
}
l >>= 1;
return (isEq(x, y, l) && isEq(x + l, y + l, l)) ||
(isEq(x + l, y, l) && isEq(x, y + l, l));
}
int main() {
ios_base::sync_with_stdio(false);
scanf("%s\n%s", a, b);
puts(isEq(a, b, strlen(a)) ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
bool check(string x, string y) {
if (x == y) return true;
if (x.size() % 2 == 1) return x == y;
string c1 = "", c2 = "";
for (int i = 0; i < (x.size() / 2); i++) {
c1 += x[i];
c2 += y[i + x.size() / 2];
}
string c3, c4;
for (int i = 0; i < (x.size() / 2); i++) {
c4 += y[i];
c3 += x[i + x.size() / 2];
}
if (check(c1, c2) && check(c3, c4) || check(c1, c4) && check(c2, c3))
return true;
return false;
}
int main() {
cin >> a >> b;
if (check(a, b))
puts("YES");
else
puts("NO");
}
|
#include <bits/stdc++.h>
using namespace std;
long long MO[] = {1000000007, 1000000009, 1000000007};
long long PR[] = {137, 173, 17};
long long PO[1][200005];
long long HA[1][200005][2];
string a, b;
void init() {
PO[0][0] = 1;
for (int h = 0; h < 1; ++h) {
for (int i = 0; i < a.size(); ++i) {
if (i) PO[h][i] = (PO[h][i - 1] * PR[h]) % MO[h];
if (i) {
HA[h][i][0] = ((HA[h][i - 1][0] * PR[h]) + a[i]) % MO[h];
HA[h][i][1] = ((HA[h][i - 1][1] * PR[h]) + b[i]) % MO[h];
} else {
HA[h][i][0] = a[i];
HA[h][i][1] = b[i];
}
}
}
}
long long getHash(int hId, int l, int r, int k) {
long long ret = HA[hId][r][k];
if (l == 0) return ret;
ret = (ret - (HA[hId][l - 1][k] * PO[hId][(r - l + 1)])) % MO[hId];
ret = (ret + MO[hId]) % MO[hId];
return ret;
}
bool same(int l, int r, int l2, int r2) {
for (int i = 0; i < 1; i++) {
if (getHash(i, l, r, 0) != getHash(i, l2, r2, 1)) return false;
}
return true;
}
bool solve(int a1, int a2, int b1, int b2) {
if (same(a1, a2, b1, b2)) return true;
if ((a2 - a1 + 1) & 1) return false;
int midpoint_a = (a2 + a1) / 2;
int midpoint_b = (b2 + b1) / 2;
bool ans = (solve(a1, midpoint_a, midpoint_b + 1, b2) &&
solve(midpoint_a + 1, a2, b1, midpoint_b));
if (!ans)
ans = ans || (solve(a1, midpoint_a, b1, midpoint_b) &&
solve(midpoint_a + 1, a2, midpoint_b + 1, b2));
return ans;
}
int main() {
cin >> a;
cin >> b;
init();
if (solve(0, a.size() - 1, 0, b.size() - 1))
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxnb = (int)1e9 + 7;
const double pi = acos(-1.0);
const int maxnl = 100500;
const double eps = 1e-9;
string s1, s2;
string sm(string s) {
if (s.length() % 2 == 1) return s;
string s1 = sm(s.substr(0, s.size() / 2));
string s2 = sm(s.substr(s.size() / 2, s.size()));
if (s1 < s2)
return s1 + s2;
else
return s2 + s1;
}
int main() {
cin >> s1 >> s2;
cout << (sm(s1) == sm(s2) ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res) n -= n & (-n);
return res;
}
long long int gcd(long long int a, long long int b) {
return (a ? gcd(b % a, a) : b);
}
long long int modPow(long long int a, long long int b, long long int MOD) {
long long int x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y) % MOD;
}
b /= 2;
y = (y * y) % MOD;
}
return x;
}
long long int modInverse(long long int a, long long int p) {
return modPow(a, p - 2, p);
}
using namespace std;
string func(string str) {
int len = str.size();
if (len & 1)
return str;
else {
string first = func(str.substr(0, len / 2));
string second = func(str.substr(len / 2, len));
if (first < second)
return first + second;
else
return second + first;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string str1, str2;
cin >> str1 >> str2;
int a, b, c;
if (func(str1) == func(str2))
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace ::std;
const double pi = acos(-1.0);
int a1, b1, walls[2][2];
bool check(int w, int h, int w2, int h2) {
if (w + w2 <= b1 && max(h, h2) <= a1) return true;
if (w + w2 <= a1 && max(h, h2) <= b1) return true;
return false;
}
bool equal(const string& f, const string& s) {
if (f == s) return true;
if (f.size() % 2 && f != s) return false;
string f1 = f.substr(0, f.size() / 2),
f2 = f.substr(f.size() / 2, f.size() / 2);
string s1 = s.substr(0, f.size() / 2),
s2 = s.substr(f.size() / 2, f.size() / 2);
return (equal(f1, s2) && equal(f2, s1)) || (equal(f1, s1) && equal(f2, s2));
}
string a, b;
int main() {
cin >> a >> b;
if (equal(a, b))
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int to_int(string s) {
int first = 0;
int k = (int)pow(10, (double)s.length() - 1);
for (int i = 0; i < (int)s.length(); i++) {
first += (s[i] - '0') * k;
k /= 10;
}
return first;
}
string to_string(int first) {
if (first == 0) {
return "0";
}
string s = "";
bool f = first < 0;
first = abs(first);
while (first != 0) {
s += (first % 10) + '0';
first /= 10;
}
string t = "";
if (f) {
t = "-";
}
for (int i = s.length() - 1; i >= 0; i--) {
t += s[i];
}
return t;
}
int factorial(int first) {
int sum = 1;
for (long long i = 1; i <= first; i++) {
sum *= i;
}
return sum;
}
bool is_prime(int n) {
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
string a(string s) {
if (s.size() % 2 == 1) {
return s;
}
string first = s.substr(0, s.size() / 2);
string second = s.substr(s.size() / 2, s.size());
first = a(first);
second = a(second);
if (first < second) {
return first + second;
} else {
return second + first;
}
}
inline void out(int mas[], int s) {
for (int i = 0; i < s; i++) {
cout << mas[i] << endl;
}
}
inline long long nxt() {
long long first;
scanf("%I64d", &first);
return first;
}
int main() {
string s, str;
cin >> s >> str;
if (a(s) == a(str))
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
char a[200001];
char b[200001];
bool divide(int a1, int b1, int len) {
if (len == 1) {
return a[a1] == b[b1];
} else if (strncmp(a + a1, b + b1, len) == 0) {
return true;
}
if (len % 2 == 0) {
if (divide(a1, b1, len / 2) &&
divide(a1 + (len / 2), b1 + (len / 2), len / 2)) {
return true;
}
if (divide(a1 + (len / 2), b1, len / 2) &&
divide(a1, b1 + (len / 2), len / 2)) {
return true;
}
}
return false;
}
int main() {
scanf("%s%s", a, b);
int len = strlen(a);
if (divide(0, 0, len)) {
printf("YES");
} else {
printf("NO");
}
}
|
#include <bits/stdc++.h>
using namespace std;
string conv(string cur) {
int i;
if (cur.size() & 1)
return cur;
else {
string tmp, tmp1;
for (i = 0; i < cur.size() / 2; i++) tmp.push_back(cur[i]);
for (; i < cur.size(); i++) tmp1.push_back(cur[i]);
tmp = conv(tmp);
tmp1 = conv(tmp1);
if (tmp < tmp1) {
return tmp + tmp1;
} else
return tmp1 + tmp;
}
}
int main() {
ios_base::sync_with_stdio(false);
int t, i, j, k, n, m, a, b, c;
string inp, inp2;
cin >> inp >> inp2;
if (conv(inp) == conv(inp2))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
if (s.size() & 1) return s;
string x = solve(s.substr(0, s.size() / 2));
string y = solve(s.substr(s.size() / 2));
return min(x + y, y + x);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a, b;
cin >> a >> b;
cout << (solve(a) == solve(b) ? "YES" : "NO") << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
string smallest(string a) {
if (a.size() & 1) return a;
string b = smallest(a.substr(0, a.size() / 2));
string c = smallest(a.substr(a.size() / 2));
if (b > c)
return c + b;
else
return b + c;
}
int main() {
cin >> a >> b;
if (smallest(a) == smallest(b))
cout << "YES\n";
else
cout << "NO\n";
}
|
#include <bits/stdc++.h>
using namespace std;
long long int inline ipow(long long int a, long long int b, long long int m) {
long long int val = 1;
a %= m;
while (b) {
if (b & 01) val = (val * a) % m;
b >>= 1;
a = (a * a) % m;
};
return val % m;
}
long long int inline ipow(long long int a, long long int b) {
long long int val = 1;
while (b) {
if (b & 01) val = (val * a);
b >>= 1;
a = (a * a);
};
return val;
}
set<pair<int, int> > s;
set<int> xc;
set<int> yc;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool func(string a, string b) {
if (a == b)
return true;
else if (a.size() % 2 == 0) {
long long int length = a.size() / 2;
if (func(a.substr(0, length), b.substr(length, length)) &&
func(a.substr(length, length), b.substr(0, length)) ||
func(a.substr(0, length), b.substr(0, length)) &&
func(a.substr(length, length), b.substr(length, length)))
return true;
else
return false;
} else
return false;
}
int main() {
string a, b;
cin >> a >> b;
if (func(a, b))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string chk(string a) {
if (a.length() & 1) {
return a;
}
string left = chk(a.substr(0, a.length() / 2));
string right = chk(a.substr(a.length() / 2, a.length()));
if (left < right)
return left + right;
else
return right + left;
}
int main() {
string a, b;
cin >> a >> b;
if (chk(a) == chk(b)) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
int m, n, y;
bool ans(string s, string t) {
if (s == t) return 1;
if ((s.length()) % 2) {
return 0;
}
int z1 = s.length() / 2;
string g1 = s.substr(0, z1), g2 = t.substr(z1, z1), g3 = t.substr(0, z1),
g4 = s.substr(z1, z1);
return ((ans(g1, g2) && ans(g3, g4)) || (ans(g1, g3) && ans(g4, g2)));
}
int main() {
ios::sync_with_stdio(false);
cin >> a >> b;
if (ans(a, b))
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
bool eq(int idx1, int idx2, int idx3, int idx4) {
if (idx2 - idx1 != idx4 - idx3) return false;
bool all = true;
for (int i = idx1; i <= idx2; i++) {
all = all && a[i] == b[idx3 + i - idx1];
}
if (all) return true;
if (idx1 == idx2) return false;
return (((idx2 - idx1 + 1) % 2) == 0) && (((idx4 - idx3 + 1) % 2) == 0) &&
((eq(idx1, (idx1 + idx2) / 2, (idx3 + idx4) / 2 + 1, idx4) &&
eq((idx1 + idx2) / 2 + 1, idx2, idx3, (idx3 + idx4) / 2)) ||
(eq(idx1, (idx1 + idx2) / 2, idx3, (idx3 + idx4) / 2) &&
eq((idx1 + idx2) / 2 + 1, idx2, (idx3 + idx4) / 2 + 1, idx4)));
}
int main() {
cin >> a >> b;
if (eq(0, a.size() - 1, 0, b.size() - 1)) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string word, word2;
bool check(string a, string b) {
if (a == b) return 1;
int len = a.size();
if (len & 1 || len == 0) return 0;
len >>= 1;
string temp = a.substr(0, len), temp1 = a.substr(len, len),
tmp = b.substr(0, len), tmp1 = b.substr(len, len);
if (check(temp, tmp1) && check(temp1, tmp) ||
check(temp, tmp) && check(temp1, tmp1))
return 1;
return 0;
}
int main() {
cin >> word >> word2;
if (check(word, word2))
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1E9 + 9;
const string process(const string &s) {
if (s.size() & 1) return s;
string s1 = process(s.substr(0, s.size() >> 1));
string s2 = process(s.substr(s.size() >> 1));
return s1 < s2 ? s1 + s2 : s2 + s1;
}
int main() {
string s1, s2;
cin >> s1 >> s2;
printf("%s\n", process(s1) == process(s2) ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int MOD = 1e9 + 7;
const int CM = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
template <typename T>
T MAX(T a, T b) {
return a > b ? a : b;
}
template <typename T>
T MIN(T a, T b) {
return a > b ? b : a;
}
template <typename T>
T GCD(T a, T b) {
return b == 0 ? a : GCD(b, a % b);
}
template <typename T>
T LCM(T a, T b) {
return a / GCD(a, b) * b;
}
template <typename T>
T ABS(T a) {
return a > 0 ? a : -a;
}
template <typename T>
T ADD(T a, T b, T MOD) {
return (a + b) % MOD;
}
template <typename T>
T DEL(T a, T b, T MOD) {
return ((a - b) % MOD + MOD) % MOD;
}
template <typename T>
T getmod(T a, T mod) {
return (a % mod + mod) % mod;
}
template <typename T>
void debug(T a, char x) {
return;
}
int rand(int a, int b) { return rand() % (b - a + 1) + a; }
string a, b;
bool divi(string a, string b) {
if (a == b) return 1;
int n = a.length();
if (n & 1) return 0;
string a1 = a.substr(0, n / 2), a2 = a.substr(n / 2, n / 2);
string b1 = b.substr(0, n / 2), b2 = b.substr(n / 2, n / 2);
if (divi(a1, b2) && divi(a2, b1)) return 1;
if (divi(a1, b1) && divi(a2, b2)) return 1;
return 0;
}
void solve(int kase) {
cin >> a >> b;
if (divi(a, b))
printf("YES\n");
else
printf("NO\n");
}
const bool DUO = 0;
void TIME() {
clock_t start, finish;
double totaltime;
start = clock();
if (DUO) {
int Kase = 0;
cin >> Kase;
for (int kase = 1; kase <= Kase; kase++) solve(kase);
} else
solve(1);
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
printf("\nTime:%lfms\n", totaltime * 1000);
}
int main() {
if (DUO) {
int Kase = 0;
cin >> Kase;
for (int kase = 1; kase <= Kase; kase++) solve(kase);
} else
solve(1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
long long int e[100], ha[200005], hb[200005], len, pexp[200005];
map<long long int, int> dp;
long long int fastexp(long long int base, long long int ex) {
long long int ans = 1;
while (ex) {
if (ex % 2 == 1) ans = (ans % 1000000007 * base % 1000000007) % 1000000007;
ex /= 2;
base = (base * base) % 1000000007;
}
return ans % 1000000007;
}
long long int make(long long int x, long long int y, long long int z) {
return z + y * 1000000 + x * 1000000000000;
}
void pre() {
e[0] = 1;
for (int i = 1; i < 30; i++) e[i] = 2 * e[i - 1];
long long int exp = 33;
pexp[0] = 1;
ha[1] = a[0];
hb[1] = b[0];
for (int i = 1; i < a.size(); i++) {
ha[i + 1] =
(((a[i] % 1000000007) * (exp % 1000000007)) % 1000000007 + ha[i]) %
1000000007;
hb[i + 1] =
(((b[i] % 1000000007) * (exp % 1000000007)) % 1000000007 + hb[i]) %
1000000007;
pexp[i] = fastexp(exp, 1000000007 - 2);
exp = (exp * 33) % 1000000007;
}
len = a.size();
}
int cdp(long long int p2, long long int sa, long long int sb) {
if (dp.find(make(p2, sa, sb)) == dp.end()) {
int temp = 0;
if (((ha[sa + (len / e[p2]) - 1] - ha[sa - 1] + 1000000007) % 1000000007 *
pexp[sa - 1]) %
1000000007 ==
((hb[sb + (len / e[p2]) - 1] - hb[sb - 1] + 1000000007) % 1000000007 *
pexp[sb - 1]) %
1000000007)
temp = 1;
else if ((len / e[p2]) % 2 == 1)
temp = 0;
else if (cdp(p2 + 1, sa, sb + len / e[p2 + 1]) == 1 &&
cdp(p2 + 1, sa + len / e[p2 + 1], sb) == 1)
temp = 1;
else if (cdp(p2 + 1, sa, sb) == 1 &&
cdp(p2 + 1, sa + len / e[p2 + 1], sb + len / e[p2 + 1]) == 1)
temp = 1;
dp[make(p2, sa, sb)] = temp;
}
return dp[make(p2, sa, sb)];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b;
pre();
if (cdp(0, 1, 1) == 1)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
return 0;
}
|
#include <bits/stdc++.h>
char A[210000];
char B[210000];
bool Equal(int Ab, int Ae, int Bb, int Be) {
int i;
if ((Ae - Ab + 1) % 2) {
for (i = Ab; i <= Ae; i++)
if (A[i] != B[i - Ab + Bb]) break;
if (i > Ae)
return true;
else
return false;
} else {
if (Equal(Ab, (Ab + Ae) / 2, Bb, (Bb + Be) / 2) &&
Equal((Ab + Ae) / 2 + 1, Ae, (Bb + Be) / 2 + 1, Be))
return true;
else if (Equal(Ab, (Ab + Ae) / 2, (Bb + Be) / 2 + 1, Be) &&
Equal((Ab + Ae) / 2 + 1, Ae, Bb, (Bb + Be) / 2))
return true;
else
return false;
}
}
int main() {
int L;
scanf("%s %s", A, B);
L = strlen(A);
if (Equal(0, L - 1, 0, L - 1))
printf("YES");
else
printf("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char A[201000], B[201000];
bool isequal(int l, int r, int a, int b) {
int i, j;
for (i = l, j = a; i <= r; i++, j++)
if (A[i] != B[j]) return false;
return true;
}
bool iseqv(int l, int r, int a, int b) {
if ((r - l + 1) % 2 == 1) return isequal(l, r, a, b);
if (isequal(l, r, a, b)) return true;
int m = (l + r) / 2, c = (a + b) / 2;
return (iseqv(l, m, a, c) && iseqv(m + 1, r, c + 1, b)) ||
(iseqv(l, m, c + 1, b) && iseqv(m + 1, r, a, c));
}
int main() {
int len;
scanf("%s", A);
scanf("%s", B);
len = strlen(A) - 1;
iseqv(0, len, 0, len) ? printf("YES\n") : printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[200001], b[200001];
scanf("%s%s", a, b);
int ln = strlen(a);
auto f = [&](char *s) {
int lns = ln;
while (lns % 2 == 0) {
lns >>= 1;
}
for (int i = lns; i + i <= ln; i <<= 1) {
for (int j = 0; j < ln; j += i + i) {
for (int jj = j; jj < j + i; jj++) {
if (s[jj] != s[jj + i]) {
if (s[jj] > s[jj + i])
for (int ii = j; ii < j + i; ii++) {
swap(s[ii], s[ii + i]);
}
break;
}
}
}
}
};
f(a);
f(b);
if (strcmp(a, b) == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string str1, str2;
int sum[2][30][200005];
bool solve(string &a, string &b, int an, int bn) {
bool ret = false;
if (a == b) return true;
if (a.length() % 2) return false;
for (int k = 'a'; k <= 'z'; k++) {
if (sum[0][k - 'a'][an + a.length()] - sum[0][k - 'a'][an] !=
sum[1][k - 'a'][bn + b.length()] - sum[1][k - 'a'][bn])
return false;
}
string at[2], bt[2];
bool tt[2][2] = {};
int as = a.size() / 2, bs = b.size() / 2;
at[0] = a.substr(0, as);
at[1] = a.substr(as);
bt[0] = b.substr(0, bs);
bt[1] = b.substr(bs);
if (solve(at[0], bt[0], an, bn) && solve(at[1], bt[1], an + as, bn + bs)) {
ret = true;
} else if (solve(at[1], bt[0], an + as, bn) &&
solve(at[0], bt[1], an, bn + bs)) {
ret = true;
}
return ret;
}
int main() {
cin >> str1 >> str2;
for (int i = 0; i < str1.length(); i++) {
for (int k = 'a'; k <= 'z'; k++) {
sum[0][k - 'a'][i + 1] = sum[0][k - 'a'][i];
sum[1][k - 'a'][i + 1] = sum[1][k - 'a'][i];
}
sum[0][str1[i] - 'a'][i + 1]++;
sum[1][str2[i] - 'a'][i + 1]++;
}
cout << (solve(str1, str2, 0, 0) ? "YES" : "NO") << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool eq(string p, string q) {
if (p == q) return true;
int n1 = p.length(), m1 = q.length();
if (n1 & 1 || m1 & 1 || n1 == 0 || m1 == 0) return false;
if (eq(p.substr(0, n1 / 2), q.substr(m1 / 2, m1 / 2)) &&
eq(p.substr(n1 / 2, n1 / 2), q.substr(0, m1 / 2)))
return true;
if (eq(p.substr(0, n1 / 2), q.substr(0, m1 / 2)) &&
eq(p.substr(n1 / 2, n1 / 2), q.substr(m1 / 2, m1 / 2)))
return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string p, q;
cin >> p >> q;
if (eq(p, q))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int mod = 1073741824;
const int MAXN = 1e9 + 1;
const double PI = 3.14159265359;
using namespace std;
string first(string q) {
if (q.size() % 2 == 1) {
return q;
}
string a = q.substr(0, q.size() / 2);
string b = q.substr(q.size() / 2, q.size());
a = first(a);
b = first(b);
if (a < b) {
return a + b;
} else {
return b + a;
}
}
int main() {
ios_base::sync_with_stdio(0);
string a, b;
cin >> a >> b;
if (first(a) == first(b)) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool solve(string a, string b) {
if (a == b) return true;
int n = a.size();
if (n % 2 == 1) return false;
string a1 = a.substr(0, n / 2);
string a2 = a.substr(n / 2, n / 2);
string b1 = b.substr(0, n / 2);
string b2 = b.substr(n / 2, n / 2);
bool x = (solve(a1, b2) && solve(a2, b1));
if (x) return true;
x = (solve(a1, b1) && solve(a2, b2));
return x;
}
int main() {
ios::sync_with_stdio(0);
string a, b;
cin >> a >> b;
bool x = solve(a, b);
if (x)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string smalleststring(string s) {
if (s.length() % 2 == 1) return s;
string s1 = smalleststring(s.substr(0, s.length() / 2));
string s2 = smalleststring(s.substr(s.length() / 2, s.length()));
return s1 < s2 ? s1 + s2 : s2 + s1;
}
int main() {
string sa, sb;
cin >> sa >> sb;
sa = smalleststring(sa);
sb = smalleststring(sb);
printf("%s\n", sa == sb ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int MOD = 1e9 + 7;
const int CM = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
template <typename T>
T MAX(T a, T b) {
return a > b ? a : b;
}
template <typename T>
T MIN(T a, T b) {
return a > b ? b : a;
}
template <typename T>
T GCD(T a, T b) {
return b == 0 ? a : GCD(b, a % b);
}
template <typename T>
T LCM(T a, T b) {
return a / GCD(a, b) * b;
}
template <typename T>
T ABS(T a) {
return a > 0 ? a : -a;
}
template <typename T>
T ADD(T a, T b, T MOD) {
return (a + b) % MOD;
}
template <typename T>
T DEL(T a, T b, T MOD) {
return ((a - b) % MOD + MOD) % MOD;
}
template <typename T>
T getmod(T a, T mod) {
return (a % mod + mod) % mod;
}
template <typename T>
void debug(T a, char x) {
return;
}
int rand(int a, int b) { return rand() % (b - a + 1) + a; }
char aa[N], bb[N];
char a1[N], a2[N], b1[N], b2[N];
bool divi(int l1, int r1, int l2, int r2) {
bool f = 1;
for (int i = l1, j = l2; i <= r1 && j <= r2; i++, j++) {
if (aa[i] != bb[j]) {
f = 0;
break;
}
}
if (f == 1) return 1;
int n = r1 - l1 + 1;
if (n & 1) return 0;
int mid1 = (l1 + r1) >> 1, mid2 = (l2 + r2) >> 1;
if (divi(l1, mid1, l2, mid2) && divi(mid1 + 1, r1, mid2 + 1, r2)) return 1;
if (divi(l1, mid1, mid2 + 1, r2) && divi(mid1 + 1, r1, l2, mid2)) return 1;
return 0;
}
void solve(int kase) {
scanf("%s", aa + 1);
scanf("%s", bb + 1);
int n = strlen(aa + 1);
if (divi(1, n, 1, n))
printf("YES\n");
else
printf("NO\n");
}
const bool DUO = 0;
void TIME() {
clock_t start, finish;
double totaltime;
start = clock();
if (DUO) {
int Kase = 0;
cin >> Kase;
for (int kase = 1; kase <= Kase; kase++) solve(kase);
} else
solve(1);
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
printf("\nTime:%lfms\n", totaltime * 1000);
}
int main() {
if (DUO) {
int Kase = 0;
cin >> Kase;
for (int kase = 1; kase <= Kase; kase++) solve(kase);
} else
solve(1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1E9 + 9;
const int maxn = 2e5 + 6;
char s1[maxn], s2[maxn];
bool ok(int a, int b, int c, int d) {
for (; a <= b && (s1[a] == s2[c]); a++, c++)
;
return a > b;
}
bool dfs(int a, int b, int c, int d) {
if (ok(a, b, c, d)) return true;
if ((b - a + 1) & 1) return false;
int m1 = (a + b) >> 1;
int m2 = (c + d) >> 1;
if (dfs(a, m1, c, m2) && dfs(m1 + 1, b, m2 + 1, d)) return true;
return dfs(a, m1, m2 + 1, d) && dfs(m1 + 1, b, c, m2);
}
int main() {
scanf("%s%s", s1 + 1, s2 + 1);
printf("%s\n", (dfs(1, strlen(s1 + 1), 1, strlen(s2 + 1)) ? "YES" : "NO"));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int tree[25][300000];
bool lazy[25][300000] = {0};
bitset<25> mybitset[300000];
string minEquivalent(string s) {
if (s.length() % 2) return s;
string s1 = minEquivalent(s.substr(0, s.length() / 2));
string s2 = minEquivalent(s.substr(s.length() / 2, s.length() / 2));
if (s1 < s2)
return s1 + s2;
else
return s2 + s1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string a, b;
cin >> a >> b;
if (minEquivalent(a) == minEquivalent(b)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool isequal(string& a, string& b) {
if (a.size() != b.size()) return false;
if (a == b) return true;
if (a.size() % 2) return false;
string ah = string(a.begin(), a.begin() + a.size() / 2);
string al = string(a.begin() + a.size() / 2, a.end());
string bh = string(b.begin(), b.begin() + b.size() / 2);
string bl = string(b.begin() + b.size() / 2, b.end());
return (isequal(ah, bl) && isequal(al, bh)) ||
(isequal(ah, bh) && isequal(al, bl));
}
int main() {
string a, b;
cin >> a >> b;
cout << (isequal(a, b) ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[200200], t[200200];
bool solve(int l, int r, int L, int R) {
bool f = 1;
for (int i = l, j = L; i < r && j < R && f; i++, j++)
if (s[i] != t[j]) f = 0;
if (f) return 1;
int len = r - l;
if (len % 2 == 0) {
int m = (l + r) >> 1;
int M = (L + R) >> 1;
if (solve(l, m, L, M) && solve(m, r, M, R)) return 1;
if (solve(l, m, M, R) && solve(m, r, L, M)) return 1;
}
return 0;
}
int main() {
scanf("%s%s", s, t);
int n = strlen(s);
if (solve(0, n, 0, n))
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool f(string a, string b) {
string a1, a2, b1, b2;
if (a.size() == 0 or b.size() == 0) return false;
if (a.size() != b.size()) return false;
bool res = (a == b);
if ((a.size() % 2 != 0 or b.size() % 2 != 0) and !res) return false;
if (res) return true;
a1.insert(a1.begin(), a.begin(), a.begin() + a.size() / 2);
a2.insert(a2.begin(), a.begin() + a.size() / 2, a.end());
b1.insert(b1.begin(), b.begin(), b.begin() + b.size() / 2);
b2.insert(b2.begin(), b.begin() + b.size() / 2, b.end());
if (f(a1, b2) and f(a2, b1))
return true;
else if (f(a1, b1) and f(a2, b2))
return true;
else
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string a, b;
cin >> a >> b;
if (f(a, b))
printf("YES");
else
printf("NO");
}
|
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
bool f(string a, string b) {
if (a == b) return true;
int len1 = a.size(), len2 = b.size();
if (len1 & 1 || len2 & 1) return false;
if (len1 == 1) return false;
string ta1 = a.substr(0, len1 / 2), ta2 = a.substr(len1 / 2, len1 / 2);
string tb1 = b.substr(0, len2 / 2), tb2 = b.substr(len2 / 2, len2 / 2);
return (f(ta1, tb2) && f(ta2, tb1)) || (f(ta1, tb1) && f(ta2, tb2));
}
int main() {
cin >> s1;
cin >> s2;
if (f(s1, s2))
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool equiv(const string& a, const string& b) {
static string _a1, _a2, _b1, _b2;
if (a == b) return true;
if (a.size() % 2) return false;
string a1 = a.substr(0, a.size() / 2), a2 = a.substr(a.size() / 2);
string b1 = b.substr(0, b.size() / 2), b2 = b.substr(b.size() / 2);
_a1 = a1, _a2 = a2;
_b1 = b1, _b2 = b2;
sort(_a1.begin(), _a1.end());
sort(_a2.begin(), _a2.end());
sort(_b1.begin(), _b1.end());
sort(_b2.begin(), _b2.end());
const bool f1 = (_a1 == _b1 && _a2 == _b2);
const bool f2 = (_a1 == _b2 && _a2 == _b1);
if (f1)
if (equiv(a1, b1) && equiv(a2, b2)) return true;
if (f2)
if (equiv(a1, b2) && equiv(a2, b1)) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
string a, b;
cin >> a >> b;
cout << (equiv(a, b) ? "YES" : "NO") << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
if (s.size() & 1) return s;
string s1 = solve(s.substr(0, s.size() / 2));
;
string s2 = solve(s.substr(s.size() / 2));
;
return (s1 < s2 ? s1 + s2 : s2 + s1);
}
int main() {
string s, str;
cin >> s >> str;
cout << (solve(s) == solve(str) ? "YES" : "NO");
}
|
#include <bits/stdc++.h>
using namespace std;
char a[200010], b[200010];
int equi(char *s, char *t, int len) {
if (!strncmp(s, t, len))
return 1;
else if (len % 2)
return 0;
else if (equi(s, t + len / 2, len / 2) && equi(s + len / 2, t, len / 2))
return 1;
else if (equi(s, t, len / 2) && equi(s + len / 2, t + len / 2, len / 2))
return 1;
else
return 0;
}
int main() {
scanf("%s%s", a, b);
if (equi(a, b, strlen(a)))
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char a[204800], b[204800], c[204800];
void canon(char *p, int len) {
if (len & 1) return;
len >>= 1;
canon(p, len);
canon(p + len, len);
bool is_rev = false;
for (int i = 0; i < len; i++)
if (p[i] > p[i + len]) {
is_rev = true;
break;
} else if (p[i] < p[i + len])
break;
if (is_rev) {
char tmp;
for (int i = 0; i < len; i++) {
tmp = p[i];
p[i] = p[i + len];
p[i + len] = tmp;
}
}
}
int main() {
scanf("%s%s", a, b);
int len = strlen(a);
canon(a, len);
canon(b, len);
if (strcmp(a, b) == 0)
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string smallest(string s) {
if (s.length() % 2 == 1) return s;
string s1 = smallest(s.substr(0, s.length() / 2));
string s2 = smallest(s.substr(s.length() / 2));
if (s1 < s2)
return s1 + s2;
else
return s2 + s1;
}
bool solve(string s1, string s2) {
for (int i = 0; i < s1.length(); i++)
if (s1[i] != s2[i]) return 0;
return 1;
}
int main() {
string s1, s2;
cin >> s1 >> s2;
s1 = smallest(s1);
s2 = smallest(s2);
if (solve(s1, s2))
cout << "YES\n";
else
cout << "NO\n";
}
|
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long MAX = 1e17;
int itachi[2][26][200001], n, nar1[26], nar2[26], flag[4][26];
string a, b;
void help(int id1, int s, int l, int id2) {
for (int i = 0; i < 26; ++i) {
if (s == 0)
flag[id1][i] = itachi[id2][i][s + l - 1];
else
flag[id1][i] = itachi[id2][i][s + l - 1] - itachi[id2][i][s - 1];
}
}
bool verify(int id1, int id2) {
for (int i = 0; i < 26; ++i) {
if (flag[id1][i] != flag[id2][i]) return 0;
}
return 1;
}
bool check(int s1, int s2, int l) {
if (l % 2 != 0) {
for (int i = 0; i < l; ++i) {
if (a[s1 + i] != b[s2 + i]) return 0;
}
return 1;
} else {
help(0, s1, l / 2, 0);
help(1, s1 + l / 2, l / 2, 0);
help(2, s2, l / 2, 1);
help(3, s2 + l / 2, l / 2, 1);
bool x = (verify(0, 2) and verify(1, 3));
bool y = (verify(0, 3) and verify(1, 2));
if (x) {
if (check(s1, s2, l / 2) and check(s1 + l / 2, s2 + l / 2, l / 2))
return 1;
}
if (y) {
if (check(s1, s2 + l / 2, l / 2) and check(s1 + l / 2, s2, l / 2))
return 1;
}
return 0;
}
}
int main() {
ios_base::sync_with_stdio(0);
;
cin >> a >> b;
n = a.size();
for (int i = 0; i < n; ++i) {
int x = a[i] - 'a';
nar1[x]++;
for (int j = 0; j < 26; ++j) {
itachi[0][j][i] = nar1[j];
}
}
for (int i = 0; i < n; ++i) {
int y = b[i] - 'a';
nar2[y]++;
for (int j = 0; j < 26; ++j) {
itachi[1][j][i] = nar2[j];
}
}
if (check(0, 0, n)) {
cout << "YES" << '\n';
return 0;
;
}
cout << "NO" << '\n';
return 0;
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
bool isEq(int start1, int len1, int start2, int len2) {
if (len1 & 1) {
for (int i = 0; i < len1; i++) {
if (s1[start1 + i] != s2[start2 + i]) return false;
}
return true;
}
int mid1 = len1 / 2, mid2 = len2 / 2;
int skip1 = len1 % 2, skip2 = len2 % 2;
bool result = ((isEq(start1, mid1, start2, mid2) &&
isEq(start1 + mid1, mid1, start2 + mid2, mid2)) ||
(isEq(start1, mid1, start2 + mid2, mid2) &&
isEq(start1 + mid1, mid1, start2, mid2)));
return result;
}
int main() {
cin >> s1 >> s2;
if (s1.compare(s2) == 0)
printf("YES\n");
else {
if (isEq(0, s1.length(), 0, s2.length()))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string getmin(string st) {
int len = st.size();
if (len % 2) return st;
string s1 = st.substr(0, len / 2);
string s2 = st.substr(len / 2, len / 2);
s1 = getmin(s1);
s2 = getmin(s2);
if (s1 < s2) return s1 + s2;
return s2 + s1;
}
string s, w;
int main() {
cin >> s >> w;
s = getmin(s);
w = getmin(w);
if (s == w)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t k = 0;
inline bool equals(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2,
int64_t j2) {
if (j1 != j2) {
return false;
}
auto x = j1;
for (int64_t i = 0; i < x; i++) {
if (s1[i1 + i] != s2[i2 + i]) {
return false;
}
}
return true;
}
bool equivilant(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2,
int64_t j2) {
if (equals(s1, i1, j1, s2, i2, j2)) {
return true;
}
if (j1 != j2 || j1 % 2 == 1) {
return false;
}
auto x = j1 / 2;
if (equivilant(s1, i1, x, s2, i2, x) &&
equivilant(s1, i1 + x, x, s2, i2 + x, x)) {
return true;
}
if (equivilant(s1, i1, x, s2, i2 + x, x) &&
equivilant(s1, i1 + x, x, s2, i2, x)) {
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
string s1;
cin >> s1;
string s2;
cin >> s2;
if (equivilant(s1, 0, s1.size(), s2, 0, s2.size())) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 9e18;
const double pi = acos(-1.0);
const long long M = 1e9 + 7;
const long long N = 1e5 + 5;
bool equ(string s1, string s2) {
if (s1 == s2) return 1;
if (s1.size() == 1) return 0;
string t1, t2, t3, t4;
if ((long long)s1.size() % 2) return 0;
long long l = s1.size();
long long ar1[27] = {0}, ar2[27] = {0}, ar3[27] = {0}, ar4[27] = {0};
for (long long i = 0; i < l / 2; i++) {
t1 += s1[i];
ar1[s1[i] - 'a']++;
t2 += s1[i + l / 2];
ar2[s1[i + l / 2] - 'a']++;
t3 += s2[i];
ar3[s2[i] - 'a']++;
t4 += s2[i + l / 2];
ar4[s2[i + l / 2] - 'a']++;
}
long long cnt1(1), cnt2(1), cnt3(1), cnt4(1);
for (long long i = 0; i < 26; i++) {
if (ar1[i] != ar3[i]) cnt1 = 0;
if (ar1[i] != ar4[i]) cnt3 = 0;
if (ar2[i] != ar4[i]) cnt2 = 0;
if (ar2[i] != ar3[i]) cnt4 = 0;
}
if (cnt1 && cnt2 && equ(t1, t3) && equ(t2, t4)) return 1;
if (cnt3 && cnt4 && equ(t1, t4) && equ(t2, t3)) return 1;
return 0;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
if (equ(s1, s2)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
string f(string a) {
int len = a.size();
if (len & 1) return a;
int mid = len >> 1;
string x = f(a.substr(0, mid));
string y = f(a.substr(mid, mid));
if (x < y)
return x + y;
else
return y + x;
}
int main() {
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
if (f(s) == f(t))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
string get(string x) {
if (x.length() % 2) return x;
string t1 = get(x.substr(0, x.length() / 2));
string t2 = get(x.substr(x.length() / 2));
return min(t1, t2) + max(t1, t2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s1;
cin >> s2;
if (get(s1) == get(s2))
cout << "YES";
else
cout << "NO";
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.