Skip to content

Instantly share code, notes, and snippets.

@GoBigorGoHome
GoBigorGoHome / 【模板】树的点分治.cpp
Last active November 8, 2019 14:17
CodeChef July 18 SUBWAY
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x <<": " << (x) << endl
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#ifdef LOCAL
#define see(x) cout << #x << ": " << (x) << endl
@baiwfg2
baiwfg2 / CMakeLists.txt
Created September 29, 2018 12:42
How to use add_custom_target and add_custom_command correctly in cmake
# References:
# https://cmake.org/cmake/help/latest/command/add_custom_target.html
# https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/
# https://gist.github.com/socantre/7ee63133a0a3a08f3990
# https://stackoverflow.com/questions/24163778/how-to-add-custom-target-that-depends-on-make-install
# https://stackoverflow.com/questions/30719275/add-custom-command-is-not-generating-a-target
# https://stackoverflow.com/questions/26024235/how-to-call-a-cmake-function-from-add-custom-target-command
# https://blog.csdn.net/gubenpeiyuan/article/details/51096777
cmake_minimum_required(VERSION 3.10)
@GoBigorGoHome
GoBigorGoHome / KD-Tree template.cpp
Created November 28, 2018 01:24
KD Tree 模板
template <int DIM, int N = 100000>
class KDtree {
#define lson id<<1
#define rson id<<1|1
#define sqr(x) ((x)*(x))
// kd-tree
using coord = array<int,DIM>;
constexpr static auto dist2 = [](const coord &a, const coord &b) {
ll ans = 0;
for (int i = 0; i < DIM; i++) {
@GoBigorGoHome
GoBigorGoHome / dinic.cpp
Last active February 20, 2019 02:39
Dinic 模板
#define SZ(x) (int)(x).size()
const int N = 2e3+5;
struct arc{ //据说数据量大时,vector存图比前向星块
int v;
ll residual_capacity;
int next;
};
@GoBigorGoHome
GoBigorGoHome / geometry.cpp
Last active December 16, 2018 13:30
计算几何模板(建设中)
template <typename T>
T sq(const T &a){return a * a;}
using ldb = long double;
struct pnt{
ldb x, y;
ldb len()const{
return std::sqrt(x * x + y * y);
}
ldb len2()const{
struct frac{
using ll = long long;
ll fz, fm;
frac() = default;
frac(ll fz, ll fm) { // 构造函数变量名最好不要跟类成员名一样!
assert(fm != 0);
if (fm < 0) fm *= -1, fz *= -1;
ll g = __gcd(abs(fz), fm);
fz /= g, fm /= g;
@GoBigorGoHome
GoBigorGoHome / 矩阵乘法类.cpp
Created December 18, 2018 18:40
template code library
using vec = vector<ll>;
using mat = vector<vec>;
mat get_I(int n) {
mat res(n, vec(n));
for (int i = 0; i < n; i++)
res[i][i] = 1;
return res;
}
mat operator*(const mat &a, const mat &b) {
#include <type_traits>
#include <cstdint>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <cassert>
inline int h_bit(unsigned long long x) {
return sizeof(unsigned long long) * 8 - 1 - __builtin_clzll(x); // or return 63 - __builtin_clzll(x); ??
}
template <typename T, typename Compare = std::less<T>>
struct ST{
size_t n; // 0-indexed
vv<T> a;
// const static Compare comp;
template <typename ptr_t>
ST(ptr_t beg, ptr_t end):n(end-beg){
// 这种写法内存消耗大约是上一种写法的两倍,时间消耗二者差不多。
template <typename Arc>
struct SCC {
int n;
using Graph = vector<vector<Arc>>;
Graph &g;
function<int&(Arc &)> get_v;
vector<int> scc_id;
int scc_cnt;
Graph scc_g; // 缩点建图