洛谷P2146 [NOI2015]软件包管理器
2024-08-28 09:34:04
https://www.luogu.org/problemnew/show/P2146 传送门
简单的树链剖分......维护下当前安装了多少个包......修改后查询下就行了......附上极其丑陋的代码......
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; int head[N], to[N], v[N], p; void build(int a, int b) { v[++ p] = b; to[p] = head[a]; head[a] = p; } #define mid (l + r >> 1) ], lazy[N << ]; void push_down(int c, int l, int r) { if( !lazy[c]) return ; lazy[c] --; tr[c << ] = (mid - l + ) * lazy[c]; tr[c << |] = (r - mid) * lazy[c]; lazy[c << ] = lazy[c << |] = lazy[c] + ; lazy[c] = ; } void change(int c, int l, int r, int L, int R, int o) { if( L <= l && R >= r) { tr[c] = (r - l + ) * o; lazy[c] = o + ; return ; } push_down(c, l, r); , l, mid, L, R, o); |, mid+, r, L, R, o); tr[c] = tr[c << ] + tr[c << |]; } int get_(int c, int l, int r, int L, int R) { if( l == L && R == r) return tr[c]; push_down(c, l, r); , l, mid, L, R); |, mid+, r, L, R); , l, mid, L, mid) + get_(c << |, mid+, r, mid+, R); } int son[N], si[N]; void search(int u) { si[u] = ; son[u] = ; for( int i = head[u]; ~i; i = to[i]) { search(v[i]), si[u] += si[v[i]]; if( si[v[i]] > si[son[u]]) son[u] = v[i]; } } int top[N], dfs[N], dfn[N], cnt; void build_son(int u, int c) { top[u] = c; dfs[u] = ++cnt; if( son[u]) build_son(son[u], c); for( int i = head[u]; ~i; i = to[i]) if( v[i] != son[u]) build_son(v[i], v[i]); dfn[u] = cnt; } int n, q, pre[N]; void query(int a) { ]; while( a) { change(, , n, dfs[top[a]], dfs[a], ); a = pre[top[a]]; }printf(] - tcmp); } ]; int main() { scanf(, ; ; i <= n; i ++) scanf("%d", pre + i), pre[i] ++ ; ; i <= n; i ++) build(pre[i], i); search();build_son(, ); scanf("%d", &q); , a; i <= q; i ++) { scanf("%s%d", s, &a); a ++; ] == 'i') query(a); else { ]; change(, , n, dfs[a], dfn[a], ); printf(]); } } }
最新文章
- python的历史
- icmp_ping学习笔记
- HTML5学习总结
- web 开发前端学习
- 深入浅出设计模式——备忘录模式(Memento Pattern)
- 在Mac/Linux/Windows上编译corefx遇到的问题及解决方法
- jsp中表格,表格中的文字根据表格的大小自动换行
- iBatisSQL中prepend的问题
- 关于Android悬浮窗要获取按键响应的问题
- php protected只能被继承,不可以在实例中调用,parent::调用父类(子类函数的重载对父类的函数没有影响)
- Don&#39;t Repeat Yourself (不要重复你自己)
- MVP快速开发框架
- 有关sqlitedrop数据库重建比delete方式来清空数据库更加有效率
- 批量下载google 字体小工具
- RDay1-Problem 3 C
- 2018/12/19 20:55:58 螺纹钢豆粕PTA
- OpenFlow学习笔记
- SpringBoot系列——EnableScheduling,对定时器的支持
- 记一次 MySQL semaphore crash 的分析(爱可生)
- BZOJ3537 : [Usaco2014 Open]Code Breaking
热门文章
- Eclipse导入MyEclipse项目遇到问题解答
- ubuntu16.04 Mask_RCNN AlphaPose OpenPose Librealsense
- dubbo 相关面试题 有用
- django 1.8 官方文档翻译:13-12 验证器
- pymysql模块使用---Python连接MySQL数据库
- spring.net 集成nhibernate配置文件(这里暴露了GetCurrentSession 对于 CurrentSession unbond thread这里给出了解决方法)
- JavaScript——Dom编程(1)
- 第04章-面向切面的Spring
- 编写高质量代码改善C#程序的157个建议——建议4: TryParse比Parse好
- c# 简单委托例子