题目描述

风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果。由于她已经DT FC 了The big black, 她觉得这个游戏太简单了,于是发明了一个更加难的版本。

首先有一个地图,是一棵由 n 个顶点、n-1 条边组成的树(例如图 1给出的树包含 8 个顶点、7 条边)。

这颗树上有 P 个盘子,每个盘子实际上是一条路径(例如图 1 中顶点 6 到顶点 8 的路径),并且每个盘子还有一个权值。第 i 个盘子就是顶点a_i到顶点b_i的路径(由于是树,所以从a_i到b_i的路径是唯一的),权值为c_i。

接下来依次会有Q个水果掉下来,每个水果本质上也是一条路径,第i 个水果是从顶点 u_i 到顶点v_i 的路径。

幽香每次需要选择一个盘子去接当前的水果:一个盘子能接住一个水果,当且仅当盘子的路径是水果的路径的子路径(例如图1中从 3到7 的路径是从1到8的路径的子路径)。这里规定:从a 到b的路径与从b到 a的路径是同一条路径。

当然为了提高难度,对于第 i 个水果,你需要选择能接住它的所有盘子中,权值第 k_i 小的那个盘子,每个盘子可重复使用(没有使用次数的上限:一个盘子接完一个水果后,后面还可继续接其他水果,只要它是水果路径的子路径)。幽香认为这个游戏很难,你能轻松解决给她看吗?

输入输出格式

输入格式:

第一行三个数 n和P 和Q,表示树的大小和盘子的个数和水果的个数。 接下来n-1 行,每行两个数 a、b,表示树上的a和b 之间有一条边。树中顶点按1到 n标号。 接下来 P 行,每行三个数 a、b、c,表示路径为 a 到 b、权值为 c 的盘子,其中0<=c<=10^9,a不等于b。 接下来Q行,每行三个数 u、v、k,表示路径为 u到 v的水果,其中 u不等于v,你需要选择第 k小的盘子,第k 小一定存在。

输出格式:

对于每个果子,输出一行表示选择的盘子的权值。

题意:统计对于给出一些有权值的点对(盘子),再给出一些询问点对(水果),每个水果能被一个盘子接住当且仅当盘子的两点间的路径是水果两点之间路径的子路径。

题解:

①转化一下:一个盘子A可以接住一个水果B,意思是要么是A.x和A.y无祖先关系时,B.x和B.y都在A.x和A.y(可以交换位置)的子树里,要么是A.x和A.y有祖先关系:假设A.x是A.y的祖先,B.x一定在A.y的子树里且B.y一定不在A.x到A.y路径上的第二个点(第一个点为A.x)的子树里(同样可以交换)。

(还是给个图吧)aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdIAAAGHCAYAAAAEI9NyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACZ6SURBVHhe7d1/qF/1nefxc/Pre+9Nc9Uu+aODWVhJl2ktrJOCNYEVw+okVImsrmFlFGSaUSZBl2QKZiyoEUwj2Lg7XYV20yFghy7NrJDU7ETs0qwL1gYaClPHgbpdaKTzh0yNt97k3iQme1/nfj7J5577Pd9fn/Pjc87n+YCL5/s1JvHe7/f7Ou/359fYlXkJAAAYyTLzTwAAMAIqUqAAc0deS86/9O3k8pkPzDODWbbuxmTVljuT8Z2PJsvWrjXPAmgSghTwMGqAZo11Osn47seTiV2PmWcANAVBCoygqADNGn/4wTRQqU6B5mCMFBjQxZNvJWc3bU5+t+7zycyeJ5eEaGfbPckN7//SPBrMZw69kqy4+QvmUZLMvvqD5OyGTemfc/7l75hnAYSMihQYkALu8ocfmkfXKEAnDx5IPlr/JfPMcBS+M7t2JxfeeNM8c83UiWOLghZAeKhIgT5sJZoNUVuBzh17feQQFf23CtFsdSrTW7elf7ZayQDCREUK9KAAO/fs88mV6WnzzEKAKjzLoipUAerSZKRh28YAqkFFCuTQeKXGQrMhqjZumRSimnTkujI3l1am+jsBCAsVKdCFwvPjO7Yuaucq3KoOMlWiClHXhJbJ7HnCPAJQNypSIEPjlWc3Lh4TVVu1jmpQS2GytOzm/MG/Mo8A1I2KFMjIzs5decft6YSjOinIP9mxc9Hfg8oUCAMVKeBQ1emG6OqDL9QeoqKZvZrVq1C3qEyBMFCRAg63Gi17du4oqEyB8FCRAka2Gi17du4oqEyB8BCkgDE7H0iWqlGfTRbKRJgCYaG1CxjaQ9dSCzXUILVo8wJhIEgBww3SpiBMgfrR2gUajDYvUD+CFJjX5K33CF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igtQsAgAeCFAAADwQpAAAeCFIAADwQpAAAeCBIAQDwQJACAOCBIAUAwANBCgCAB4IUAAAPBCkAAB4IUgAAPBCkAAB4IEgBAPBAkAIA4IEgBQDAA0EKAIAHghQAAA8EKQAAHghSAAA8EKQAAHggSAEA8ECQAgDggSAFAMADQQoAgAeCFAAADwQpAAAeCFIAADwQpAAAeCBIAQDwQJACAOCBIAUAwANBCgCAB4IUAAAPBCkAAB4IUgAAPBCkAAB4IEgBAPBAkAIA4IEgBQDAA0EKAIAHghQAAA8EKQAAHghSAAA8EKQAAHggSAEA8ECQAgAwsiT5/4dHiRJTarSPAAAAAElFTkSuQmCC" alt="" />

