【BZOJ2588】【Spoj 10628.】 Count on a tree 可持久化线段树+lca

思科路由器、交换机组网实验报告 通过思科模拟器搭建路由交换网络 阅读详情

链接:

#include <stdio.h>
int main()
{
    puts("转载请注明出处[vmurder]谢谢");
    puts("网址:blog.youkuaiyun.com/vmurder/article/details/45048639");
}

题解:

对于每个树上节点存一个版本的可持久化线段树,为它到根节点上所有权值的权值线段树(需要离散化)。
然后对于每次询问,这条链(a,b)的线段树就是:线段树a+线段树b−线段树lca−线段树falca
然后线段树上求第k小啦。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 101000
#define LOGN 20
#define LS s[last].l
#define RS s[last].r
#define ls s[now].l
#define rs s[now].r
using namespace std;
struct LSH
{
    int x,id;
    void read(int i){id=i;scanf("%d",&x);}
    bool operator < (const LSH &a)const
    {return x<a.x;}
}lsh[N];
int n,m,p;
struct Eli
{
    int v,next;
}e[N<<1];
int head[N],cnt,val[N];
inline void add(int u,int v)
{
    e[++cnt].v=v;
    e[cnt].next=head[u];
    head[u]=cnt;
}
struct Segment_Tree
{
    int l,r,x;
}s[N*LOGN];
int root[N];
void add(int last,int &now,int x,int L=1,int R=p)
{
    now=++cnt;
    if(L==R)s[now].x=s[last].x+1;
    else {
        int mid=L+R>>1;
        if(x<=mid)add(LS,ls,x,L,mid),rs=RS;
        else add(RS,rs,x,mid+1,R),ls=LS;
        s[now].x=s[ls].x+s[rs].x;
    }
}
int query(int a,int b,int A,int B,int k,int L=1,int R=p)
{
    int x=s[s[a].l].x+s[s[b].l].x-s[s[A].l].x-s[s[B].l].x;
    if(L==R)return L;
    int mid=L+R>>1;
    if(k<=x)return query(s[a].l,s[b].l,s[A].l,s[B].l,k,L,mid);
    else return query(s[a].r,s[b].r,s[A].r,s[B].r,k-x,mid+1,R);
}
int fa[N][LOGN],dep[N];
void dfs(int x,int p)
{
    fa[x][0]=p;
    dep[x]=dep[p]+1;
    add(root[p],root[x],val[x]);
    int i,v;
    for(i=head[x];i;i=e[i].next)
    {
        v=e[i].v;
        if(v==p)continue;
        dfs(v,x);
    }
}
void array()
{
    for(int k=1;k<LOGN;k++)
        for(int i=1;i<=n;i++)
            fa[i][k]=fa[fa[i][k-1]][k-1];
}
int getlca(int x,int y)
{
    if(dep[x]<dep[y])swap(x,y);
    for(int k=LOGN-1;~k;k--)
        if(dep[fa[x][k]]>=dep[y])
            x=fa[x][k];
    if(x==y)return x;
    for(int k=LOGN-1;~k;k--)
        if(fa[x][k]!=fa[y][k])
            x=fa[x][k],y=fa[y][k];
    return fa[x][0];
}
int lastans;
int main()
{
    int i,a,b,c;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)lsh[i].read(i);
    sort(lsh+1,lsh+n+1);
    for(i=1;i<=n;i++)
    {
        if(i==1||lsh[i].x!=lsh[i-1].x)lsh[++p].x=lsh[i].x;
        val[lsh[i].id]=p;
    }
    for(cnt=0,i=1;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        add(a,b),add(b,a);
    }
    cnt=0,dfs(1,0);
    array();
    while(m--)
    {
        scanf("%d%d%d",&a,&b,&c),a^=lastans;
        i=getlca(a,b);
        a=query(root[a],root[b],root[i],root[fa[i][0]],c);
        lastans=lsh[a].x;
        printf("%d\n",lastans);
    }
    return 0;
}
YOLOv9原创自研:卷积魔改 | 一种新颖的风车形卷积(PConv)融合注意力机制,加强微弱小目标检测能力 为了进一步提升小目标检测能力,风车形卷积(PConv)融合注意力机制进一步提升小目标检测能力 阅读详情

