BZOJ4003 [JLOI2015]城池攻占
这题有两种做法来着。。。
第一种就是一开始想到的比较不靠谱,不过貌似可以过掉:
看从$1$号节点开始到$p$号节点最大需要的体力,记录单调上升的体力,询问的时候二分跳着走就可以了
不过精度问题还有可能爆double什么的QAQ
于是写了一半果断弃疗。。。结果有人说他过了【摔
第二种是正解,对于每个点我们可以先把下面的骑士都先做完然后还活着的全部搞到这个点上来,然后再看有谁死在这个点上了
所以我们要维护能都删除/查询最小值,合并,允许打标记的数据结构
貌似是可并堆喵!【完结撒花~
/**************************************************************
Problem: 4003
User: rausen
Language: C++
Result: Accepted
Time:6872 ms
Memory:56988 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std;
typedef double lf;
typedef long long ll; const int N = 3e5 + ; struct edge {
int next, to;
edge(int _n = , int _t = ) : next(_n), to(_t) {}
} e[N]; struct heap {
heap *ls, *rs;
ll v, tag_t, tag_a;
int dep, st, w; void* operator new(size_t, int x, int y, ll z) {
static heap mempool[N], *c = mempool;
c -> ls = c -> rs = NULL;
c -> dep = , c -> v = z, c -> w = x, c -> st = y;
c -> tag_t = , c -> tag_a = ;
return c++;
} inline void Times(ll x) {
v *= x, tag_t *= x, tag_a *= x;
}
inline void Add(ll x) {
v += x, tag_a += x;
}
inline void push() {
if (ls) ls -> Times(tag_t);
if (rs) rs -> Times(tag_t);
tag_t = ;
if (ls) ls -> Add(tag_a);
if (rs) rs -> Add(tag_a);
tag_a = ;
} #define Dep(p) (p ? p -> dep : 0)
inline void update() {
dep = Dep(rs) + ;
} friend heap* merge(heap *x, heap *y) {
if (!x) return y;
if (!y) return x;
if (x -> v > y -> v) swap(x, y);
x -> push();
x -> rs = merge(x -> rs, y);
if (Dep(x -> rs) > Dep(x -> ls)) swap(x -> ls, x -> rs);
x -> update();
return x;
}
#undef Dep inline heap* pop() {
this -> push();
return merge(ls, rs);
}
} *h[N]; struct tree_node {
int fa, a, dep;
ll h, v;
} tr[N]; inline ll read() {
static ll x, sgn;
static char ch;
x = , sgn = , ch = getchar();
while (ch < '' || '' < ch) {
if (ch == '-') sgn = -;
ch = getchar();
}
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return sgn * x;
} int n, m;
int first[N], tot;
int ans1[N], ans2[N]; inline void add_edge(int x, int y) {
e[++tot] = edge(first[x], y);
first[x] = tot;
} #define y e[x].to
void dfs(int p) {
int x;
tr[p].dep = tr[tr[p].fa].dep + ;
for (x = first[p]; x; x = e[x].next) {
dfs(y);
h[p] = merge(h[p], h[y]);
}
while (h[p] && h[p] -> v < tr[p].h) {
++ans1[p], ans2[h[p] -> w] = tr[h[p] -> st].dep - tr[p].dep;
h[p] = h[p] -> pop();
}
if (h[p])
if (tr[p].a) h[p] -> Times(tr[p].v);
else h[p] -> Add(tr[p].v);
}
#undef y int main() {
int i, x, c;
ll s;
n = read(), m = read();
for (i = ; i <= n; ++i) tr[i].h = read();
for (i = ; i <= n; ++i) {
x = read(), add_edge(x, i);
tr[i].fa = x , tr[i].a = read(), tr[i].v = read();
}
for (i = ; i <= m; ++i) {
s = read(), c = read();
h[c] = merge(h[c], new(i, c, s)heap);
}
dfs();
while (h[]) {
ans2[h[] -> w] = tr[h[] -> st].dep;
h[] = h[] -> pop();
}
for (i = ; i <= n; ++i) printf("%d\n", ans1[i]);
for (i = ; i <= m; ++i) printf("%d\n", ans2[i]);
return ;
}
BZOJ4003 [JLOI2015]城池攻占的更多相关文章
- [bzoj4003][JLOI2015]城池攻占_左偏树
城池攻占 bzoj-4003 JLOI-2015 题目大意:一颗n个节点的有根数,m个有初始战斗力的骑士都站在节点上.每一个节点有一个standard,如果这个骑士的战斗力超过了这个门槛,他就会根据城 ...
- BZOJ4003 [JLOI2015]城池攻占 左偏树 可并堆
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4003 题意概括 题意有点复杂,直接放原题了. 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑 ...
- BZOJ4003[JLOI2015]城池攻占——可并堆
题目描述 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的管辖, 其中 fi ...
- [BZOJ4003][JLOI2015]城池攻占(左偏树)
这题有多种做法,一种是倍增预处理出每个点往上走2^i步最少需要的初始战斗力,一种是裸的启发式合并带标记splay. 每个点合并能攻占其儿子的所有骑士,删去所有无法攻占这个城市的骑士并记录答案. 注意到 ...
- BZOJ4003 JLOI2015城池攻占
用左偏树模拟攻占的过程,维护最小值,最多入和出m次,每次log复杂度. #include<bits/stdc++.h> using namespace std; ; typedef lon ...
- 【BZOJ4003】[JLOI2015]城池攻占 可并堆
[BZOJ4003][JLOI2015]城池攻占 Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号 ...
- BZOJ_4003_[JLOI2015]城池攻占_可并堆
BZOJ_4003_[JLOI2015]城池攻占_可并堆 Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 ...
- [洛谷P3261] [JLOI2015]城池攻占(左偏树)
不得不说,这道题目是真的难,真不愧它的“省选/NOI-”的紫色大火题!!! 花了我晚自习前半节课看题解,写代码,又花了我半节晚自习调代码,真的心态爆炸.基本上改得和题解完全一样了我才过了这道题!真的烦 ...
- BZOJ4003:[JLOI2015]城池攻占——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4003 https://www.luogu.org/problemnew/show/P3261 小铭 ...
随机推荐
- Struts BaseAction工具类,封装Session,Request,Application,ModelDriven
package com.ssh.shop.action; import java.io.InputStream; import java.lang.reflect.ParameterizedType; ...
- WinForm 弹框确认后执行
if (MessageBox.Show("你确定要退出程序吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIc ...
- 坐标随鼠标移动 jquery简易版
<html> <span style="position:absolute" id="xy_test"></span> &l ...
- yii2-datepicker/datetimepicker插件使用
datepicker: https://github.com/2amigos/yii2-date-picker-widget 通过composer安装: composer require 2amigo ...
- Java Abstract class and Interface
Abstract Class 在定义class的时候必须有abstract 关键字 抽象方法必须有abstract关键字. 可以有已经实现的方法. 可以定义static final 的常量. 可以实现 ...
- Redis基础知识之————空间换时间的查询案例
空间与时间 空间换时间是在数据库中经常出现的术语,简单说就是把查询需要的条件进行索引的存储,然后查询时为O(1)的时间复杂度来快速获取数据,从而达到了使用空间存储来换快速的时间响应!对于redis这个 ...
- tomcat PermGen space
centos: 修改Tomcat中的catalina.sh文件.--用了这个 在catalina.sh文件中,找到cygwin=false,在这一行的前面加入参数,具体如下 # vim TOMCAT_ ...
- js分组排序算法, OrderBy
由于项目中需要对数据进行分组排序,类似于sql中 order by column1,column2.... 实现的关键是 分组排序,第一个column1,排序完成之后,对其分组,然后按照column ...
- JavaWeb 7 Servlet
7 Servlet Servlet学习的大纲:1. servlet概念及相关接口简介2. servet 执行过程3. servlet路径映射4. 缺省servlet --应用5. s ...
- 针对ASP.NET页面实时进行GZIP压缩优化的几款压缩模块的使用简介及应用测试!(附源码)
在介绍之前,先简单说一说ASP.NET服务端GZIP压缩模块的作用及工作原理,很多人编写网页的时候页面因为使用了大量的JS特效又或者放置很多大型动态广告导致了页面或脚本体积庞大,通常都会使用一些压缩工 ...