1
0
Fork 0

Update include.hh

This commit is contained in:
Ariel 2024-01-16 16:05:34 +08:00 committed by GitHub
parent 2333a23577
commit 9f8d20e18f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 7 deletions

View File

@ -1,6 +1,14 @@
/////////////////////////////////////////////////////////
/**
* Useful Macros
* by subcrip
* (requires C++17)
*/
#include<bits/stdc++.h> #include<bits/stdc++.h>
using namespace std; using namespace std;
/* macro helpers */
#define __NARGS(...) std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value #define __NARGS(...) std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value
#define __DECOMPOSE_S(a, x) auto x = a; #define __DECOMPOSE_S(a, x) auto x = a;
#define __DECOMPOSE_N(a, ...) auto [__VA_ARGS__] = a; #define __DECOMPOSE_N(a, ...) auto [__VA_ARGS__] = a;
@ -8,6 +16,7 @@ constexpr void __() {}
#define __AS_PROCEDURE(...) __(); __VA_ARGS__; __() #define __AS_PROCEDURE(...) __(); __VA_ARGS__; __()
#define __as_typeof(container) decltype(container)::value_type #define __as_typeof(container) decltype(container)::value_type
/* type aliases */
using ll = int64_t; using ll = int64_t;
using ull = uint64_t; using ull = uint64_t;
using pii = pair<int, int>; using pii = pair<int, int>;
@ -15,17 +24,20 @@ using pil = pair<int, ll>;
using pli = pair<ll, int>; using pli = pair<ll, int>;
using pll = pair<ll, ll>; using pll = pair<ll, ll>;
/* constants */
constexpr ull MDL = 1e9 + 7; constexpr ull MDL = 1e9 + 7;
constexpr ull PRIME = 998244353; constexpr ull PRIME = 998244353;
constexpr ull MDL1 = 825; constexpr ull MDL1 = 825;
constexpr ull MDL2 = 87825; constexpr ull MDL2 = 87825;
/* bit-wise operations */
#define lowbit(x) ((x) & -(x)) #define lowbit(x) ((x) & -(x))
#define popcount(x) (__builtin_popcountll(ll(x))) #define popcount(x) (__builtin_popcountll(ll(x)))
#define parity(x) (__builtin_parityll(ll(x))) #define parity(x) (__builtin_parityll(ll(x)))
#define msp(x) (63LL - __builtin_clzll(ll(x))) #define msp(x) (63LL - __builtin_clzll(ll(x)))
#define lsp(x) (__builtin_ctzll(ll(x))) #define lsp(x) (__builtin_ctzll(ll(x)))
/* fast pairs */
#define upair ull #define upair ull
#define umake(x, y) (ull(x) << 32 | ull(y)) #define umake(x, y) (ull(x) << 32 | ull(y))
#define u1(p) ((p) >> 32) #define u1(p) ((p) >> 32)
@ -50,8 +62,21 @@ struct igt {
} }
}; };
/* conditions */
#define loop while (1)
#define continue_or(var, val) __AS_PROCEDURE(if (var == val) continue; var = val;)
#define break_or(var, val) __AS_PROCEDURE(if (var == val) break; var = val;)
/* build data structures */
#define unordered_counter(from, to) __AS_PROCEDURE(unordered_map<__as_typeof(from), size_t> to; for (auto&& x : from) ++to[x];) #define unordered_counter(from, to) __AS_PROCEDURE(unordered_map<__as_typeof(from), size_t> to; for (auto&& x : from) ++to[x];)
#define counter(from, to, cmp) __AS_PROCEDURE(map<__as_typeof(from), size_t, cmp> to; for (auto&& x : from) ++to[x];) #define counter(from, to, cmp) __AS_PROCEDURE(map<__as_typeof(from), size_t, cmp> to; for (auto&& x : from) ++to[x];)
#define pa(a) __AS_PROCEDURE(__typeof(a) pa; pa.push_back({}); for (auto&&x : a) pa.push_back(pa.back() + x);)
#define sa(a) __AS_PROCEDURE(__typeof(a) sa(a.size() + 1); {int n = a.size(); for (int i = n - 1; i >= 0; --i) sa[i] = sa[i + 1] + a[i];};)
#define adj(ch, n) __AS_PROCEDURE(vector<vector<int>> ch((n) + 1);)
#define edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v), ch[v].push_back(u);)
#define Edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v);)
/* io */
#define untie __AS_PROCEDURE(ios_base::sync_with_stdio(0), cin.tie(NULL)) #define untie __AS_PROCEDURE(ios_base::sync_with_stdio(0), cin.tie(NULL))
template<typename T> void __read(T& x) { cin >> x; } template<typename T> void __read(T& x) { cin >> x; }
template<typename T, typename... U> void __read(T& x, U&... args) { cin >> x; __read(args...); } template<typename T, typename... U> void __read(T& x, U&... args) { cin >> x; __read(args...); }
@ -61,17 +86,12 @@ template<typename T, typename... U> void __read(T& x, U&... args) { cin >> x; __
#define debug(x) __AS_PROCEDURE(cerr << #x" = " << x << endl;) #define debug(x) __AS_PROCEDURE(cerr << #x" = " << x << endl;)
#define debugvec(a) __AS_PROCEDURE(cerr << #a" = "; for (auto&& x : a) cerr << x << ' '; cerr << endl;) #define debugvec(a) __AS_PROCEDURE(cerr << #a" = "; for (auto&& x : a) cerr << x << ' '; cerr << endl;)
#define pa(a) __AS_PROCEDURE(__typeof(a) pa; pa.push_back({}); for (auto&&x : a) pa.push_back(pa.back() + x);) /* pops */
#define sa(a) __AS_PROCEDURE(__typeof(a) sa(a.size() + 1); {int n = a.size(); for (int i = n - 1; i >= 0; --i) sa[i] = sa[i + 1] + a[i];};)
#define poptop(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.top(); q.pop();) #define poptop(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.top(); q.pop();)
#define popback(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.back(); q.pop_back();) #define popback(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.back(); q.pop_back();)
#define popfront(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.front();q.pop_front();) #define popfront(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.front();q.pop_front();)
#define adj(ch, n) __AS_PROCEDURE(vector<vector<int>> ch((n) + 1);) /* algorithms */
#define edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v), ch[v].push_back(u);)
#define Edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v);)
vector<int> kmp(string s, string t) { // find all t in s vector<int> kmp(string s, string t) { // find all t in s
int n = s.length(), m = t.length(); int n = s.length(), m = t.length();
vector<int> next; next.push_back(-1); vector<int> next; next.push_back(-1);
@ -91,3 +111,4 @@ vector<int> kmp(string s, string t) { // find all t in s
} else j = next[j]; } else j = next[j];
return res; return res;
} }
/////////////////////////////////////////////////////////