②用dfs序维护一下子树信息,一个子树成为一个连续的一段,找x到y的第二个点可以LCA或者树剖每次往上跳即可。

③现在相当于每个盘子可以转化成一个矩形:整体二分,用扫描线的思想维护一下每次的答案。把所有矩形和询问点按横坐标的大小排序,想像有一条从左向右的直线,扫到的横坐标为一个矩形的起点是把这个区间的[l,r]加入树状数组里,终点时再去掉。询问变为纵坐标的询问就可以在树状数组内完成。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAACxCAYAAAArk2MCAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAARUSURBVHhe7d3dbtpAFIXR0Pv2/Z+TPgDF1EaDZZD5iX0me62boKhSnRPzZcZCmsPp7Ksnfw/ji7PffV06VPNr/AoEEgAIJgAQTAAgmABAMAGAYAIAwQQAggkABFv9ScDDofkE3o5Ox/HF2eHP+KIDw5irzLBXZvi++dv9qQCs/Kffa+GjwNNNUeL6FkyzKzPDBWb4vl5m2LIFgGACAMEEAIIJAAQTAAgmABBMACCYAEAwAYBgAgDBBACCCQAEEwAIJgAQTAAgmABAMAGAYAIAwQQAggkABBMACCYAEEwAIJgAQDABgGACAMFqHw3WHgMGc+PRcFU4GgzoigBAsH62ANNyz+nA36KXGS7eE0V0M8NG3wH4KQrcyALwvh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MACCYAEAwAYBYX1//AJVjeiDMBU+6AAAAAElFTkSuQmCC" alt="" />

 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = ;
