Skip to content

Commit

Permalink
feat: upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiphereth-A committed May 5, 2024
1 parent 694d311 commit 87d4d26
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
28 changes: 10 additions & 18 deletions src/code/geo2d/cvh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct cvh : public polygon<FP> {
CEXP cvh() {}
explicit CEXP cvh(u32 sz) : polygon<FP>(sz) {}
explicit CEXP cvh(vec<point<FP>> CR vs_, bool inited = false, bool strict = true) : polygon<FP>(vs_) {
if (!inited) strict ? init() : init_nonstrict();
if (!inited) strict ? init<true>() : init<false>();
}

friend std::istream &operator>>(std::istream &is, cvh &ch) {
Expand All @@ -24,30 +24,23 @@ struct cvh : public polygon<FP> {
return os << ch.vs.back();
}

template <bool strict = true>
CEXP cvh &init() {
this->reunique();
u32 n = (u32)this->vs.size();
if (n <= 1) return *this;
vec<point<FP>> cvh(n * 2);
u32 sz_cvh = 0;
for (u32 i = 0; i < n; cvh[sz_cvh++] = this->vs[i++])
while (sz_cvh > 1 && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) <= 0) --sz_cvh;
if CEXP (strict)
while (sz_cvh > 1 && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) <= 0) --sz_cvh;
else
while (sz_cvh > 1 && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) < 0) --sz_cvh;
for (u32 i = n - 2, t = sz_cvh; ~i; cvh[sz_cvh++] = this->vs[i--])
while (sz_cvh > t && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) <= 0) --sz_cvh;
cvh.resize(sz_cvh - 1);
this->vs = cvh;
return *this;
}
CEXP cvh &init_nonstrict() {
this->reunique();
u32 n = (u32)this->vs.size();
if (n <= 1) return *this;
vec<point<FP>> cvh(n * 2);
u32 sz_cvh = 0;
for (u32 i = 0; i < n; cvh[sz_cvh++] = this->vs[i++])
while (sz_cvh > 1 && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) < 0) --sz_cvh;
for (u32 i = n - 2, t = sz_cvh; ~i; cvh[sz_cvh++] = this->vs[i--])
while (sz_cvh > t && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) < 0) --sz_cvh;
if CEXP (strict)
while (sz_cvh > t && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) <= 0) --sz_cvh;
else
while (sz_cvh > t && sgn_cross(cvh[sz_cvh - 2], cvh[sz_cvh - 1], this->vs[i]) < 0) --sz_cvh;
cvh.resize(sz_cvh - 1);
this->vs = cvh;
return *this;
Expand Down Expand Up @@ -91,7 +84,6 @@ struct cvh : public polygon<FP> {
this->vs = result;
return *this;
}

CEXP cvh &do_minkowski_sum(cvh<FP> CR r) { return do_minkowski_sum_nonstrict(r).init(); }

CEXP cvh &do_ins_CVHhP(line<FP> CR l) {
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu-cgl/cgl_4_a.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main() {
std::cin >> n;
cvh p(n);
std::cin >> p;
p.init_nonstrict();
p.template init<false>();
std::cout << p.vs.size() << '\n';
u32 now = 0;
for (u32 i = 1; i < p.vs.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define PROBLEM "https://judge.yosupo.jp/problem/static_range_frequency"

#include "../../code/edh/hash_splitmix64.hpp"

int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
u32 n, q;
std::cin >> n >> q;
vecu a(n);
for (auto& i : a) std::cin >> i;
tifa_libs::hmap<u32, vecu> hm;
flt_ (u32, i, 0, n) hm[a[i]].push_back(i);
fle_ (u32, i, 1, q, l, r, x) {
std::cin >> l >> r >> x;
if (l == r) {
std::cout << "0\n";
continue;
}
auto CR now = hm[x];
auto it1 = std::ranges::lower_bound(now, l), it2 = std::ranges::upper_bound(now, r - 1);
std::cout << it2 - it1 << '\n';
}
return 0;
}
3 changes: 2 additions & 1 deletion src/test_cpverifier/unit-test/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ template <class T>
strn to_str(T CR x) {
std::stringstream ss;
ss << std::fixed << std::setprecision(12) << x;
return ss.str();
auto str = ss.str();
return str.length() <= 1024 ? str : str.substr(0, 1024) + "... (length = " + std::to_string(str.length()) + ")";
}

template <class T, class... Ts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main() {
case tifa_libs::unittest::ts_example_00: test("1"); break;
case tifa_libs::unittest::ts_example_01: test("2"); break;
case tifa_libs::unittest::ts_random_00: test("3"); break;
case tifa_libs::unittest::ts_random_01: test("4"); break;
case tifa_libs::unittest::ts_random_01: break;
case tifa_libs::unittest::ts_random_02: break;
case tifa_libs::unittest::ts_random_03: break;
case tifa_libs::unittest::ts_random_04: break;
Expand Down

0 comments on commit 87d4d26

Please sign in to comment.