相关推荐

QGIS-空间分析-核密度分析

本文在QGIS软件中使用核密度估计法分析全球历年的地震数据,旨在分析出地震频发且严重的区域,为地震防控提供参考依据。全球历年地震数据来源于网络,仅用于技术学习探索。通过核密度分析,可以观察到南美、美国西部海岸线和太平洋北部区域在全球地震分布状态中是最为集中和强烈的。

imxiezy的博客 2467

bzoj2588树上主席树

2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MB Submit: 6896  Solved: 1668 [Submit][Status][Discuss] Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和

maxtir的博客 419

ENVI5.6 自动化流程:GF系列卫星影像批处理与质量优化

本文详细介绍了如何利用ENVI5.6构建针对GF-2、GF-6、GF-7系列卫星影像的自动化批处理流水线。通过配置Batch Processing工具,实现从正射校正到图像融合的全流程批量处理,并分享参数设置、质量监控与故障排查的实战经验,旨在显著提升海量遥感影像的处理效率与成果质量。

efc1234567的博客 603

BZOJ-2588-Count on a tree(树上主席树+LCA模板)

题目 Reaper 题解: 每个点的前向是它的父亲,建立n(n个节点)的前缀树。 ac=lca(x,y),acfa=fa[ac][0]; left=sum[t[x].l]+sum[t[y].l]-sum[t[ac].l]-sum[t[acfa].l]; 也就是 x+y-ac-acfa=x-ac+y-ac+(ac-acfa); Sample Input 8 5 105 2 9 3 8 5 7 7...

qq_42576687的博客 192

华为C语言笔试题(附答案)

华为C语言笔试题(附答案)     1、局部变量能否和全局变量重名?   答:能,局部会屏蔽全局。要用全局变量,需要使用 ":: "   局部变量可以与全局变量同名,在函数内引用这个变量时,会用到同名的局部变量,而不会用到全局变量。对于有些编译器而言,在同一个函数内可以定义多个同名的局部变量,比如在两个循环体内都定义一个同名的局部变量,而那个局部变量的作用域就在那个循环体内。  

峰云四起 3033

遥感大模型核心技术之自监督预训练技术研究(2025年9月版)

本文系统探讨了自监督预训练技术在遥感大模型构建中的核心作用。随着遥感数据进入"大数据"时代,传统监督学习面临"数据丰富、标签贫乏"的瓶颈,而自监督预训练通过设计代理任务从无标签数据中学习特征表示,成为驱动大模型发展的关键引擎。文章分析了遥感领域对自监督预训练的三大独特挑战:多源异构性、地理空间约束和时空动态性,并提出了针对性解决方案:掩码自编码(MAE)技术及其演进、地理对比学习与多模态融合、位置感知预训练与多任务学习。

panshengwu的博客 842

[BZOJ2588]Count on a tree

第一步:离散化 即:把节点的点权换成它在所有点权中的排名(它是第几小的) 将存储点权的数组复制一份之后排序,去重,然后将原先的每个点权在去重后的数组里进行二分查找,就可以得到它的排名。 第二步:建主席树 每个节点维护它到根的路径上的权值线段树,所以每个节点可以利用它的父节点更新,所以将整棵树dfs一遍,在此过程中建树。 第三步:求解 用u点的主席树+v点的主席树-lca(u,v)的主席

*★,°*:.☆( ̄▽ ̄)/$:*.°★* 251

STM32定时器ARR寄存器详解:从‘水桶接水’到精准测速,你的PWM和编码器都靠它

本文深入解析STM32定时器ARR寄存器的核心原理与应用技巧,从PWM波形生成到编码器测速实战。通过水桶模型和硬件本质的比喻,揭示ARR如何作为定时器的'心跳节拍器',并详细探讨其在动态调频、死区时间配置和高精度PWM中的关键作用。特别针对编码器模式下的ARR配置和溢出补偿算法进行优化建议,帮助工程师提升系统性能和实时性。