int n,m;
int o,hd[N],v[*N],nt[*N],son[N],top[N],size[N],st[N],ed[N],dep[N],idx,fa[N],ans[N],k;
char gc(){
static char *p1,*p2,s[];
if(p1==p2) p2=(p1=s)+fread(s,,,stdin);
return(p1==p2)?EOF:*p1++;
}
int rd(){
int x = ,f = ; char c = gc();
while(c<''||c>'') {if(c=='-') f=-;c = gc();}
while(c>=''&&c<='') x=x*+c-'',c=gc();
return x*f;
}///
void adde(int x,int y){v[o]=y;nt[o]=hd[x];hd[x]=o++;} ///
void Adde(int u,int v){adde(u,v);adde(v,u);}///
void dfsA(int u){
size[u] = ; st[u] = ++idx;
for(int i=hd[u];i!=-;i=nt[i]){
if(v[i]==fa[u]) continue;
fa[v[i]] = u;
dfsA(v[i]);
size[u] += size[v[i]];
if(size[v[i]]>size[son[u]]) son[u] = v[i];
}
ed[u] = idx;
}///
void dfsB(int u,int Top){
top[u] = Top; dep[u]=dep[fa[u]]+;
if(son[u]) dfsB(son[u],Top);
for(int i=hd[u];i!=-;i=nt[i]){
if(v[i]==fa[u]||v[i]==son[u]) continue;
dfsB(v[i],v[i]);
}
}///
int find(int x,int y){
int tmp=x;
while(top[x]!=top[y]) tmp=top[x],x=fa[top[x]];
return x==y?tmp:son[y];
}///
struct edge{int l,r,x1,y1,x2,y2,w;
bool operator <(const edge &a)const{return w<a.w;}
}e[N];///
struct A{int id,x,y,k;}a[N],tmp[N];///
struct B{int p,x,y,d;
bool operator<(const B&a)const{return p<a.p;}
}b[*N];///
struct C{int id,x,y;
bool operator<(const C&a)const{return x<a.x;}
}c[*N];///
int tot,cnt,bit[N],now[N];
void add(int x,int y){for(;x<=n;x+=x&-x)bit[x]+=y;}
int ask(int x){int ret=;for(;x;x-=x&-x)ret+=bit[x];return ret;}//
void erfn(int l,int r,int L,int R){
if(L>R) return ;
if(l==r){
for(int i=L;i<=R;i++) ans[a[i].id]=e[l].w;
return;
}
int mid=l+r>>,tb=,tc=,tl=L,tr=;
for(int i=l;i<=mid;i++){
if(e[i].x1<=e[i].y1){
b[++tb] = (B){e[i].l,e[i].x1,e[i].y1,};
b[++tb] = (B){e[i].r+,e[i].x1,e[i].y1,-};
}
if(e[i].x2<=e[i].y2){
b[++tb] = (B){e[i].l,e[i].x2,e[i].y2,};
b[++tb] = (B){e[i].r+,e[i].x2,e[i].y2,-};
}
}
sort(b+,b+tb+);
for(int i=L;i<=R;i++){
c[++tc] = (C){i,a[i].x,a[i].y};
c[++tc] = (C){i,a[i].y,a[i].x};
now[i] = ;
}
sort(c+,c+tc+);
int j=;
for(int i=;i <= tc;i++){
while(j<=tb&&b[j].p<=c[i].x) add(b[j].x,b[j].d),add(b[j].y+,-b[j].d),j++;
now[c[i].id]+=ask(c[i].y);
}
for(int i=j;i<=tb;i++) add(b[i].x,b[i].d),add(b[i].y+,-b[i].d);
for(int i=L;i<=R;i++){
if(now[i]>=a[i].k) a[tl++] = a[i]; else a[i].k-=now[i],tmp[tr++] = a[i];
}
for(int i=tl;i<=R;i++) a[i] = tmp[i-tl];
erfn(l,mid,L,tl-); erfn(mid+,r,tl,R);
}//
int main()
{ freopen("bzoj4009.in","r",stdin);
freopen("bzoj4009.out","w",stdout);
n=rd(); m=rd(); k=rd();
for(int i=;i<=n;i++) hd[i]=-;
for(int i=;i<n;i++) Adde(rd(),rd());
dfsA();
dfsB(,);
for(int i=,x,y,w;i<=m;i++){
x=rd(),y=rd(),w=rd();
if(dep[x]<dep[y]) swap(x,y);
if(st[x]>=st[y]&&ed[x]<=ed[y])
{
y=find(x,y);
e[++tot]=(edge){st[x],ed[x],,st[y]-,ed[y]+,n,w};
}
else e[++tot]=(edge){st[x],ed[x],st[y],ed[y],,,w};
}
sort(e+,e+tot+);
for(int i=,x,y,w;i<=k;i++){
x=rd(),y=rd(),w=rd();
a[++cnt]=(A){i,st[x],st[y],w};
}
erfn(,tot,,cnt);
for(int i =;i <= k;i++) printf("%d\n",ans[i]);//
}//by tkys_Austin;

