跳到正文

hank0402

482642

你会不会披星戴月 乘风破浪来我梦里

在洛谷打开
资料、奖项与版本

资料

编号
482642
抓取

https://askahh.com/archives/17/

http://1.94.255.218:5000/

缺省源:

C++
#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;
}
JSON
{
	// 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

备忘录\large\texttt{备忘录}

魔法\large\texttt{魔法}

一些链接:
qq表情\texttt{qq表情} || 初赛\texttt{初赛} || CF辅助\texttt{CF辅助} || AT辅助(kenkoooo)\texttt{AT辅助(kenkoooo)} || AT中文\texttt{AT中文} || AT 数据 || || 高质量Blog\texttt{高质量Blog} || POJ Uid\texttt{POJ Uid} || 考试心态调整大法\texttt{考试心态调整大法} || 阴阳师|| Box\texttt{Box} || Exlg\texttt{Exlg} || 搜帖子\texttt{搜帖子} || Chrome 扩展\texttt{Chrome 扩展}

C++
#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《新华日报》

共 7 篇
  1. 个人记录

    P7650 的方案数

    该问题涉及计算元素最终位置的总和,并通过调整逆序对和不动点来优化结果。初始答案为所有元素i与最终位置p_i的和,但需减去因逆序对产生的冗余计算。逆序对的处理分为两种情况:当i向右跨过j或j向左跨过i时,会引发位置调整。进一步分析发现,不动点集合U(满足p_i单调递增)的每个元素i可减少2*(L_i+1)的总和,其中L_i表示初始位置小于p_i的元素数量。最终,问题转化为求带权最长递增子序列(LIS)的长度,可通过树状数组优化动态规划实现。

  2. 题解

    题解:AT_abc428_e [ABC428E] Farthest Vertex

    题意:给一棵树,求距离树上每个点最远的点的编号(相同距离输出最大编号)。 这是换根 dp 板子题,但是我不会换根,于是写了普通树形 dp。 显然答案可以分为子树内的和在子树外的,所以记 f_i 和 g_i 表示这两部分的答案,注意这里可以用 pair 同时存距离和编号,直接用 m…

  3. 题解

    题解:AT_snuke21_j Drink Bar

    该题解针对模拟赛T3问题,通过分析三个排列a、b、c的性质,得出集合S的大小最多为3。具体思路如下: 基础情况: 当|S|=1时,直接有n种方案(每个元素单独选)。 当|S|=2时,总方案数为组合数C(n,2),需减去满足三维偏序(a_i < a_j且b_i < b_j且c_i < c_j)的二元组数量,使用cdq分治高效计算三维偏序。 当|S|=3时,总方案数为C(n,3),需减去存在元素贡献两个最大值的情况(如a和b、a和c、b和c),通过树状数组处理二维偏序统计。若某元素贡献三个最大值,则被重复减去3次,需用容斥原理加回2次。 算法实现: 初始ans为n + C(n,2) + C(n,3)。 通过cdq分治计算三维偏序,三次调用twoo函数分别处理不同维度的二维偏序(交换a/c、b/c等),最终通过组合数调整得到正确结果。 关键点: 利用排列特性限制S的大小,避免重复计算。 cdq分治与树状数组结合处理三维/二维偏序问题。 容斥原理修正重复减去的特殊情况,确保统计准确性。

  4. 个人记录

    UOJ49 铀仓库

    注意到搬箱子的规律:初始地点必有箱子,而且每次是去搬一个最近的箱子。 二分答案,那么,枚举初始点,可以通过双指针来求出取过的区间(显然取的一定是一个区间)。 确定初始点后,显然可以通过前缀和迅速求出所需时间。

  5. 个人记录

    扯谈

    求最小的 y 使 y^Nequiv B pmod P× Q \ 其中,P,Q 为给定的两个相邻的质数,N 为质数常量,B 给定。 问题转化为求 y^Nequiv B pmod P。然后用 P 和 Q 的两个方程合并为答案方程。 注意到 y^k(P-1)+1equiv ypmod …

  6. 个人记录

    HL提高组模拟赛20220704总结

    本文简要总结了三道算法竞赛题目的题意及核心解法: T2.forward:涉及数列的“提前”操作。关键在于发现已操作的数位于未操作数之前,且未操作数保持升序。解法为倒序输出操作过的数,随后输出剩余未操作的数。 T3.oil:几何覆盖问题。性质是最优直线必经过至少两个线段端点。通过枚举端点将问题转化为区间覆盖问题,总复杂度约为 O(n^2 log n)。 T4.jenga:积木塔博弈问题。采用记忆化搜索,通过对状态进行压缩(忽略下层顺序、记录可取板、利用对称性)来降低复杂度,文末提及作者未实现该代码。

    1 赞
  7. 个人记录

    C++OIer教程——从入门到入土 另版

    C++ OIer 教程——从入门到入土 by 6872 本人和6872有了合作关系,于是经过商量自己也造了一个教程,将于某日和6872的作品合并。 第一章 输入与输出