From e415d478bc89a15296f85799df39a58b52964c6b Mon Sep 17 00:00:00 2001 From: Benjamin Qi Date: Sun, 27 Nov 2022 12:13:30 -0500 Subject: [PATCH] update geo templates + others --- Contests/Tools/USACO/usaco_val.cpp | 269 ------------------ .../geometry (13)/Polygons/HalfPlaneSet.h | 85 ++++++ .../geometry (13)/Polygons/HullDiameter.h | 9 +- .../geometry (13)/Polygons/MinkowskiSum.h | 40 +++ .../content/geometry (13)/chapter.tex | 8 +- .../content/graphs (12)/DFS/TwoSAT (12.1).h | 5 +- .../number-theory (11.1)/Euclid/ModArith.h | 2 - .../Modular Arithmetic/ModInt128.h | 260 +++++++++++++++++ .../numerical/Matrix (11.3)/MatrixTree.h | 6 +- Implementations/content/various/Decimal.py | 8 +- Implementations/content/various/FastIO.h | 6 +- 11 files changed, 408 insertions(+), 290 deletions(-) delete mode 100644 Contests/Tools/USACO/usaco_val.cpp create mode 100644 Implementations/content/geometry (13)/Polygons/HalfPlaneSet.h create mode 100644 Implementations/content/geometry (13)/Polygons/MinkowskiSum.h create mode 100644 Implementations/content/number-theory (11.1)/Modular Arithmetic/ModInt128.h diff --git a/Contests/Tools/USACO/usaco_val.cpp b/Contests/Tools/USACO/usaco_val.cpp deleted file mode 100644 index f3cfd9de..00000000 --- a/Contests/Tools/USACO/usaco_val.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define GET_MACRO(_0, _1, _2, _3, NAME, ...) NAME - -#define fail2(msg, line) do { \ - const char* _msg = (msg); \ - if (_msg) { \ - cout << "fail[line " << line << "] " << _msg << endl;\ - } else { \ - cout << "fail[line " << line << "]" << endl; \ - } \ - exit(1); \ - } while (0) - -#define fail1(msg) fail2((msg), __LINE__) - -#define fail0() fail2(NULL, __LINE__) - -#define fail(...) GET_MACRO(_0, _1, ##__VA_ARGS__, \ - fail2, fail1, fail0)(__VA_ARGS__) - -#define fassert3(cond, msg, line) do { \ - if (!(cond)) { \ - fail((msg), (line)); \ - } \ - }while(0) - -#define fassert2(cond, msg) fassert3(cond, msg, __LINE__) - -#define fassert1(cond) fassert3(cond, NULL, __LINE__) - -#define fassert(...) GET_MACRO(_0, ##__VA_ARGS__, \ - fassert3, fassert2, fassert1)(__VA_ARGS__) - -// void fail(const char* msg = NULL) { -// if (msg) { -// cout << "fail: " << msg << endl; -// } else { -// cout << "fail" << endl; -// } -// exit(1); -// } - -// void fassert(bool cond, const char* msg = NULL) { -// if (!cond) { -// fail(msg); -// } -// } - -struct input { - input(FILE* f) : uch(-2), fin(f), sin(NULL) { - } - input(istream& in) : uch(-2), fin(NULL), sin(&in) { - } - - int get() { - if (uch != -2) { - int ch = uch; - uch = -2; - return ch; - } else if (fin) { - return fgetc(fin); - } - return sin->get(); - } - - void unget(int ch) { - uch = ch; - } - - char get_char() { - int ch = get(); - if (ch == -1) { - fail("expected char"); - } else if (ch != '\n' && (ch < 32 || 126 < ch)) { - fail("expected printable ascii"); - } - return ch; - } - - void get_eof() { - fassert(get() == -1, "expected eof"); - } - - void get_eol() { - fassert(get() == '\n', "expected eol"); - } - - void get_space() { - fassert(get() == ' ', "expected space"); - } - - void get_spaces() { - int ch; - get_space(); - for (ch = get(); ch == ' '; ch = get()); - unget(ch); - } - - string get_token() { - int ch; - string res; - for (ch = get(); ch != -1 && ch != '\n' && ch != ' '; ch = get()) { - res += (char)ch; - } - fassert(!res.empty(), "expected token"); - unget(ch); - return res; - } - - long long get_int(long long min, long long max) { - string tok = get_token(); - long long res = atoll(tok.c_str()); - fassert(tok == to_string(res), "expected int"); - fassert(min <= res && res <= max, "int out of range"); - return res; - } - - string get_line(int min_length, int max_length) { - int ch; - string res; - for (ch = get(); ch != -1 && ch != '\n'; ch = get()) { - res += (char)ch; - fassert(res.size() <= max_length, "line too long"); - } - fassert(min_length <= res.size(), "line too short"); - unget(ch); - return res; - } - - int uch; - FILE* fin; - istream* sin; -}; - -vector get_test_case_batches(int argc, char** argv) { - vector res; - if (argc < 3) { - return res; - } - - int test_id = atoi(argv[1]); - if (test_id == 0) { - return res; - } - - int batch = 0; - ifstream fscorer_in(argv[2]); - for (string ln; getline(fscorer_in, ln); ) { - if (ln.empty() || ln[0] == '#') { - continue; - } - for (char& c: ln) if (c == ',') c = ' '; - int sppos = ln.find(' '); - if (sppos == string::npos) { - continue; - } - istringstream sin(ln.substr(sppos + 1)); - - for (string part; sin >> part; ) { - int dash = part.find('-'); - if (dash == string::npos) { - int num = atoi(part.c_str()); - if (num == test_id) { - res.push_back(batch); - break; - } - } else { - int lo = atoi(part.substr(0, dash).c_str()); - int hi = atoi(part.substr(dash + 1).c_str()); - if (lo <= test_id && test_id <= hi) { - res.push_back(batch); - break; - } - } - } - batch++; - } - return res; -} - -typedef long long ll; -typedef long double ld; -typedef pair pi; -typedef vector vi; -typedef vector vpi; - -#define f first -#define s second -#define sz(x) (int)x.size() -#define all(x) begin(x), end(x) -#define rsz resize -#define bk back() -#define pb push_back -#define ins insert - -#define FOR(i,a,b) for (int i = (a); i < (b); ++i) -#define F0R(i,a) FOR(i,0,a) -#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) -#define R0F(i,a) ROF(i,0,a) -#define trav(a,x) for (auto& a: x) - -const int MOD = 1e9+7; - -template bool ckmin(T& a, const T& b) { - return b < a ? a = b, 1 : 0; } -template bool ckmax(T& a, const T& b) { - return a < b ? a = b, 1 : 0; } - -struct DSU { - vi e; void init(int n) { e = vi(n,-1); } - int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } - bool sameSet(int a, int b) { return get(a) == get(b); } - int size(int x) { return -e[get(x)]; } - bool unite(int x, int y) { // union-by-rank - x = get(x), y = get(y); if (x == y) return 0; - if (e[x] > e[y]) swap(x,y); - e[x] += e[y]; e[y] = x; - return 1; - } -}; - -input in(cin); - -#define gi(a,b) in.get_int(a,b) -#define gl(a,b) in.get_line(a,b) -#define gs() in.get_space() -#define ge() in.get_eol() -#define gt() in.get_token() - - -int main(int argc, char** argv) { - int tc = atoi(argv[1]); // test id - cerr << "TEST #: " << tc << endl; - -#ifndef LOCAL - const int NUM_BATCHES = 5; - vector batches = get_test_case_batches(argc, argv); - cerr << "BATCHES: {"; - for (int i = 0; i < (int)batches.size(); ++i) { - if (i) cerr << ", "; - fassert(0 <= batches[i] && batches[i] < NUM_BATCHES, "invalid batching"); - cerr << batches[i]; - } - cerr << "}\n"; - for (int batch = 0; batch < NUM_BATCHES; ++batch) { - bool contains_batch = find(all(batches),batch) != end(batches); - bool calc_batch = 1; - // modify calc_batch below to actually check whether test is in batch - - fassert(calc_batch == contains_batch); - } -#endif - - in.get_eof(); - cerr << "VALIDATED!" << endl; -} diff --git a/Implementations/content/geometry (13)/Polygons/HalfPlaneSet.h b/Implementations/content/geometry (13)/Polygons/HalfPlaneSet.h new file mode 100644 index 00000000..86719e2a --- /dev/null +++ b/Implementations/content/geometry (13)/Polygons/HalfPlaneSet.h @@ -0,0 +1,85 @@ +/** + * Description: Online Half-Plane Intersection + * Source: retrograd + * Verification: + * https://infoarena.ro/job_detail/2700262?action=view-source + * https://open.kattis.com/problems/bigbrother + */ + +using T = int; +using T2 = long long; +using T4 = __int128_t; +const T2 INF = 2e9; + +struct Line { + T a, b; + T2 c; +}; + +bool operator<(Line m, Line n) { + auto half = [&](Line m) { return m.b < 0 || m.b == 0 && m.a < 0; }; + return make_tuple(half(m), (T2)m.b * n.a) < + make_tuple(half(n), (T2)m.a * n.b); +} +tuple LineIntersection(Line m, Line n) { + T2 d = (T2)m.a * n.b - (T2)m.b * n.a; // assert(d); + T4 x = (T4)m.c * n.b - (T4)m.b * n.c; + T4 y = (T4)m.a * n.c - (T4)m.c * n.a; + return {x, y, d}; +} +Line LineFromPoints(T x1, T y1, T x2, T y2) { + // everything to the right of ray {x1, y1} -> {x2, y2} + T a = y1 - y2, b = x2 - x1; + T2 c = (T2)a * x1 + (T2)b * y1; + return {a, b, c}; // ax + by <= c +} +ostream &operator<<(ostream &out, Line l) { + out << "Line " << l.a << " " << l.b << " " << -l.c; + // out << "(" << l.a << " * x + " << l.b << " * y <= " << l.c << ")"; + return out; +} + +struct HalfplaneSet : multiset { + HalfplaneSet() { + insert({+1, 0, INF}); + insert({0, +1, INF}); + insert({-1, 0, INF}); + insert({0, -1, INF}); + }; + auto adv(auto it, int z) { // z = {-1, +1} + return (z == -1 ? --(it == begin() ? end() : it) + : (++it == end() ? begin() : it)); + } + bool chk(auto it) { + Line l = *it, pl = *adv(it, -1), nl = *adv(it, +1); + auto [x, y, d] = LineIntersection(pl, nl); + T4 sat = l.a * x + l.b * y - (T4)l.c * d; + if (d < 0 && sat < 0) return clear(), 0; // unsat + if ((d > 0 && sat <= 0) || (d == 0 && sat < 0)) return erase(it), 1; + return 0; + } + void Cut(Line l) { // add ax + by <= c + if (empty()) return; + auto it = insert(l); + if (chk(it)) return; + for (int z : {-1, +1}) + while (size() && chk(adv(it, z))) + ; + } + double Maximize(T a, T b) { // max ax + by (UNTESTED) + if (empty()) return -1 / 0.; + auto it = lower_bound({a, b}); + if (it == end()) it = begin(); + auto [x, y, d] = LineIntersection(*adv(it, -1), *it); + return (1.0 * a * x + 1.0 * b * y) / d; + } + double Area() { + double total = 0.; + for (auto it = begin(); it != end(); ++it) { + auto [x1, y1, d1] = LineIntersection(*adv(it, -1), *it); + auto [x2, y2, d2] = LineIntersection(*it, *adv(it, +1)); + total += (1.0 * x1 * y2 - 1.0 * x2 * y1) / d1 / d2; + } + return total * 0.5; + } +}; \ No newline at end of file diff --git a/Implementations/content/geometry (13)/Polygons/HullDiameter.h b/Implementations/content/geometry (13)/Polygons/HullDiameter.h index b5c6b339..83282527 100644 --- a/Implementations/content/geometry (13)/Polygons/HullDiameter.h +++ b/Implementations/content/geometry (13)/Polygons/HullDiameter.h @@ -1,5 +1,6 @@ /** - * Description: rotating caliphers, gives greatest distance between two points in $P$ + * Description: Rotating caliphers. Returns square of greatest distance + * between two points in $P$. * Time: $O(N)$ given convex hull * Source: KACTL * Verification: https://open.kattis.com/problems/roberthood @@ -7,11 +8,11 @@ #include "ConvexHull (13.2).h" -db diameter(vP P) { +db diameter2(vP P) { P = hull(P); - int n = sz(P), ind = 1; db ans = 0; + int n = sz(P), ind = 1; T ans = 0; if (n > 1) F0R(i,n) for (int j = (i+1)%n;;ind = (ind+1)%n) { - ckmax(ans,abs(P[i]-P[ind])); + ckmax(ans, norm(P[i]-P[ind])); if (cross(P[j]-P[i],P[(ind+1)%n]-P[ind]) <= 0) break; } return ans; diff --git a/Implementations/content/geometry (13)/Polygons/MinkowskiSum.h b/Implementations/content/geometry (13)/Polygons/MinkowskiSum.h new file mode 100644 index 00000000..69693766 --- /dev/null +++ b/Implementations/content/geometry (13)/Polygons/MinkowskiSum.h @@ -0,0 +1,40 @@ +/** + * Description: Minkowski sum of two convex polygons given in CCW order. + * Time: O(N) + * Source: https://cp-algorithms.com/geometry/minkowski.html#implementation + * Verification: + * MITPC + * https://open.kattis.com/problems/roberthood + */ + +#include "ConvexHull.h" + +vP minkowski_sum(vP a, vP b) { + if (sz(a) > sz(b)) swap(a, b); + if (!sz(a)) return {}; + if (sz(a) == 1) { + each(t, b) t += a.ft; + return b; + } + rotate(begin(a), min_element(all(a)), end(a)); + rotate(begin(b), min_element(all(b)), end(b)); + a.pb(a[0]), a.pb(a[1]); + b.pb(b[0]), b.pb(b[1]); + vP result; + int i = 0, j = 0; + while (i < sz(a)-2 || j < sz(b)-2) { + result.pb(a[i]+b[j]); + T crs = cross(a[i+1]-a[i],b[j+1]-b[j]); + i += (crs >= 0); + j += (crs <= 0); + } + return result; +} + +T diameter2(vP p) { // example application: squared diameter + vP a = hull(p); + vP b = a; each(t, b) t *= -1; + vP c = minkowski_sum(a, b); + T ret = 0; each(t, c) ckmax(ret, norm(t)); + return ret; +} \ No newline at end of file diff --git a/Implementations/content/geometry (13)/chapter.tex b/Implementations/content/geometry (13)/chapter.tex index 9a6a552b..b9461e1e 100755 --- a/Implementations/content/geometry (13)/chapter.tex +++ b/Implementations/content/geometry (13)/chapter.tex @@ -11,12 +11,14 @@ \section{Polygons} \kactlimport{Polygons/PolygonCenArea.h} \kactlimport{Polygons/InPolygon.h} \kactlimport{Polygons/ConvexHull (13.2).h} + \kactlimport{Polygons/MinkowskiSum.h} \kactlimport{Polygons/HullDiameter.h} - % \kactlimport{Polygons/HullTangents.h} + \kactlimport{Polygons/HullTangents.h} \kactlimport{Polygons/LineHull.h} \kactlimport{Polygons/HalfPlaneIsect.h} - % \kactlimport{Polygons/PolyUnion.java} - % \kactlimport{Polygons/PolygonUnion.kt} + \kactlimport{Polygons/HalfPlaneSet.h} + \kactlimport{Polygons/PolygonUnion.kt} + % \kactlimport{Polygons/PolygonUnion.java} \section{Circles} \kactlimport{Circles/Circle.h} diff --git a/Implementations/content/graphs (12)/DFS/TwoSAT (12.1).h b/Implementations/content/graphs (12)/DFS/TwoSAT (12.1).h index aa75423b..889ca251 100644 --- a/Implementations/content/graphs (12)/DFS/TwoSAT (12.1).h +++ b/Implementations/content/graphs (12)/DFS/TwoSAT (12.1).h @@ -21,7 +21,7 @@ struct TwoSAT { int N = 0; vpi edges; void init(int _N) { N = _N; } - int addVar() { return N++; } // for atMostOne + int addVar() { return N++; } void either(int x, int y) { x = max(2*x,-1-2*x), y = max(2*y,-1-2*y); edges.eb(x,y); } @@ -37,8 +37,7 @@ struct TwoSAT { } either(cur,~li[1]); } - vb solve(int _N = -1) { - if (_N != -1) N = _N; + vb solve() { SCC S; S.init(2*N); each(e,edges) S.ae(e.f^1,e.s), S.ae(e.s^1,e.f); S.gen(); reverse(all(S.comps)); // reverse topo order diff --git a/Implementations/content/number-theory (11.1)/Euclid/ModArith.h b/Implementations/content/number-theory (11.1)/Euclid/ModArith.h index baa7796b..56c01ee6 100644 --- a/Implementations/content/number-theory (11.1)/Euclid/ModArith.h +++ b/Implementations/content/number-theory (11.1)/Euclid/ModArith.h @@ -7,8 +7,6 @@ * Verification: https://codeforces.com/gym/102411/problem/G */ -#include "Euclid.h" - ll minBetween(ll A, ll B, ll L, ll R) { // min x s.t. exists y s.t. L <= A*x-B*y <= R A %= B; diff --git a/Implementations/content/number-theory (11.1)/Modular Arithmetic/ModInt128.h b/Implementations/content/number-theory (11.1)/Modular Arithmetic/ModInt128.h new file mode 100644 index 00000000..edfd1ed4 --- /dev/null +++ b/Implementations/content/number-theory (11.1)/Modular Arithmetic/ModInt128.h @@ -0,0 +1,260 @@ +/** + * Description: modular arithmetic operations + * Source: tourist + */ + +template T inverse(T a, T m) { + T u = 0, v = 1; + while (a != 0) { + T t = m / a; + m -= t * a; + swap(a, m); + u -= t * v; + swap(u, v); + } + assert(m == 1); + return u; +} + +template class Modular { +public: + using Type = typename decay::type; + + constexpr Modular() : value() {} + template Modular(const U &x) { value = normalize(x); } + + template static Type normalize(const U &x) { + Type v; + if (-mod() <= x && x < mod()) + v = static_cast(x); + else + v = static_cast(x % mod()); + if (v < 0) + v += mod(); + return v; + } + + const Type &operator()() const { return value; } + template explicit operator U() const { + return static_cast(value); + } + constexpr static Type mod() { return T::value; } + + Modular &operator+=(const Modular &other) { + if ((value += other.value) >= mod()) + value -= mod(); + return *this; + } + Modular &operator-=(const Modular &other) { + if ((value -= other.value) < 0) + value += mod(); + return *this; + } + template Modular &operator+=(const U &other) { + return *this += Modular(other); + } + template Modular &operator-=(const U &other) { + return *this -= Modular(other); + } + Modular &operator++() { return *this += 1; } + Modular &operator--() { return *this -= 1; } + Modular operator++(int) { + Modular result(*this); + *this += 1; + return result; + } + Modular operator--(int) { + Modular result(*this); + *this -= 1; + return result; + } + Modular operator-() const { return Modular(-value); } + + template + typename enable_if::Type, int>::value, + Modular>::type & + operator*=(const Modular &rhs) { +#ifdef _WIN32 + uint64_t x = static_cast(value) * static_cast(rhs.value); + uint32_t xh = static_cast(x >> 32), xl = static_cast(x), + d, m; + asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod())); + value = m; +#else + value = normalize(static_cast(value) * + static_cast(rhs.value)); +#endif + return *this; + } + template + typename enable_if::Type, long long>::value, + Modular>::type & + operator*=(const Modular &rhs) { + /* long long q = static_cast(static_cast(value) * + rhs.value / mod()); value = normalize(value * rhs.value - q * + mod());*/ + value = (long long)((__int128)value * rhs.value % mod()); + return *this; + } + template + typename enable_if::Type>::value, + Modular>::type & + operator*=(const Modular &rhs) { + value = normalize(value * rhs.value); + return *this; + } + + Modular &operator/=(const Modular &other) { + return *this *= Modular(inverse(other.value, mod())); + } + + friend const Type &abs(const Modular &x) { return x.value; } + + template + friend bool operator==(const Modular &lhs, const Modular &rhs); + + template + friend bool operator<(const Modular &lhs, const Modular &rhs); + + template + friend V &operator>>(V &stream, Modular &number); + +private: + Type value; +}; + +template +bool operator==(const Modular &lhs, const Modular &rhs) { + return lhs.value == rhs.value; +} +template +bool operator==(const Modular &lhs, U rhs) { + return lhs == Modular(rhs); +} +template +bool operator==(U lhs, const Modular &rhs) { + return Modular(lhs) == rhs; +} + +template +bool operator!=(const Modular &lhs, const Modular &rhs) { + return !(lhs == rhs); +} +template +bool operator!=(const Modular &lhs, U rhs) { + return !(lhs == rhs); +} +template +bool operator!=(U lhs, const Modular &rhs) { + return !(lhs == rhs); +} + +template +bool operator<(const Modular &lhs, const Modular &rhs) { + return lhs.value < rhs.value; +} + +template +Modular operator+(const Modular &lhs, const Modular &rhs) { + return Modular(lhs) += rhs; +} +template +Modular operator+(const Modular &lhs, U rhs) { + return Modular(lhs) += rhs; +} +template +Modular operator+(U lhs, const Modular &rhs) { + return Modular(lhs) += rhs; +} + +template +Modular operator-(const Modular &lhs, const Modular &rhs) { + return Modular(lhs) -= rhs; +} +template +Modular operator-(const Modular &lhs, U rhs) { + return Modular(lhs) -= rhs; +} +template +Modular operator-(U lhs, const Modular &rhs) { + return Modular(lhs) -= rhs; +} + +template +Modular operator*(const Modular &lhs, const Modular &rhs) { + return Modular(lhs) *= rhs; +} +template +Modular operator*(const Modular &lhs, U rhs) { + return Modular(lhs) *= rhs; +} +template +Modular operator*(U lhs, const Modular &rhs) { + return Modular(lhs) *= rhs; +} + +template +Modular operator/(const Modular &lhs, const Modular &rhs) { + return Modular(lhs) /= rhs; +} +template +Modular operator/(const Modular &lhs, U rhs) { + return Modular(lhs) /= rhs; +} +template +Modular operator/(U lhs, const Modular &rhs) { + return Modular(lhs) /= rhs; +} + +template +Modular power(const Modular &a, const U &b) { + assert(b >= 0); + Modular x = a, res = 1; + U p = b; + while (p > 0) { + if (p & 1) + res *= x; + x *= x; + p >>= 1; + } + return res; +} + +template bool IsZero(const Modular &number) { + return number() == 0; +} + +template string to_string(const Modular &number) { + return to_string(number()); +} + +// U == std::ostream? but done this way because of fastoutput +template +U &operator<<(U &stream, const Modular &number) { + return stream << number(); +} + +// U == std::istream? but done this way because of fastinput +template U &operator>>(U &stream, Modular &number) { + typename common_type::Type, long long>::type x; + stream >> x; + number.value = Modular::normalize(x); + return stream; +} + +/* +using ModType = int; + +struct VarMod { static ModType value; }; +ModType VarMod::value; +ModType& md = VarMod::value; +using Mint = Modular; +*/ + +constexpr long long md = (1LL << 61) - 1; +using Mint = Modular::type, md>>; + +mt19937_64 + rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count()); + +Mint step = (md >> 2) + rng() % (md >> 1); \ No newline at end of file diff --git a/Implementations/content/numerical/Matrix (11.3)/MatrixTree.h b/Implementations/content/numerical/Matrix (11.3)/MatrixTree.h index 497d4e26..0c1dfbc8 100644 --- a/Implementations/content/numerical/Matrix (11.3)/MatrixTree.h +++ b/Implementations/content/numerical/Matrix (11.3)/MatrixTree.h @@ -2,13 +2,13 @@ * Description: Kirchhoff's Matrix Tree Theorem. * Given adjacency matrix, calculates \# of spanning trees. * Source: various - * Verification: SPOJ MIFF (matrix inverse modulo prime) + * Verification: TC Finals 2022 1000 */ #include "MatrixInv.h" -T numSpan(Mat m) { - int n = sz(m); Mat res(n-1,n-1); +T numSpan(const Mat& m) { + int n = sz(m); Mat res = makeMat(n-1,n-1); F0R(i,n) FOR(j,i+1,n) { mi ed = m[i][j]; res[i][i] += ed; if (j != n-1) { diff --git a/Implementations/content/various/Decimal.py b/Implementations/content/various/Decimal.py index 73016a8e..04a311c0 100644 --- a/Implementations/content/various/Decimal.py +++ b/Implementations/content/various/Decimal.py @@ -1,10 +1,10 @@ /** * Description: Arbitrary-precision decimals + * Source: https://docs.python.org/3/library/decimal.html */ from decimal import * -ctx = getcontext() -ctx.prec = 28 -print(Decimal(1) / Decimal(7)) # 0.1428571428571428571428571429 -print(ctx.power(Decimal(10),-30)) # 1E-30 \ No newline at end of file +getcontext().prec = 100 # how many digits of precision +print(Decimal(1) / Decimal(7)) # 0.142857142857... +print(Decimal(10) ** -100) # 1E-100 \ No newline at end of file diff --git a/Implementations/content/various/FastIO.h b/Implementations/content/various/FastIO.h index 6ee2c75f..247c8ee2 100644 --- a/Implementations/content/various/FastIO.h +++ b/Implementations/content/various/FastIO.h @@ -1,10 +1,12 @@ /** - * Description: Fast input and output. - * Time: input is $\sim$300ms faster for $10^6$ long longs on CF + * Description: Fast input and output for integers and strings. For doubles, read them + * as strings and convert them to double using \texttt{stod}. + * Time: input is $\sim$300ms faster for $10^6$ long longs on CF. * Source: * https://codeforces.com/gym/102394/submission/64154785 * https://codeforces.com/contest/1254/submission/65420506 (neal) * https://codeforces.com/blog/entry/45835 (AI.Cash) + * https://codeforces.com/blog/entry/93706 (double input) * Verification: https://codeforces.com/gym/102394/problem/G * Usage: initO(); int a,b; ri(a,b); wi(b,'\textbackslash n'); wi(a,'\textbackslash n'); */