diff --git a/fontes/extgcd.h b/fontes/extgcd.h index 546bfff8bb068ba636c3a29aef7f1ef43398877f..61b6a6cb42df1b156e8ae78629a9456bedde2483 100644 --- a/fontes/extgcd.h +++ b/fontes/extgcd.h @@ -12,7 +12,7 @@ ll inv(ll a, ll m) { vector<ll> invall (N); void calc() { - allinv[1] = 1; + invall[1] = 1; for (int i = 2; i < N; i++) invall[i] = P - P / i * invall[P % i] % P; } diff --git a/fontes/freq-freq.h b/fontes/freq-freq.h index e21ddf0af515c4b4d06bd3ecc60ec0b5ef594b61..5d03eeeec7688c85bb7bb273eadd33a6b852d233 100644 --- a/fontes/freq-freq.h +++ b/fontes/freq-freq.h @@ -1,11 +1,11 @@ -vector<int> hvy (N), cnt (C), freqfreq (N); -vector<ll> c (N), sumfreq (N); +vector<int> cnt (C), freqfreq (N); +vector<ll> sumfreq (N); int mf = 0; -freqfreq[cnt[c[u]]]--; -if (cnt[c[u]]) { sumfreq[cnt[c[u]]] -= c[u]; } -cnt[c[u]] += x; -if (cnt[c[u]]) { sumfreq[cnt[c[u]]] += c[u]; } -freqfreq[cnt[c[u]]]++; +freqfreq[cnt[w]]--; +if (cnt[w]) { sumfreq[cnt[w]] -= w; } +cnt[w] += x; +if (cnt[w]) { sumfreq[cnt[w]] += w; } +freqfreq[cnt[w]]++; if (freqfreq[mf+1]) { mf++; } if (mf > 0 && freqfreq[mf] == 0) { mf--; } diff --git a/fontes/hld.h b/fontes/hld.h index 9febdd92b860fe5ed324a84caa82b5d7a7eeb9fe..73d19f0532bbfdeb00df81f23a224406cbc23c27 100644 --- a/fontes/hld.h +++ b/fontes/hld.h @@ -31,6 +31,6 @@ ll hld_op(int u, int v, bool edge_wei = 1) { return OP(ans, op_inclusive(ixs[u] + edge_wei, ixs[v])); } -void hld_init(int u) { - cix = 1; hld_fill(u, u); hld(u, u); build(ori); +void hld_init(int u, int n) { + cix = 1; hld_fill(u, u); hld(u, u); build(ori, n); } diff --git a/fontes/kd-tree.h b/fontes/kd-tree.h index 60cea2552a7322393bc0b8a818823d743d3200da..469eec845f0a6a8a2e971774bd9e17c42c509924 100644 --- a/fontes/kd-tree.h +++ b/fontes/kd-tree.h @@ -3,8 +3,7 @@ int get_ii(pt pair, int ix) { else { return pair.py; } } -class kdtree { - private: +struct kdtree { struct node { node(pt& p) : p(p), left(nullptr), right(nullptr) {} double dist_sq(const pt& o) { return norm(o - p); } @@ -17,7 +16,7 @@ class kdtree { struct node_cmp { node_cmp(size_t _index) : ix(_index) {} bool operator()(const node& n1, const node& n2) { - return get_ii(n1.point, ix) < get_ii(n2.point, ix); + return get_ii(n1.p, ix) < get_ii(n2.p, ix); } size_t ix; }; @@ -53,7 +52,6 @@ class kdtree { nearest_k(dx > 0 ? r->right : r->left, p, ix, k); } - public: template<typename iterator> kdtree(iterator begin, iterator end) : t(begin, end) { root = make_tree(0, t.size(), 0); diff --git a/fontes/lstit.h b/fontes/lstit.h index 02cb98989ad21fa717c765e217a85f0255f9122e..205959c2b99df0e1a15f7c960dddb0ff0e417ada 100644 --- a/fontes/lstit.h +++ b/fontes/lstit.h @@ -2,10 +2,10 @@ const int L = ceil(log2(N)); struct dlta { int add = 0, set = -1; }; vector<ll> t (2*N); vector<dlta> delta (2*N); -void build(vector<int>& src) { +void build(vector<int>& src, int n) { for (int i = 1; i < src.size(); i++) t[N+i] = src[i]; - for (int ti = N-1; ti > 0; ti--) + for (int ti = n-1; ti > 0; ti--) t[ti] = OP(t[2*ti], t[2*ti+1]); } @@ -38,13 +38,13 @@ void push(int i) { } } -void apply_inclusive(int l, int r, +void apply_inclusive(int l, int r, int n, char op = '\0', ll x = 0) { r++; dlta d; if (op == '+') { d.add = x; } if (op == '=') { d.set = x; } - int tl = l += N, tr = r += N, sz = 1; + int tl = l += n, tr = r += n, sz = 1; push(tl); push(tr); for (; l < r; l /= 2, r /= 2, sz *= 2) { if (l & 1) { apply(l++, d, sz); } @@ -57,9 +57,9 @@ void add_inclusive(int l, int r, ll d) { apply_inclusive(l, r, '+', d); } -ll op_inclusive(int l, int r) { +ll op_inclusive(int l, int r, int n) { r++; - int tl = l += N, tr = r += N, sz = 1; + int tl = l += n, tr = r += n, sz = 1; push(tl); push(tr); ll ans = NEUTRAL; for (; l < r; l /= 2, r /= 2, sz *= 2) { diff --git a/fontes/point.h b/fontes/point.h index 968b9802ba7f587ce3b1e92c3513ed7a185bd75a..62ef593fa41c338a94b86dca31499c15c1aca3f9 100644 --- a/fontes/point.h +++ b/fontes/point.h @@ -6,8 +6,8 @@ double cross(pt a, pt b) { return (conj(a) * b).py; } pt vec(pt a, pt b) { return b - a; } int sgn(double v) { return (v > -EPS) - (v < EPS); } // -1 (cw), 0 (colinear), +1 (ccw) -int seg_ornt(pt a, pt b, pt c) { - return sgn(cross(vec(a, b), vec(a, c))); +int seg_ornt(pt p, pt a, pt b) { + return sgn(cross(vec(p, a), vec(p, b))); } int ccw(pt a, pt b, pt c, bool col) { int o = seg_ornt(a, b, c); diff --git a/fontes/stit.h b/fontes/stit.h index 8ce8562d549e300372cc5b399c666da5bdb0b9a9..aebf9b9d5fb149e2aeec3ae773c29c1fc6bef5ae 100644 --- a/fontes/stit.h +++ b/fontes/stit.h @@ -1,24 +1,24 @@ vector<int> t (2*N); -void build(vector<int>& src) { +void build(vector<int>& src, int n) { for (int i = 1; i < src.size(); i++) t[N+i] = src[i]; - for (int i = N-1; i > 0; i--) + for (int i = n-1; i > 0; i--) t[i] = OP(t[2*i], t[2*i+1]); } -int op_inclusive(int l, int r) { +int op_inclusive(int l, int r, int n) { r++; int left = NEUTRAL, right = NEUTRAL; - for (l += N, r += N; l < r; l /= 2, r /= 2) { + for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l & 1) left = OP(left, t[l++]); if (r & 1) right = OP(right, t[--r]); } return OP(left, right); } -void set_value(int i, int v) { - t[i += N] = v; +void set_value(int i, int v, int n) { + t[i += n] = v; for (i /= 2; i > 0; i /= 2) t[i] = OP(t[i*2], t[i*2+1]); } diff --git a/fontes/stress.sh b/fontes/stress.sh index 8e01a861828e73071cff997380f073ba3c581b27..cbc8222ccfa94d8685127f3709cf5a30eee9953f 100644 --- a/fontes/stress.sh +++ b/fontes/stress.sh @@ -1,11 +1,11 @@ for (( I=0; I < 5; I++ )); do - ./gen $I >a.in - ./brute <a.in >a.exp - ./a.out <a.in >a.out - if diff -u a.exp a.out; then : ; else - echo "--> entrada:"; cat a.in - echo "--> saída esperada"; cat a.exp - echo "--> saída obtida"; cat a.out + ./gen $I >t.in + ./brute <t.in >t.exp + ./a.out <t.in >t.out + if diff -u t.exp t.out; then : ; else + echo "--> entrada:"; cat t.in + echo "--> saída esperada"; cat t.exp + echo "--> saída obtida"; cat t.out break fi echo -n . diff --git a/fontes/template.cpp b/fontes/template.cpp index 0626c8c8504e8bc0f0c6ccc5552c1a7f93df11dd..151052969f9fde75a239a59eabec1e5095dddd9e 100644 --- a/fontes/template.cpp +++ b/fontes/template.cpp @@ -6,5 +6,5 @@ using namespace std; using ll = long long; #define _(X) {cerr << #X << " = " << X << " ";} int main() { - ios::sync_with_stdio(0); cin.tie(0); + cin.tie(0)->sync_with_stdio(0); }