https://askahh.com/archives/17/
缺省源:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void rd(T& res) {
T fh = 1;
res = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ '0');
res = res * fh;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) {
rd(x), rd(args...);
}
template <typename T>
inline void wr(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
wr(x / 10);
putchar(x % 10 + 48);
}
template <typename T, typename... Args>
inline void wr(T x, Args... args) {
wr(x), putchar(' '), wr(args...);
}
signed main() {
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
return 0;
}
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"C++ template": {
"prefix": "#include",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"template <typename T>",
"inline void rd(T& res) {",
" T fh = 1;",
" res = 0;",
" char ch = getchar();",
" for (; !isdigit(ch); ch = getchar())",
" if (ch == '-') fh = -1;",
" for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ '0');",
" res = res * fh;",
"}",
"template <typename T, typename... Args>",
"inline void rd(T& x, Args&... args) {",
" rd(x), rd(args...);",
"}",
"",
"template <typename T>",
"inline void wr(T x) {",
" if (x < 0)",
" putchar('-'), x = -x;",
" if (x > 9)",
" wr(x / 10);",
" putchar(x % 10 + 48);",
"}",
"template <typename T, typename... Args>",
"inline void wr(T x, Args... args) {",
" wr(x), putchar(' '), wr(args...);",
"}",
"",
"signed main() {",
" freopen(\".in\", \"r\", stdin);",
" freopen(\".out\", \"w\", stdout);",
"" ,
" return 0;",
"}"
],
"description": "template"
}
}https://netcut.cn/hankdl bageba
一些资源 / 项目:
https://github.com/marktext/marktext
https://github.com/CannedGrape/oi
https://github.com/lydrainbowcat/tedukuri
https://github.com/enkerewpo/OI-Public-Library
一些链接:
|| || || || || AT 数据 || || || || || 阴阳师|| || || ||
#define ls(x) a[x].sons[0]
#define rs(x) a[x].sons[1]
#define fa(x) a[x].f
// 宏增加代码可读性
struct splay {
// 父亲编号,副本数量,关键码,子树大小,左右子树下标
int f, cnt, val, size, sons[2];
}a[100005];
int tot, root, INF = 1e9;
// 获取它是父亲节点的左子节点还是右子节点
int ident(int x) {
return a[fa(x)].sons[0] == x ? 0 : 1;
}
// 新建节点
int New(int val, int f) {
a[++tot].val = val;
a[tot].f = f;
a[tot].cnt = a[tot].size = 1;
a[tot].sons[0] = a[tot].sons[1] = 0;
return tot;
}
// pushup
void update(int p) {
a[p].size = a[ls(p)].size + a[rs(p)].size + a[p].cnt;
}
// 把 x 挂到 fa 节点的 how 子节点上
void connect(int x, int fa, int how) {
a[fa].sons[how] = x;
a[x].f = fa;
}
// 单旋
void rotate(int x) {
int y = a[x].f, z = a[y].f;
int Yson = ident(x), Zson = ident(y);
connect(a[x].sons[Yson ^ 1], y, Yson);
connect(y, x, Yson ^ 1);
connect(x, z, Zson);
update(y);
update(x);
}
// 伸展(x 旋到 to)
void splay(int x, int to) {
to = fa(to);
while(fa(x) != to) {
int y = fa(x);
if(a[y].f == to) rotate(x);
else if(ident(x) == ident(y)) { // 三点共线
rotate(y);
rotate(x);
}
else {
rotate(x);
rotate(x);
}
}
if(to == 0) root = x; // 特别注意!!!!!!
}
// 查找元素
int find(int x) { // 找到关键码为 x 的节点编号
int now = root;
while(1) {
if(!now) return 0; // 未找到
if(a[now].val == x) {
splay(now, root); // 使平衡树更平衡
return now;
}
int nxt = x < a[now].val ? 0 : 1;
now = a[now].sons[nxt];
}
}
int getrankbyval(int val) {
int p = find(val);
if(!p) return 0;
return a[ls(p)].size + 1;
}
int kth(int p, int rank) {
if(!p) return INF; // 不存在
if(a[ls(p)].size >= rank) return kth(ls(p), rank);
if(a[ls(p)].size + a[p].cnt >= rank) {
splay(p, root);
return a[p].val;
}
return kth(rs(p), rank - a[ls(p)].size);
}
//插入元素
void insert(int x) {
if(!root) { //
root = New(x, 0);
return ;
}
int now = root;
while(1) {
a[now].size ++;
if(a[now].val == x) {
a[now].cnt ++;
splay(now, root);
return ;
}
int nxt = x > a[now].val;
if(!a[now].sons[nxt]) {
int p = New(x, now);
a[now].sons[nxt] = p;
splay(p, root);
return ;
}
now = a[now].sons[nxt];
}
}
// 合并
int join(int r1, int r2) {
int ms = r1;
while(rs(ms)) {
ms = rs(ms);
}
splay(ms, r1);
connect(r2, ms, 1);
update(ms);
return ms;
}
// 删除
void del(int x) {
int p = find(x);
if(p) {
if(a[p].cnt > 1) {
a[p].cnt --;
a[p].size --;
return ;
}
if(!ls(p) && !rs(p)) {
root = 0;
return ;
}
// 左子节点不存在
if(!ls(p)) {
root = rs(p);
a[root].f = 0;
return ;
}
// 其他情况,合并左子节点和右子节点
root = join(ls(p), rs(p));
a[root].f = 0;
}
}
// 分裂,以 x 为界,<x 分到 s1,剩下的分到 s2
void split(int x, int &r1, int &r2) {
int p = find(x);
if(!p) return ;
r1 = ls(p); r2 = rs(p);
}
// 前驱后继
int GetPre(int x) {
insert(x);
int p = find(x);
int now = ls(p);
while(rs(now)) now = rs(now);
int ans = a[now].val;
del(x);
return ans;
}
int GetNxt(int x) {
insert(x);
int p = find(x);
int now = rs(p);
while(ls(now)) now = ls(now);
int ans = a[now].val;
del(x);
return ans;
}
infp-a
你可以对政治毫无兴趣
可你必须确信:政治对你却太有兴趣,这一切绝不会因为你对政治不关心而放过你,所以,假如你不想作布偶戏匠人手中可怜的布偶,给别人随心所欲地推来推去,你就别无选择——必须关心政治,因为这其实就是在关心你自己。
————1945《新华日报》