Skip to content

Commit

Permalink
Change all ints by ll
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRenison committed Mar 1, 2024
1 parent 28ef41a commit 9b9c520
Show file tree
Hide file tree
Showing 222 changed files with 1,396 additions and 1,396 deletions.
6 changes: 3 additions & 3 deletions content/combinatorial/IntPerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
#pragma once

int permToInt(vi& v) {
int use = 0, i = 0, r = 0;
for(int x:v) r = r * ++i + __builtin_popcount(use & -(1<<x)),
ll permToInt(vi& v) {
ll use = 0, i = 0, r = 0;
for(ll x:v) r = r * ++i + __builtin_popcount(use & -(1<<x)),
use |= 1 << x; // (note: minus, not ~!)
return r;
}
10 changes: 5 additions & 5 deletions content/contest/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ using namespace std;
#define fst first
#define snd second
#define pb push_back
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rep(i, a, b) for (ll i = a; i < (b); i++)
#define fore(i, a, b) for (ll i = a, gmat = b; i < gmat; i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define sz(x) (ll)(x).size()
#define ALL(x) begin(x), end(x)
#define SZ(x) (ll)(x).size()
#define mset(a, v) memset((a), (v), sizeof(a))
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;

int main() {
ll main() {
cin.tie(0)->sync_with_stdio(0);

}
12 changes: 6 additions & 6 deletions content/data-structures/FenwickTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

struct FT {
vector<ll> s;
FT(int n) : s(n) {}
void update(int pos, ll dif) { // a[pos] += dif
FT(ll n) : s(n) {}
void update(ll pos, ll dif) { // a[pos] += dif
for (; pos < sz(s); pos |= pos + 1) s[pos] += dif;
}
ll query(int pos) { // sum of values in [0, pos)
ll query(ll pos) { // sum of values in [0, pos)
ll res = 0;
for (; pos > 0; pos &= pos - 1) res += s[pos-1];
return res;
}
int lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum
ll lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum
// Returns n if no sum is >= sum, or -1 if empty sum is.
if (sum <= 0) return -1;
int pos = 0;
for (int pw = 1 << 25; pw; pw >>= 1) {
ll pos = 0;
for (ll pw = 1 << 25; pw; pw >>= 1) {
if (pos + pw <= sz(s) && s[pos + pw-1] < sum)
pos += pw, sum -= s[pos-1];
}
Expand Down
12 changes: 6 additions & 6 deletions content/data-structures/FenwickTree2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@

struct FT2 {
vector<vi> ys; vector<FT> ft;
FT2(int limx) : ys(limx) {}
void fakeUpdate(int x, int y) {
FT2(ll limx) : ys(limx) {}
void fakeUpdate(ll x, ll y) {
for (; x < sz(ys); x |= x + 1) ys[x].push_back(y);
}
void init() {
for (vi& v : ys) sort(all(v)), ft.emplace_back(sz(v));
}
int ind(int x, int y) {
return (int)(lower_bound(all(ys[x]), y) - ys[x].begin()); }
void update(int x, int y, ll dif) {
ll ind(ll x, ll y) {
return (ll)(lower_bound(all(ys[x]), y) - ys[x].begin()); }
void update(ll x, ll y, ll dif) {
for (; x < sz(ys); x |= x + 1)
ft[x].update(ind(x, y), dif);
}
ll query(int x, int y) {
ll query(ll x, ll y) {
ll sum = 0;
for (; x; x &= x - 1)
sum += ft[x-1].query(ind(x-1, y));
Expand Down
6 changes: 3 additions & 3 deletions content/data-structures/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ struct chash { // large odd number for C
const uint64_t C = ll(4e18 * acos(0)) | 71;
ll operator()(ll x) const { return __builtin_bswap64(x*C); }
};
__gnu_pbds::gp_hash_table<ll,int,chash> h({},{},{},{},{1<<16});
__gnu_pbds::gp_hash_table<ll,ll,chash> h({},{},{},{},{1<<16});

/** For CodeForces, or other places where hacking might be a problem:
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash { // To use most bits rather than just the lowest ones:
const uint64_t C = ll(4e18 * acos(0)) | 71; // large odd number
ll operator()(ll x) const { return __builtin_bswap64((x^RANDOM)*C); }
};
__gnu_pbds::gp_hash_table<ll, int, chash> h({},{},{},{}, {1 << 16});
__gnu_pbds::gp_hash_table<ll, ll, chash> h({},{},{},{}, {1 << 16});
*/
24 changes: 12 additions & 12 deletions content/data-structures/LazySegmentTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#include "../various/BumpAllocator.h"

const int inf = 1e9;
const ll inf = 1e9;
struct Node {
typedef int T; // data type
struct L { int mset, madd; }; // lazy type
typedef ll T; // data type
struct L { ll mset, madd; }; // lazy type
const T tneut = -inf; // neutral elements
const L lneut = {inf, 0};
T f (T a, T b) { return max(a, b); } // (any associative fn)
Expand All @@ -30,35 +30,35 @@ struct Node {
} // Combine lazy

Node *l = 0, *r = 0;
int lo, hi; T val = tneut; L lazy = lneut;
Node(int lo,int hi):lo(lo),hi(hi){}//Large interval of tneut
Node(vector<T>& v, int lo, int hi) : lo(lo), hi(hi) {
ll lo, hi; T val = tneut; L lazy = lneut;
Node(ll lo,ll hi):lo(lo),hi(hi){}//Large interval of tneut
Node(vector<T>& v, ll lo, ll hi) : lo(lo), hi(hi) {
if (lo + 1 < hi) {
int mid = lo + (hi - lo)/2;
ll mid = lo + (hi - lo)/2;
l = new Node(v, lo, mid); r = new Node(v, mid, hi);
val = f(l->val, r->val);
}
else val = v[lo];
}
T query(int L, int R) {
T query(ll L, ll R) {
if (R <= lo || hi <= L) return tneut;
if (L <= lo && hi <= R) return apply(val, lazy);
push();
return f(l->query(L, R), r->query(L, R));
}
void upd(int Le, int Ri, L x) {
void upd(ll Le, ll Ri, L x) {
if (Ri <= lo || hi <= Le) return;
if (Le <= lo && hi <= Ri) lazy = comb(lazy, x);
else {
push(), l->upd(Le, Ri, x), r->upd(Le, Ri, x);
val = f(l->query(lo, hi), r->query(lo, hi));
}
}
void set(int L, int R, int x) { upd(L, R, {x, 0}); }
void add(int L, int R, int x) { upd(L, R, {inf, x}); }
void set(ll L, ll R, ll x) { upd(L, R, {x, 0}); }
void add(ll L, ll R, ll x) { upd(L, R, {inf, x}); }
void push() {
if (!l) {
int mid = lo + (hi - lo)/2;
ll mid = lo + (hi - lo)/2;
l = new Node(lo, mid), r = new Node(mid, hi);
}
l->lazy = comb(l->lazy, lazy);
Expand Down
6 changes: 3 additions & 3 deletions content/data-structures/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* License: CC0
* Source: My head
* Description: Basic operations on square matrices.
* Usage: Matrix<int, 3> A;
* Usage: Matrix<ll, 3> A;
* A.d = {{{{1,2,3}}, {{4,5,6}}, {{7,8,9}}}};
* vector<int> vec = {1,2,3};
* vector<ll> vec = {1,2,3};
* vec = (A^N) * vec;
* Status: tested
*/
#pragma once

template<class T, int N> struct Matrix {
template<class T, ll N> struct Matrix {
typedef Matrix M;
array<array<T, N>, N> d{};
M operator*(const M& m) const {
Expand Down
26 changes: 13 additions & 13 deletions content/data-structures/MoQueries.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
*/
#pragma once

void add(int ind, int end) { ... } // add a[ind] (end = 0 or 1)
void del(int ind, int end) { ... } // remove a[ind]
int calc() { ... } // compute current answer
void add(ll ind, ll end) { ... } // add a[ind] (end = 0 or 1)
void del(ll ind, ll end) { ... } // remove a[ind]
ll calc() { ... } // compute current answer

vi mo(vector<pii> Q) {
int L = 0, R = 0, blk = 350; // ~N/sqrt(Q)
ll L = 0, R = 0, blk = 350; // ~N/sqrt(Q)
vi s(sz(Q)), res = s;
#define K(x) pii(x.first/blk, x.second ^ -(x.first/blk & 1))
iota(all(s), 0);
sort(all(s), [&](int s, int t){ return K(Q[s]) < K(Q[t]); });
for (int qi : s) {
sort(all(s), [&](ll s, ll t){ return K(Q[s]) < K(Q[t]); });
for (ll qi : s) {
pii q = Q[qi];
while (L > q.first) add(--L, 0);
while (R < q.second) add(R++, 1);
Expand All @@ -32,24 +32,24 @@ vi mo(vector<pii> Q) {
return res;
}

vi moTree(vector<array<int, 2>> Q, vector<vi>& ed, int root=0){
int N = sz(ed), pos[2] = {}, blk = 350; // ~N/sqrt(Q)
vi moTree(vector<array<ll, 2>> Q, vector<vi>& ed, ll root=0){
ll N = sz(ed), pos[2] = {}, blk = 350; // ~N/sqrt(Q)
vi s(sz(Q)), res = s, I(N), L(N), R(N), in(N), par(N);
add(0, 0), in[0] = 1;
auto dfs = [&](int x, int p, int dep, auto& f) -> void {
auto dfs = [&](ll x, ll p, ll dep, auto& f) -> void {
par[x] = p;
L[x] = N;
if (dep) I[x] = N++;
for (int y : ed[x]) if (y != p) f(y, x, !dep, f);
for (ll y : ed[x]) if (y != p) f(y, x, !dep, f);
if (!dep) I[x] = N++;
R[x] = N;
};
dfs(root, -1, 0, dfs);
#define K(x) pii(I[x[0]] / blk, I[x[1]] ^ -(I[x[0]] / blk & 1))
iota(all(s), 0);
sort(all(s), [&](int s, int t){ return K(Q[s]) < K(Q[t]); });
for (int qi : s) rep(end,0,2) {
int &a = pos[end], b = Q[qi][end], i = 0;
sort(all(s), [&](ll s, ll t){ return K(Q[s]) < K(Q[t]); });
for (ll qi : s) rep(end,0,2) {
ll &a = pos[end], b = Q[qi][end], i = 0;
#define step(c) { if (in[c]) { del(a, end); in[a] = 0; } \
else { add(c, end); in[c] = 1; } a = c; }
while (!(L[b] <= L[a] && R[a] <= R[b]))
Expand Down
2 changes: 1 addition & 1 deletion content/data-structures/OrderStatisticTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using Tree = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

void example() {
Tree<int> t, t2; t.insert(8);
Tree<ll> t, t2; t.insert(8);
auto it = t.insert(10).first;
assert(it == t.lower_bound(9));
assert(t.order_of_key(10) == 1);
Expand Down
6 changes: 3 additions & 3 deletions content/data-structures/RMQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ template<class T>
struct RMQ {
vector<vector<T>> jmp;
RMQ(const vector<T>& V) : jmp(1, V) {
for (int pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k) {
for (ll pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k) {
jmp.emplace_back(sz(V) - pw * 2 + 1);
rep(j,0,sz(jmp[k]))
jmp[k][j] = min(jmp[k - 1][j], jmp[k - 1][j + pw]);
}
}
T query(int a, int b) {
T query(ll a, ll b) {
assert(a < b); // or return inf if a == b
int dep = 31 - __builtin_clz(b - a);
ll dep = 31 - __builtin_clz(b - a);
return min(jmp[dep][a], jmp[dep][b - (1 << dep)]);
}
};
10 changes: 5 additions & 5 deletions content/data-structures/SegmentTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
#pragma once

struct Tree {
typedef int T;
typedef ll T;
static constexpr T unit = INT_MIN;
T f(T a, T b) { return max(a, b); } // (any associative fn)
vector<T> s; int n;
Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
void update(int pos, T val) {
vector<T> s; ll n;
Tree(ll n = 0, T def = unit) : s(2*n, def), n(n) {}
void update(ll pos, T val) {
for (s[pos += n] = val; pos /= 2;)
s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
}
T query(int b, int e) { // query [b, e)
T query(ll b, ll e) { // query [b, e)
T ra = unit, rb = unit;
for (b += n, e += n; b < e; b /= 2, e /= 2) {
if (b % 2) ra = f(ra, s[b++]);
Expand Down
6 changes: 3 additions & 3 deletions content/data-structures/SubMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Source: Folklore
* Description: Calculate submatrix sums quickly, given upper-left and lower-right corners (half-open).
* Usage:
* SubMatrix<int> m(matrix);
* SubMatrix<ll> m(matrix);
* m.sum(0, 0, 2, 2); // top left 4 elements
* Time: O(N^2 + Q)
* Status: Tested on Kattis
Expand All @@ -16,12 +16,12 @@ template<class T>
struct SubMatrix {
vector<vector<T>> p;
SubMatrix(vector<vector<T>>& v) {
int R = sz(v), C = sz(v[0]);
ll R = sz(v), C = sz(v[0]);
p.assign(R+1, vector<T>(C+1));
rep(r,0,R) rep(c,0,C)
p[r+1][c+1] = v[r][c] + p[r][c+1] + p[r+1][c] - p[r][c];
}
T sum(int u, int l, int d, int r) {
T sum(ll u, ll l, ll d, ll r) {
return p[d][r] - p[d][l] - p[u][r] + p[u][l];
}
};
12 changes: 6 additions & 6 deletions content/data-structures/Treap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@

struct Node {
Node *l = 0, *r = 0;
int val, y, c = 1;
Node(int val) : val(val), y(rand()) {}
ll val, y, c = 1;
Node(ll val) : val(val), y(rand()) {}
void recalc();
};

int cnt(Node* n) { return n ? n->c : 0; }
ll cnt(Node* n) { return n ? n->c : 0; }
void Node::recalc() { c = cnt(l) + cnt(r) + 1; }

template<class F> void each(Node* n, F f) {
if (n) { each(n->l, f); f(n->val); each(n->r, f); }
}

pair<Node*, Node*> split(Node* n, int k) {
pair<Node*, Node*> split(Node* n, ll k) {
if (!n) return {};
if (cnt(n->l) >= k) { // "n->val >= k" for lower_bound(k)
auto pa = split(n->l, k);
Expand Down Expand Up @@ -53,13 +53,13 @@ Node* merge(Node* l, Node* r) {
}
}

Node* ins(Node* t, Node* n, int pos) {
Node* ins(Node* t, Node* n, ll pos) {
auto pa = split(t, pos);
return merge(merge(pa.first, n), pa.second);
}

// Example application: move the range [l, r) to index k
void move(Node*& t, int l, int r, int k) {
void move(Node*& t, ll l, ll r, ll k) {
Node *a, *b, *c;
tie(a,b) = split(t, l); tie(b,c) = split(b, r - l);
if (k <= l) t = merge(ins(a, b, k), c);
Expand Down
10 changes: 5 additions & 5 deletions content/data-structures/UnionFind.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

struct UF {
vi e;
UF(int n) : e(n, -1) {}
bool sameSet(int a, int b) { return find(a) == find(b); }
int size(int x) { return -e[find(x)]; }
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
UF(ll n) : e(n, -1) {}
bool sameSet(ll a, ll b) { return find(a) == find(b); }
ll size(ll x) { return -e[find(x)]; }
ll find(ll x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(ll a, ll b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
Expand Down
Loading

0 comments on commit 9b9c520

Please sign in to comment.