weixin_33734785的博客 379

[BZOJ2588]Count on a tree(可持久化权值线段树|主席树)

忍耐,也是一件美好的事,但前提是你有非常清晰的未来版图,你知道忍耐这一段后,会有什么等着你,你愿意为此暂时收起自己的羽毛。

zyf2000 1205

【清华大学软院】15-19年推免试题历年整理

整理的题目为清软预推免机试(外校)硕士机考题目。 年代 题目1 题目2 题目3 2019 质因数分解 二叉搜索树 区间DP(折叠字符串) 2018 日期转换 高精度模拟 区间DP(戳气球) 2017 进制素数 被遗漏的数字 DP(收集苹果) 2016 大数运算 DP DFS 2015 进制素数: http://acm.hdu.edu.cn/showproblem.php?pid=1230 2017年题目(这个是找的最准确的题目): 1题见【链接】 2题见【链接】

云端筑梦师 2256

告别License烦恼:手把手教你用VS Code+Cppcheck搭建免费的MISRA-C代码检查环境

本文详细介绍了如何使用VS Code和开源工具Cppcheck搭建免费的MISRA-C代码检查环境,帮助开发者规避商业工具的高额License费用。通过四步环境搭建和实战技巧,实现高效的代码静态检查,提升嵌入式开发的安全性和可靠性。

weixin_42523326的博客 248

BZOJ 2588 Count on a tree 主席树+倍增LCA

题目大意:给定一棵树,每个节点有权值,询问两个节点路径上的权值第k小 这题很卡时间。。。 树链剖分+二分+树套树的O(nlog^4n)做法可以去死了 没有修改操作,树链剖分+二分+划分树O(nlog^3n),还是死了 我怒了,裸学了一发可持久化线段树(不看任何代码OTZ,我是怎么做到的0.0),二分+主席树,O(nlog^2n),居然还是死了! 最后发现我SB了,完全没有必要二分,直

世界 2717

fanuc机器人KAREL程序间参数的传递

之前的课程中讲述过KAREL程序中函数参数的传递,而控制工业机器人的动作只能通过控制TP程序来实现,所以在实际应用中就会出现在不同程序间进行参数的传递。尤其是对于有模块化编程的思想的设计者,更有这种迫切的要求。所以本次课程来讲解一下如何实现在不同程序之间进行参数的传递。 本次课程分为两个部分,以讲解在不同类型程序间进行参数传递的实现方式。 1、TP程序之间传递参数; 2、TP与PC程序之间传递参数。

haier123888的博客 2696

BZOJ - 2588 Spoj 10628. Count on a tree (可持久化线段树+LCA/树链剖分)

题目链接 第一种方法,dfs序上建可持久化线段树,然后询问的时候把两点之间的所有树链扒出来做差。 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10,inf=0x3f3f3f3f; 5 int hd[N],ne,n,n2,...

weixin_30713953的博客 149

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

BZOJ 2588: Spoj 10628. Count on a tree-可持久化线段树+LCA(点权)(树上的操作) 无语(为什么我的LCA的板子不对)...

2588: Spoj 10628. Count on a tree Time Limit:12 SecMemory Limit:128 MBSubmit:9280Solved:2421[Submit][Status][Discuss] Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这...

weixin_30745641的博客 129

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

主席树 || 可持久化线段树 || LCA || BZOJ 2588: Spoj 10628. Count on a tree || Luogu P2633 Count on a tree...

题面:Count on a tree 题解: 主席树维护每个节点到根节点的权值出现次数,大体和主席树典型做法差不多,对于询问(X,Y),答案要计算ans(X)+ans(Y)-ans(LCA(X,Y))-ans(father[LCA(X,Y)]) 代码: 1 #include<cstdio> 2 #include<cstring> 3 ...

weixin_30551947的博客 142

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

bzoj2588: Spoj 10628. Count on a tree

链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2588 题意:中文题。 分析:树上建可持久化线段树,从父亲那继承。查询的时候减去lca和lca的父亲两个前缀即可。详见代码。O(nlogn+mlogn) 代码: #include #include #include #include #include #include #include

Fsss 701

[BZOJ2588]Spoj 10628. Count on a tree

题意 给定一个有n个结点的树,在线询问两个点之间路径上第k大的点的点权是多少。 分析 其实刚开始看到这道题的想法是树链剖分出log条链在同时在可持久化线段树上查询第k大。但是这样写起来并不优雅而且很难写。 然后考虑每次其实相当于取出两条点到某个祖先的链找第k大,所以这里的可持久化线段树可以不基于dfs序,而是直接用父亲结点的线段树。 然后这样就只需要求一个lca,然后开始的时候建一棵可持...

Umbrella__的博客 323

bzoj 2588 Spoj 10628. Count on a tree

Description给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权。其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文。Input第一行两个整数N,M。 第二行有N个整数,其中第i个整数表示点i的权值。 后面N-1行每行两个整数(x,y),表示点x到点y有一条边。 最后M行每行两个

Time_major 478

bzoj2588:Count on a tree(可持久化线段树+Lca)

2588: Spoj 10628. Count on a tree Time Limit: 12Sec  Memory Limit: 128 MB Submit: 5524  Solved: 1306 Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权。其中lastans是上一个询问的

KsCla 785

bzoj 2588 Spoj 10628. Count on a tree

Description给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权。其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文。Input第一行两个整数N,M。 第二行有N个整数,其中第i个整数表示点i的权值。 后面N-1行每行两个整数(x,y),表示点x到点y有一条边。 最后M行每行两个整数(

Time_major 分殿 329

[BZOJ2588]Spoj 10628. Count on a tree 可持久化线段树

离散化 对每个节点,用线段树表示该节点到根的路径上的值域 然后可持久化询问的时候查询u,v,LCA(u,v),fa[ LCA(u,v)]结点上的四棵线段树 做一做减法就好notice: 1、初始的权值已经超过了int,需要long long 2、最后一组询问的换行符不要输出!(我已经邮件了一发管理员希望他改题面)写起来很好写#include <iostream> #include <cst

HbFS- 424

bzoj 2588 Spoj 10628. Count on a tree (可持久化线段树)

Spoj 10628. Count on a tree Time Limit:12 SecMemory Limit:128 MBSubmit:7669Solved:1894[Submit][Status][Discuss] Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第...

weixin_30245867的博客 118

【BZOJ】2588: Spoj 10628. Count on a tree

【BZOJ】2588: Spoj 10628. Count on a tree 传送门 http://www.lydsy.com/JudgeOnline/problem.php?id=2588 Solution 读入玩得太骚玩挂了QwQ每个点维护它到根的这条链上的所有权值 使用值域线段树,可以用类似于可持久化的方法

Pure_W的博客 648

【BZOJ】【2588】COT(Count On a Tree)

可持久化线段树   maya……树么……转化成序列……所以就写了个树链剖分……然后每个点保存的是从它到根的可持久化线段树。   然后就像序列一样查询……注意是多个左端点和多个右端点,处理方法类似BZOJ 1901   然后rausen(Orz!!!)粗来跟我说:你直接减去lca和fa[lca]不就好啦~搞树剖还多一个log……   我恍然大悟!然后两个都交了一下,事实证明:我链剖写的还...

weixin_30498921的博客 129

【bzoj2588】Spoj 10628. Count on a tree

Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权。其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文。 Input 第一行两个整数N,M。 第二行有N个整数,其中第i个整数表示点i的权值。 后面N-1行每行两个整数(x,y),表示点x到点y有一条边。 最后M行

wang_sj的博客 334
上一篇: 【BZOJ2298】【HAOI2011】problem a 动态规划
下一篇: 【BZOJ1912】【Apio2010】巡逻 树上最长链(才不是树的直径呢)
空灰冰魂
博客等级 码龄12年 83粉丝 392原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值