【bzoj4009 hnoi2015】接水果的更多相关文章

  1. [BZOJ4009][HNOI2015]接水果(整体二分)

    [HNOI2015]接水果 时间限制:60s      空间限制:512MB 题目描述 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC 了The b ...

  2. BZOJ4009: [HNOI2015]接水果

    4009: [HNOI2015]接水果 Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC 了The big black,  她 ...

  3. 2018.10.02 bzoj4009: [HNOI2015]接水果(整体二分)

    传送门 整体二分好题. 考虑水果被盘子接住的条件. 不妨设水果表示的路径为(x1,y1)(x_1,y_1)(x1​,y1​),盘子表示的为(x2,y2)(x_2,y_2)(x2​,y2​) 不妨设df ...

  4. [bzoj4009] [HNOI2015]接水果 整体二分+扫描线+dfs序+树状数组

    Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC 了The big black, 她觉得这个游戏太简单了,于是发明了一个更 加 ...

  5. bzoj4009: [HNOI2015]接水果(整体二分)

    题目描述 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, 她觉得这个游戏太简单了,于是发明了一个更加难的版本. 首先有 ...

  6. bzoj4009 [HNOI2015]接水果 整体二分+扫描线+树状数组+dfs序

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4009 题解 考虑怎样的情况就会有一个链覆盖另一个链. 设被覆盖的链为 \(a - b\),覆盖 ...

  7. 【BZOJ4009】[HNOI2015]接水果 DFS序+整体二分+扫描线+树状数组

    [BZOJ4009][HNOI2015]接水果 Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, ...

  8. 【BZOJ4009】接水果(整体二分,扫描线)

    [BZOJ4009]接水果(整体二分,扫描线) 题面 为什么这都是权限题???,洛谷真良心 题解 看到这道题,感觉就是主席树/整体二分之类的东西 (因为要求第\(k\)大) 但是,读完题目之后,我们发 ...

  9. BZOJ 4009: [HNOI2015]接水果

    4009: [HNOI2015]接水果 Time Limit: 60 Sec  Memory Limit: 512 MBSubmit: 636  Solved: 300[Submit][Status] ...

  10. 洛谷 P3242 [HNOI2015]接水果 解题报告

    P3242 [HNOI2015]接水果 题目描述 风见幽香非常喜欢玩一个叫做 \(osu!\) 的游戏,其中她最喜欢玩的模式就是接水果.由于她已经\(DT\) \(FC\) 了\(\tt{The\ b ...

随机推荐

  1. Android Notification setLatestEventInfo方法已废弃

    代替setLatestEventInfo的方法是用Notification.Builder创建Builder对象,通过该对象设置Notification相关属性. otification.Builde ...

  2. 算法题丨Move Zeroes

    描述 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...

  3. vSphere Client 搭建Windows server 2008 r2 服务器指南

    下载准备 下载并安装vSphere Client 链接:https://pan.baidu.com/s/1v0IrGrMjpA2FGeqagaJN-g 密码:zzd1 下载Windows server ...

  4. hadoop2.6.0实践:002 检查伪分布式环境搭建

    1.检查网络配置[root@hadoop-master ~]# cat /etc/sysconfig/networkNETWORKING=yesHOSTNAME=hadoop-masterGATEWA ...

  5. 阿里云API网关(13)请求身份识别:客户端请求签名和服务网关请求签名

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  6. GIT入门笔记(6)- 向版本库添加文本文件

    1.把文本文件添加到版本库? 所有的版本控制系统,其实只能跟踪文本文件的改动,比如TXT文件,网页,所有的程序代码等等,Git也不例外. 版本控制系统可以告诉你每次的改动,比如在第5行加了一个单词&q ...

  7. vue2.0+koa2+mongodb实现注册登录

    前言 前段时间和公司一个由技术转产品的同事探讨他的职业道路,对我说了一句深以为然的话: "不要把自己禁锢在某一个领域,技术到产品的转变,首先就是思维上的转变.你一直做前端,数据的交互你只知道 ...

  8. Easyui Datagrid 修改显示行号列宽度

    EasyUI中Datagrid的第一列显示行号,可是如果数据量大的的时候,显示行号的那一列数据会显示不完全的. 可以通过修改Datagrid的样式来解决这个问题,在样式中加入下面这个样式,就可以自己修 ...

  9. django关闭调试信息,打开内置错误视图

    1 内置错误视图 Django内置处理HTTP错误的视图,主要错误及视图包括: 404错误:page not found视图 500错误:server error视图 400错误:bad reques ...

  10. JavaScript实现面向对象

    /* js实现面向对象的方法 */ // 1 工厂模型 不推荐 function Person(name , sex , age){ obj = {}; obj.name = name; obj.se ...