이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "trilib.h"
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
int ct = 0;
bool is_clockwise2(int a, int b, int c) {
ct++;
if (ct > 1000000)
exit(1);
return is_clockwise(a, b, c);
}
vector<int> build_hull(vector<int> v, bool inv) {
sort(v.begin() + 1, v.end(), [=](int x, int y) {
return is_clockwise2(v[0], x, y) ^ inv;
});
vector<int> h;
for (int x : v) {
while (h.size() > 1 && !(is_clockwise2(*(h.end() - 2), *(h.end() - 1), x) ^ inv)) {
h.pop_back();
}
h.push_back(x);
}
return h;
}
vector<int> just_sort(vector<int> v, bool inv) {
sort(v.begin() + 1, v.end(), [=](int x, int y) {
return is_clockwise2(v[0], x, y) ^ inv;
});
return v;
}
const int N = 1e5;
bool ban[N];
int a[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n = get_n();
for (int i = 1; i <= n; i++)
a[i] = i;
mt19937 rnd(time(0));
shuffle(a + 1, a + 1 + n, rnd);
vector<int> v1 = { a[1] }, v2 = { a[1] };
for (int i = 3; i <= n; i++) {
if (is_clockwise2(a[1], a[2], a[i])) {
v2.push_back(a[i]);
}
else {
v1.push_back(a[i]);
}
}
v1.push_back(a[2]);
v2.push_back(a[2]);
v1 = build_hull(v1, 0);
v2 = just_sort(v2, 1);
v2.erase(v2.begin());
v2.pop_back();
reverse(all(v1));
for (int x : v2) {
while (v1.size() > 1 && is_clockwise2(*(v1.end() - 2), *(v1.end() - 1), x)) {
ban[v1.back()] = 1;
v1.pop_back();
}
v1.push_back(x);
}
reverse(all(v1));
reverse(all(v2));
for (int x : v2) {
if (ban[x])
continue;
while (v1.size() > 1 && !is_clockwise2(*(v1.end() - 2), *(v1.end() - 1), x)) {
ban[v1.back()] = 1;
v1.pop_back();
}
v1.push_back(x);
}
sort(all(v1));
v1.erase(unique(all(v1)), v1.end());
int ans = 0;
for (int i : v1) {
if (!ban[i])
ans++;
}
give_answer(ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |