My new name: Emergence
| 你猜 |
|---|
| All problems in computer science can be solved by another level of indirection |
2024.8.5::上橙啦
2026.5.5::打个卡
sc stop TDFileFilter
nm的数组防越界板子
template<typename T>
struct Safe_Array
{
const int n, line;
const string name;
vector<T> a;
Safe_Array(const int len,const string na = "Undefined", const int li = -1):n(len), a(len), name(na), line(li) {}
T& operator[](const size_t p) {
if(p < 0 || p >= n)
{
cerr << "Hey, son of bitch!\n"<<endl;
cerr << "Your array accessed index out of bounds!"<<endl;
cerr << "Name: "<<name<<endl;
cerr << "Line: "<<line<<endl;
cerr << "Size: "<<n<<endl;
cerr << "Index: "<<p<<endl;
abort();
}
return a.at(p);
}
};
#define define_array(type, len, a) Safe_Array<type> a (len, #a, __LINE__)treap merge/split
int merge(int x, int y)
{
if (!x || !y) return x + y;
if (pri[x] < pri[y])
{
ch[x][1] = merge(ch[x][1], y), pushup(x);
return x;
}
else
{
ch[y][0] = merge(x, ch[y][0]), pushup(y);
return y;
}
}
void split_rank(int now, int k, int& x, int& y)
{
if (!now) return x = y = 0, void(0);
if (k <= siz[ls]) y = now, split_rank(ls, k, x, ls);
else x = now, split_rank(rs, k - siz[ls] - 1, rs, y);
pushup(now);
}
void split_val(int now, int k, int& x, int& y)
{
if (!now) return x = y = 0, void(0);
if (k < val[now]) y = now, split_val(ls, k, x, ls);
else x = now, split_val(rs, k, rs, y);
pushup(now);
}矩阵板子::
struct cat {
const int n, m;
int c[17][17];
cat(int a = 0, int b = 0, int one = 0): n(a), m(b) {
mem(c, 0);
if (one) rep(i, 1, min(a, b)) c[i][i] = 1;
}
cat(const cat& b): n(b.n), m(b.m) {
rep(i, 1, n) rep(j, 1, m) c[i][j] = b.c[i][j];
}
int* operator [](const int& p) {return c[p];}
void operator =(const cat& b) {
assert(n == b.n && m == b.m);
rep(i, 1, n) rep(j, 1, m) c[i][j] = b.c[i][j];
}
void operator +=(const cat& b) {
assert((n == b.n) && (m == b.m));
rep(i, 1, n) rep(j, 1, m) (c[i][j] += b.c[i][j]) %= modd;
}
const cat operator +(const cat& b) const {
cat ret(*this);
ret += b;
return ret;
}
const cat operator *(const cat& b) const {
assert(m == b.n);
cat ret(n, b.m);
rep(i, 1, n) rep(k, 1, m) rep(j, 1, b.m) (ret.c[i][j] += c[i][k] * b.c[k][j]) %= modd;
return ret;
}
void operator *=(const cat& b) {*this = ((*this) * b);}
const cat pow(int ci) const {
cat now(*this), ret(n, m, 1);
int i = 1;
while (ci > 0) {
(ci & i) ? (ci -= i, ret *= now) : (void(0));
now *= now, i <<= 1;
}
return ret;
}
const cat operator ^(const int& a) const {return this->pow(a);}
void operator ^=(const int& a) {*this = this->pow(a);}
};网络流板子
struct network_flow
{
#define irep(i, x, n) for (int &i = x; i <= n; i++)
int n, m, S, T;
struct nod { int to, flow, inv, id; };
vector<vector<nod>> edge;
vector<int> d, cur;
void init(int nn, int SS, int TT)
{
clear();
n = nn, S = SS, T = TT;
d.resize(n+4, 0);
cur.resize(n+4, 0);
edge.resize(n+4);
}
void clear()
{
n = m = S = T = 0;
d.clear(); cur.clear();
edge.clear();
}
void add(int u, int v, int w)
{
edge[u].push_back({v, w, (int)edge[v].size(), ++m});
edge[v].push_back({u, 0, (int)edge[u].size() - 1, ++m});
}
int bfs()
{
fill(ar(cur), 0);
fill(ar(d), 0);
queue<int> q;
q.push(S), d[S] = 1;
while (!q.empty())
{
int now = q.front(); q.pop();
for (nod& i : edge[now])
{
if (i.flow && !d[i.to])
{
d[i.to] = d[now] + 1;
if (i.to == T) { return 1; }
q.push(i.to);
}
}
}
return 0;
}
int dfs(int now, int lim)
{
if (now == T) { return lim; }
int rest = lim;
int siz = edge[now].size() - 1;
irep(i, cur[now], siz)
{
nod& nxt = edge[now][i];
if(nxt.flow && d[nxt.to] == d[now] + 1)
{
int k = dfs(nxt.to, min(rest, nxt.flow));
if(!k) { d[nxt.to] = 0; }
nxt.flow -= k;
edge[nxt.to][nxt.inv].flow += k;
rest -= k;
}
if(!rest) { break; }
}
return lim - rest;
}
int dinic()
{
ll overflow = 0;
while(bfs()) overflow += dfs(S, (1ll << 50) - 1);
return overflow;
}
} F;/*
DABC ABCD ABCA DBAA
██████╗ ██╗██╗ ██╗███████╗██╗ ████████╗██╗███╗ ███╗███████╗
██╔══██╗██║╚██╗██╔╝██╔════╝██║ ╚══██╔══╝██║████╗ ████║██╔════╝
██████╔╝██║ ╚███╔╝ █████╗ ██║█████╗██║ ██║██╔████╔██║█████╗
██╔═══╝ ██║ ██╔██╗ ██╔══╝ ██║╚════╝██║ ██║██║╚██╔╝██║██╔══╝
██║ ██║██╔╝ ██╗███████╗███████╗ ██║ ██║██║ ╚═╝ ██║███████╗
╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
*/
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
using ll = long long;
const int mod = 998244353;
const int mod2 = 1'000'000'007;
using pii = pair<int, int>;
#define elif else if
#define Reverse std::views::reverse
#define ar(x) (x).begin(), (x).end()
#define mem(a, x) memset(a, x, sizeof a)
#define rep(i, x, n) for (int i = x, i ## end = ll(n); i <= (i ## end); i++)
#define dep(i, x, n) for (int i = x, i ## end = ll(n); i >= (i ## end); i--)
inline void pr() { cout << endl; }
template<class T1, class T2> inline void MAX(T1 &x, T2 y) { if (x < y) x = y; }
template<class T1, class T2> inline void MIN(T1 &x, T2 y) { if (!(x < y)) x = y; }
template<class T1, class T2> inline void ADD(T1 &x, T2 y) { x = ((x + y) % mod + mod) % mod; }
template<typename T> void inner(T fro, T bac) { for (; fro != bac; ++fro) cin >> *fro; }
template<typename T> void outer(T fro, T bac) { for (; fro != bac; ++fro) cout << *fro << " \n"[next(fro) == bac]; }
template<typename T, typename... Args> inline void pr(const T& first, Args&&... args)
{ cout << first; if (sizeof...(args) != 0) cout << " "; pr(args...); }
template<class T1, class T2, typename cmp = less<T1> >
using PBDS_map = tree<T1, T2, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, typename cmp = less<T> > using PBDS_set = PBDS_map<T, null_type, cmp>;
template<typename T>void operator +=(vector<T> &v, const T &x) { v.push_back(x); }
template<typename T> void outer(const T &v) { outer(v.begin(), v.end()); }
void work();
string OFHandle, IFHandle, test_data = R"()";
signed main()
{
if (IFHandle != "") freopen(IFHandle.c_str(), "r", stdin);
if (OFHandle != "") freopen(OFHandle.c_str(), "w", stdout);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
if (test_data != "") cin.rdbuf((new istringstream(test_data))->rdbuf()), cout << "----------InputData----------\n"
<< test_data << "\n----------InputEnd----------\n\n";
#endif
int t = 1; //cin >> t;
for (; t; t--) work();
return 0;
}
void work()
{
}