标题

标题

标题

标题

标题
标题
#include <cstdio>
#define R register int
#define I inline void
#define IL inline
#define ls c[x][0]
#define rs c[x][1] const int _ = 3e5 + 5;
int n, m;
struct Link_Cut_Tree
{
int f[_], c[_][2], v[_], s[_], st[_], r[_];
I _swap(R &x, R &y) { R t = x; x = y; y = t; }
IL bool nroot(R x) { return c[f[x]][0] == x || c[f[x]][1] == x; }
I pushup(R x) { s[x] = s[ls] ^ s[rs] ^ v[x]; }
I pushr(R x) { _swap(ls, rs); r[x] ^= 1; }
I pushdown(R x) { if(r[x]) { if(ls) pushr(ls); if(rs) pushr(rs); r[x] = 0; } }
I pushall(R x) { if(nroot(x)) pushall(f[x]); pushdown(x); }
I rotate(R x) {
R y = f[x], z = f[y], k = c[y][1] == x, w = c[x][!k];
if(nroot(y)) c[z][c[z][1] == y] = x; c[x][!k] = y; c[y][k] = w;
if(w) f[w] = y; f[y] = x; f[x] = z; pushup(y);
}
I splay(R x) {
R y, z; pushall(x);
while(nroot(x)) {
y = f[x]; z = f[y];
if(nroot(y)) rotate((c[y][0] == x) ^ (c[z][0] == y) ? x : y);
rotate(x);
} pushup(x);
}
I access(R x) { for(R y = 0; x; x = f[y = x]) splay(x), rs = y, pushup(x); }
I makeroot(R x) { access(x); splay(x); pushr(x); }
IL int findroot(R x) { access(x); splay(x); while(ls) pushdown(x), x = ls; splay(x); return x; }
I split(R x, R y) { makeroot(x); access(y); splay(y); }
I link(R x, R y) { makeroot(x); if(findroot(y) != x) f[x] = y; }
I cut(R x, R y) {
makeroot(x); if(findroot(y) != x || f[y] != x || c[y][0]) return;
f[y] = c[x][1] = 0; pushup(x);
}
}lct;
int main()
{
int opt, x, y;
scanf("%d%d", &n, &m);
for(R i = 1; i <= n; ++i) scanf("%d", &lct.v[i]);
while(m--) {
scanf("%d%d%d", &opt, &x, &y);
if(opt == 0) lct.split(x, y), printf("%d\n", lct.s[y]);
else if(opt == 1) lct.link(x, y);
else if(opt == 2) lct.cut(x, y);
else if(opt == 3) lct.splay(x), lct.v[x] = y;
}
return 0;
}
#include <iostream>
#include <cstdio>
#define ll long long using namespace std;
const int N = 1e5 + 10;
int n,m,root,mod,cnt,a[N],father[N],deep[N],size[N],son[N],rk[N],top[N],id[N];
struct Edge {
int Next, to;
}e[N<<1];
int head[N], num;
void add(int from, int to) {
e[++num].Next = head[from];
e[num].to = to;
head[from] = num;
}
struct Segment_Tree
{
ll ans[N<<2], tag[N<<2];
inline ll ls(ll p) { return p << 1; }
inline ll rs(ll p) { return p << 1 | 1; }
inline void pushup(ll p) {
ans[p] = (ans[ls(p)] + ans[rs(p)]) % mod;
}
inline void pushdown(ll p, ll l, ll r) {
ll mid = (l + r) >> 1;
ans[ls(p)] += (mid - l + 1) * tag[p] % mod;
tag[ls(p)] += tag[p] % mod;
ans[rs(p)] += (r - mid) * tag[p] % mod;
tag[rs(p)] += tag[p] % mod;
tag[p] = 0;
}
void build(ll p, ll l, ll r) {
if(l == r) {
ans[p] = a[rk[l]];
return;
}
ll mid = (l + r) >> 1;
build(ls(p), l, mid);
build(rs(p), mid + 1, r);
pushup(p);
}
void update(ll p, ll l, ll r, ll ul, ll ur, ll k) {
if(ul <= l && r <= ur) {
ans[p] += (r - l + 1) * k % mod;
tag[p] += k % mod;
return;
}
if(tag[p]) pushdown(p, l, r);
ll mid = (l + r) >> 1;
if(ul <= mid) update(ls(p), l, mid, ul, ur, k);
if(ur > mid) update(rs(p), mid + 1, r, ul, ur, k);
pushup(p);
}
ll query(ll p, ll l, ll r, ll ql, ll qr) {
if(ql <= l && r <= qr)
return ans[p];
if(tag[p]) pushdown(p, l, r);
ll mid = (l + r) >> 1, res = 0;
if(ql <= mid) res = (res + query(ls(p), l, mid, ql, qr)) % mod;
if(qr > mid) res = (res + query(rs(p), mid + 1, r, ql, qr)) % mod;
return res % mod;
}
}T;
struct lianpou
{
void dfs1(int u, int f, int depth)
{
father[u] = f;
deep[u] = depth;
size[u] = 1;
for(int i = head[u]; i; i = e[i].Next)
{
int v = e[i].to;
if(v == f) continue;
dfs1(v, u, depth + 1);
size[u] += size[v];
if(size[v] > size[son[u]])
son[u] = v;
}
}
void dfs2(int u, int tp)
{
top[u] = tp;
id[u] = ++cnt;
rk[cnt] = u;
if(!son[u]) return;
dfs2(son[u], tp);
for(int i = head[u]; i; i = e[i].Next)
{
int v = e[i].to;
if(v != son[u] && v != father[u])
dfs2(v, v);
}
}
ll sum(int x, int y)
{
ll ans = 0;
int fx = top[x], fy = top[y];
while(fx != fy)
{
if(deep[fx] >= deep[fy]) {
ans = (ans + T.query(1, 1, n, id[fx], id[x])) % mod;
x = father[fx], fx = top[x];
}
else {
ans = (ans + T.query(1, 1, n, id[fy], id[y])) % mod;
y = father[fy], fy = top[y];
}
}
if(id[x] > id[y]) swap(x, y);
ans = (ans + T.query(1, 1, n, id[x], id[y])) % mod;
return ans % mod;
}
void update(int x, int y, int z)
{
int fx = top[x], fy = top[y];
while(fx != fy)
{
if(deep[fx] >= deep[fy]) {
T.update(1, 1, n, id[fx], id[x], z);
x = father[fx], fx = top[x];
}
else
{
T.update(1, 1, n, id[fy], id[y], z);
y = father[fy], fy = top[y];
}
}
if(id[x] > id[y]) swap(x, y);
T.update(1, 1, n, id[x], id[y], z);
}
}L;
int main()
{
scanf("%d%d%d%d", &n, &m, &root, &mod);
for(int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for(int i = 1, u, v; i < n; i++)
{
scanf("%d%d", &u, &v);
add(u,v); add(v,u);
}
L.dfs1(root, 0, 1);
L.dfs2(root, root);
T.build(1, 1, n);
for(int i = 1, opt, x, y, z; i <= m; i++)
{
scanf("%d", &opt);
if(opt == 1)
{
scanf("%d%d%d", &x, &y, &z);
L.update(x, y, z);
}
else if(opt == 2)
{
scanf("%d%d", &x, &y);
printf("%lld\n", L.sum(x, y));
}
else if(opt == 3)
{
scanf("%d%d", &x, &z);
T.update(1, 1, n, id[x], id[x] + size[x] - 1, z);
}
else if(opt == 4)
{
scanf("%d", &x);
printf("%lld\n", T.query(1, 1, n, id[x], id[x] + size[x] - 1));
}
}
return 0;
}















[测试] Markdown+Latex的更多相关文章

  1. MarkDown+LaTex 数学内容编辑样例收集

    $\color{green}{MarkDown+LaTex 数学内容编辑样例收集}$ 1.大小标题的居中,大小,颜色 [例1] $\color{Blue}{一元二次方程根的分布}$ $\color{R ...

  2. 奇怪的 Markdown / LaTeX 笔记

    记一下日常见到的一些奇怪的 Markdown / LaTeX 用法... Markdown LaTeX LaTeX 数学 1. 运算符 1.1 造运算符: a \operatorname{sin} c ...

  3. markdown | Latex | 书写测试

    我永远喜欢markdown! 建图 graph TD; 1-->2 1-->3 1-->4 2-->5 2-->6 3-->7 3-->8 4-->9 ...

  4. 测试markdown语法

    测试使用markdown 这是无序列表 空调 洗衣机 电脑 这是有序列表 西瓜 哈密瓜 火龙果 下划线bingo 测试 斜体好丑 粗体很赞 测试插入代码 $(document).ready(funct ...

  5. 测试markdown 博客功能

    欢迎使用 Cmd - 在线 Markdown 编辑阅读器 我们理解您需要更便捷更高效的工具记录思想,整理笔记.知识,并将其中承载的价值传播给他人,Cmd Markdown 是我们给出的答案 -- 我们 ...

  6. R+markdown+LaTeX 中文编译解决方案

    一丢丢前言 很久之前曾试图以Rmarkdown编译pdf文档,无奈怎么鼓捣都会error,搜索了很久都没能找到比较好的解决方案.在配置上将编译器调成了xeLaTeX后就不了了之.这两天心血来潮研究了一 ...

  7. Markdown & LaTex 常用语法

    目录 blog 的目录 博客园自带目录 用 javascript 自定义目录 主标题 副标题 h1,一级标题 h2,二级标题 h3,三级标题 注释 常用的符号及文本形式 如果你想在markdown中文 ...

  8. 利用Mathpix Snipping Tool轻松在markdown/LaTeX中输入电子书和论文的数学公式

    最近写图形学博客写累了,公式太多了,一个个输入实在太累,所以从数学建模队友那里吃了一个安利. 官网下载 下载安装后,直接新建一个截图,就可以转成LaTeX数学公式了.效果如下: 爽的一批啊!!! 另外 ...

  9. 测试数学公式latex

    \( J_\alpha(x) = \sum\limits_{m=0}^\infty \frac{(-1)^m}{m! + 1)}{\left({\frac{x}{2}}\right)}^{2 m + ...

随机推荐

  1. 无责任Windows Azure SDK .NET开发入门篇(一):开发前准备工作

    Windows Azure开发前准备工作 什么是 Azure SDK for .NET?微软官方告诉我们:Azure SDK for .NET 是一套应用程序,其中包括 Visual Studio 工 ...

  2. Fork/Join 框架-设计与实现(翻译自论文《A Java Fork/Join Framework》原作者 Doug Lea)

    作者简介 Dong Lea任职于纽约州立大学奥斯威戈分校(State University of New York at Oswego),他发布了第一个广泛使用的java collections框架实 ...

  3. Java 支付宝支付,退款,单笔转账到支付宝账户(支付宝订单退款)

    上一篇写到支付宝的支付,这代码copy下来就能直接用了,   我写学习文档时会经常贴 官方参数文档的案例地址, 因为我觉得 请求参数,响应参数说明 官方文档整理的很好,毕竟官方不会误导大家. 我学一个 ...

  4. 虚拟机中安装完 CentOS7minimal 版本后无法联网的问题

    问题描述 安装完系统后无法上网,然后进入到目录 /etc/sysconfig/network-script 查看.发现只有一个 ifcfg-lo. 解决办法 这种情况是没有识别到网卡. 在 VMwar ...

  5. js-ES6学习笔记-修饰器

    1.修饰器对类的行为的改变,是代码编译时发生的,而不是在运行时.这意味着,修饰器能在编译阶段运行代码. 2. function testable(target) { target.isTestable ...

  6. Vue.js之生命周期

    有时候,我们需要在实例创建过程中进行一些初始化的工作,以帮助我们完成项目中更复杂更丰富的需求开发,针对这样的需求,Vue提供给我们一系列的钩子函数. vue生命周期 beforeCreate 在实例初 ...

  7. jQuery事件和JSON点语法

    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" ...

  8. 新知食APP架构分析--北京识物科技有限公司旗下产品

    俗话说不打无准备之仗,这次真是有点懵逼了,建议大家去面试的时候,尤其是去小型互联网公司的时候,如果你想比其他人有竞争力,那么你要研究一下当前他的公司正在开发产品,他们的业务类型是什么样的,比如他们公司 ...

  9. 【Python】读取excel数据

    '''python3读取excle数据''' import xlrd workbook = xlrd.open_workbook(r'test.xls', encoding_override='gbk ...

  10. 【LLVM笔记】0x00 初识LLVM 链接类型

    模块结构 LLVM程序是由若干的模块(Module)组成,每个模块中包含有一些函数.全局变量和符号表. 这些模块可能由LLVM的连接器组合在一起,组合的过程将会整合这些函数和全局变量的定义,整合他们的 ...