This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SZ(x) (int)(x).size() | |
const int N = 2e3+5; | |
struct arc{ //据说数据量大时,vector存图比前向星块 | |
int v; | |
ll residual_capacity; | |
int next; | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <cstdint> | |
#include <iostream> | |
#include <fstream> | |
#include <iomanip> | |
#include <vector> | |
#include <queue> | |
#include <functional> | |
#include <numeric> | |
#include <cassert> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 这种写法内存消耗大约是上一种写法的两倍,时间消耗二者差不多。 | |
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; // 缩点建图 |