POJ 3321 Apple Tree(DFS+树状数组)

程序员未来真的会被淘汰吗? 实际上的计算机:web,图形学Q,Linux系统开发,一系列嵌入式开发,数据库,高性能服务器,中间件开发,三维建模,网络安全,通信协议°,加密算法,服务器集群维护,文件存储引擎Q,编译器,工业软件,客户端,计算机视觉,自然语言处理,算法调优,游戏引擎Q。实际上的计算机:web,图形学Q,Linux系统开发,一系列嵌入式开发,数据库,高性能服务器,中间件开发,三维建模,网络安全,通信协议°,加密算法,服务器集群维护,文件存储引擎Q,编译器,工业软件,客户端,计算机视觉,自然语言处理,算法调优,游戏引擎Q。 阅读详情

超级传送门:http://poj.org/problem?id=3321


题意:有一棵苹果树,每个分叉的交点或者末端刚开始都长有苹果,这些苹果可以被吃掉,也可以再长出来,但是每个位置上同时最多只有一个苹果。现在要查询指定的某棵子树上的苹果树。


分析:典型的树状数组求和问题,但是刚看题感觉很棘手,如何把一棵树映射到树状数组里?这里采用DFS改时间戳的方法,记两个数组begin和end,用begin[i]表示以i为根的子树遍历的第一个点,end[i]表示以i为根的子树遍历的最后一个点。

比如数据为:

5

1 2 

2 5 

2 4 

1 3


那么begin[] = {1, 2, 5, 4, 3}, end[] = {5, 4, 5, 4, 3},下标从1开始。

对于每个点都对应一个区间(begin[i], end[i]),如果要改变点a的状态,只要update(begin[a]),要求该子树的苹果树,即getsum(end[a] ) - getsum(begin[a] - 1)。

注意此题用vector建树会TLE,所以我用数组建树,最大分支数只开了20,比较危险,如果卡到分支数很大的数据就悲剧了,还好AC了。最好还是自己用结构体和指针动态建树。


代码:

#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn = 100005;
int c[maxn],a[maxn],begin[maxn],end[maxn],vis[maxn];
int t;
int tree[maxn][20],branchNum[maxn];
int n;
int lowbit(int t) {
    return t & -t;
}
int getsum(int end) {
    int ret = 0;
    for (int i=end;i>=1;i-=lowbit(i)) {
        ret += c[i];
    }
    return ret;
}
void update(int p,int val) {
    for (int i=p;i<maxn;i+=lowbit(i)) {
        c[i] += val;
    }
}
void dfs(int p) {
    if (vis[p]) return;
    vis[p] = 1;
    t++;
    begin[p] = t;
    for (int i=0;i<branchNum[p];i++) {
        int x = tree[p][i];
        dfs(x);
    }
    end[p] = t;
    return;
}
int main () {
    #ifndef ONLINE_JUDGE
        freopen("1.txt","r",stdin);
    #endif
    int x,y,q;
    char cmd[5];
    while (scanf("%d",&n)>0 && n) {
        memset(c,0,sizeof(c));
        memset(vis,0,sizeof(vis));
        memset(branchNum,0,sizeof(branchNum));
        for (int i=1;i<=n;i++) {
            memset(tree[i],0,sizeof(tree[i]));
            a[i] = 1;
        }
        for (int i=1;i<=n-1;i++) {
            scanf("%d%d",&x,&y);
            tree[x][branchNum[x]++] = y;
        }
        t = 0; //时间戳
        dfs(1);
        for (int i=1;i<=n;i++) {
            update(begin[i],1);
        }
        scanf("%d",&q);
        while (q--) {
            scanf("%s%d",cmd,&x);
            if (cmd[0]=='Q') {
                printf("%d\n",getsum(end[x])-getsum(begin[x]-1));
            } else if (cmd[0]=='C') {
                if (a[x]) {
                    update(begin[x],-1);
                    a[x] --;
                } else {
                    update(begin[x],1);
                    a[x] ++;
                }
            }
        }
    }
    return 0;
}


PyTorch强化学习实战(1)——强化学习(Reinforcement Learning,RL)详解 在本节中,开始进入探索强化学习 (Reinforcement Learning, RL) 之旅,首先剖析了强化学习的独特之处及其与监督学习、无监督学习范式的关系。随后系统学习了强化学习的基础形式化框架及其内部关联机制,并深入讲解了马尔可夫过程 (Markov Process, MP)、马尔可夫奖励过程 (Markov Reward Process, MRP) 和马尔可夫决策过程 (Markov Decision Process, MDP),为后续学习奠定基础。 阅读详情

相关推荐

智能体在车联网中的应用:第19天 智能体理论与初步实践 D30:阶段小结——在SUMO中使用TraCI控制预编程智能体

本文介绍了如何将强化学习从算法仿真迁移到交通系统实践,重点讲解了SUMO微观交通仿真平台与TraCI实时控制接口的架构。通过构建一个预编程驾驶智能体,演示了车辆从起点到目标点的导航控制。文章详细解析了TraCI的双向通信机制和事件驱动模型,对比了其与传统RL环境的差异,并提供了完整的Python实现框架,包括路网配置、车辆控制和基于向量场的导航逻辑。该实践为后续开发高级学习型交通智能体奠定了基础。

IT深耕十余载,大道之简 1479

【POJ 3321】 Apple Tree 树状数组 + DFS序(详解)

Description There is an apple tree outside of kaka’s house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree. The ...

待到山花烂漫时 657

PyCharm中Pyvips配置避坑指南:为什么pip安装后import还是报错?

本文详细解析了在PyCharm中配置Pyvips时,即使pip安装成功,import仍报错的根本原因。核心在于Pyvips依赖的libvips原生库未正确配置环境变量。文章提供了从下载libvips、配置Windows系统PATH到PyCharm项目级设置的完整避坑指南,并对比了三种配置策略,帮助开发者彻底解决DLL加载失败问题。

bush的博客 209

Poj3321 Apple Tree dfs序 + 树状数组

Poj3321 Apple Tree dfs序 + 树状数组 单点加 区间询问 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #i...

weixin_33842328的博客 157

【跳频通信】基于MATLAB的跳频通信系统仿真

同时,跳频通信也具有良好的抗干扰能力,即使有部分频点被干扰,仍能在其他未被干扰的频点上进行正常的通信。由于跳频通信系统是瞬时窄带系统,它易于与其他的窄带通信系统兼容,也就是说,跳频电台可以与常规的窄带电台互通,有利于设备的更新。跳频是最常用的扩频方式之一,其工作原理是指收发双方传输信号的载波频率按照预定规律进行离散变化的通信方式,也就是说,通信中使用的载波频率受伪随机变化码的控制而随机跳变。从通信技术的实现方式来说,“跳频”是一种用码序列进行多频频移键控的通信方式,也是一种码控载频跳变的通信系统。

FPGA/MATLAB学习教程/源码/项目合作开发 6267

深度学习与西储大学轴承数据集(一)

西储大学数据集介绍

weixin_50642818的博客 1万+

【树状数组】POJ 3321 Apple Tree

POJ 3321 DFS+树状数组

小do在努力 666

接入 AI 之后,为什么测试和排障还是没有真正变快?

如果你们准备做平台型 AI,不要先从聊天入口开始想。先把真实数据采上来;再把链路、版本、快照、报告这些核心对象建稳;再把历史沉淀、反馈、检索能力补齐;最后再让 AI 围绕这些对象去工作。这样做出来的 AI,才更容易从“看起来聪明”走向“真正省时间”。

专注 AI 精准测试平台实战落地,分享从代码 Diff 到回归决策的完整工程闭环。主张“先建数据链路,再上 AI 智能”,让测试从“靠经验”走向“基于风险”。 527

Apple Tree POJ - 3321 dfs序+树状数组

There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree. The tree hasN...

wa的一声就哭了 307

TI单芯片毫米波雷达1642demo代码走读(一)

今天我们来实际看下代码。 首先使用CCS软件导入demo工程,工程有两个,一个是ARM的工程,工程名是mmw_mss_16xx;另一个是DSP的工程,工程名为mmw_dss_16xx。我们将这两个工程的主函数打开,分别位于mss_main.c和dss_main.c文件中。 先看mss的主函数,代码如下。我为每行代码都加了中文注释和自己的理解。 int main (void) { Task_Params taskPara...

1万+

脑电信号处理实战 01 | 从 0 跑通第一个 EEG 分析:加载、滤波、频谱与“睁眼闭眼“

本文以 UCI 公开数据集"EEG Eye State"为例,从零走通脑电处理的完整流水线——数据加载、1–40 Hz 带通滤波、Welch 功率谱、频带功率、通道相关性与箱线图质控、睁闭眼对比和时频分析,并用 8 张科研风格图层层揭示这份数据中的伪迹与通道重复问题,说明"流程跑得通不等于结果可信,质量控制永远先行"。

qq_53529450的博客 116

POJ 3321 Apple Tree 树状数组+dfs序

题目:http://poj.org/problem?id=3321 题意:给出一个苹果树,开始每个节点都有一个苹果,有2个操作 C:有苹果就吃掉,没有就会长出一个苹果 Q:查询包括x的子树上苹果的个数 这个题目的关键就是怎么把它从一颗树转化成一个数组 可以用dfs序重新编号,保存节点所维护的区间,然后用树状数组可以解决了 #include<iostream&g...

dengyaodan0206的博客 166

基于STM32的智能宠物喂食系统设计与实现(代码+PCB )

STM32;DHT11;本系统的软件程序基于Keil MDK-ARM V5集成开发环境进行编写和编译。Keil MDK是ARM公司官方推荐的嵌入式开发工具,支持ARM Cortex-M系列微控制器的程序开发,内置ARM C/C++编译器、调试器和仿真器,具有代码编辑、语法高亮、工程管理和在线调试等功能,是STM32开发领域应用最为广泛的IDE之一。

3254968421的博客 72

poj3321 Apple Tree 树状数组+dfs序

                                         Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 34141   Accepted: 10231 Description There is an apple tree outside of...

OOOak 317

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ3321 Apple Tree(树状数组+dfs序)

题意:有n个点,每个点都有苹果,操作1 查询 点x的子树上有又多少个苹果包括自身,操作2 若点x上有苹果则摘下,没有则长出一个 思路:用树状数组去维护苹果树上的苹果个数,dfs序建树获取树上子树和根的区间。 #include <cstdio> #include <cstring> #include <algorithm> #include <set> #include<iostream> #include<vector> //#incl

Ray.C.L的博客 494

深度学习工具包 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")

poj 3321 Apple Tree 树状数组 dfs序

题目链接 参考资料: http://www.cnblogs.com/gj-Acit/p/3236843.html   ——再见~雨泉 题意: 给一棵树,初始时每个节点的 val 均为 1,现有一些操作, Q:将某个节点的 val 取反 C:询问以某个节点为根的子树的 val 总和 思路: dfs 一遍,将每个点的编号映射到 dfs 序,以 dfs 序来

kkkkahlua的博客 418

POJ3321Apple Tree(DFS序 +树状数组)

Apple Tree 题意:给出一棵树,n个节点,根节点1。有两种操作,(1)Q,xQ,xQ,x。(2)C,xC,xC,x。 (1).查询第x个节点, (2). // poj3233 #include<iostream> #include<cstdio> #include<vector> #include<map> #include<queue> #include<cstring> using namespace std; typede

weixin_45363113的博客 442

POJ 3321 Apple Tree(树状数组+DFS)

http://poj.org/problem?id=3321 一道搁置了好多天的树状数组 题意:有一颗苹果树,主干是1,下面会有分支,每个分支一个编号一直到n。每个分支只能有一个苹果或没有苹果。初始状态是每个分支一个苹果。示例:    5    1 2    1 3    3 5    3 4 它形成的树是这样的: 现在每个分支的苹果都是1。 下面是两种操作,Q

1341

[POJ - 3321] Apple Tree (树状数组+dfs序)

链接 http://poj.org/problem?id=3321 题意 给你一个nnn个节点的苹果树,开始这颗树上每个结点上都有一个苹果,现在需要你执行mmm次操作,操作分两种; C xC\ xC x,对结点xxx进行操作,如果结点xxx处有一个苹果就把它摘下来,如果没有它就重新生长出来一个; Q xQ\ xQ x,查询xxx所在子树苹果个数; 分析 ...

梧桐 293

POJ 3321-Apple Tree【树状数组+DFS序】

卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果。卡卡很喜欢苹果。树上有N个节点,卡卡给他们编号1到N,根的编号永远是1.每个节点上最多结一个苹果。卡卡想要了解某一个子树上一共结了多少苹果。 现在的问题是不断会有新的苹果长出来,卡卡也随时可能摘掉一个苹果吃掉。你能帮助卡卡吗? Input 输入数据:第一行包含一个整数N(N<= 100000),表示树上节点的数目。 接下来N-1...

独钓门前月 633

POJ 3321 Apple Tree 题解

POJ 3321题解

DarkoDu的博客 1032

【poj 3321】 Apple Tree 树状数组+dfs序

Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 23568 Accepted: 7118DescriptionThere is an apple tree outside of kaka’s house. Every autumn, a lot of apples will gro 树状数组+dfs

ATOD 1221

Apple Tree POJ - 3321(dfs序树状数组)

There is an apple tree outside of kaka’s house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree. The tree has N forks which are connected by branches. Kaka numbers the f

tomjobs的博客 690

POJ 3321 Apple Tree dfs序 树状数组

题目链接:POJ 3321 Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30613   Accepted: 9148 Description There is an apple tree outside of kaka's

teddywang 442

POJ-3321-Apple Tree dfs序树状数组

具体题目是,POJ-3321,这里不给了; 数据先给了n;代表了一共有n个编号(对于n个结点); 大致题意是给一颗根节点为编号1的树,以及接下来的n-1条边(x,y) 根据discuss区描述这条边就是x to y,不用考虑y to x;(这不是重点) 再是m个操作(点修改and这个点的子树的结点个数查询);   3 1 2 1 3 3 Q 1 C 2 Q 1 dfs序 后 用树状数...

zhonglong_lin的博客 1589

poj3321-Apple Tree-dfs序+树状数组

http://poj.org/problem?id=3321 给你一颗树,最初每个节点上都有一个苹果, 有两种操作:修改(即修改某一个节点值为0或1) 和查询(查询某一个节点的【子树】上有多少个苹果)   这个在树上跑一遍dfs,得到树的dfs序,每个节点管辖的区间就是in[x] - out[x] 这个区间上的节点都是 节点x的子节点,其中in[x]是x自身 那么接下来的对

缺氧 668

Apple Tree POJ3321 dfs序 + 树状数组

题意 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果。卡卡很喜欢苹果。树上有N个节点,卡卡给他们编号1到N,根的编号永远是1.每个节点上最多结一个苹果。卡卡想要了解某一个子树上一共结了多少苹果。现在的问题是不断会有新的苹果长出来,卡卡也随时可能摘掉一个苹果吃掉。你能帮助卡卡吗? 解题思路 此题我们的想法肯定是想将查询和修改都降为lognlognlogn的复杂度,这区间查询单点修改正好用树状数组或线段树解决即可。关键我们怎么将树转化为区间,即每颗子树都附上区间,dfsdfsdfs可以帮我们解决这个.

pursuit的博客 490
上一篇: POJ 2029 Get Many Persimmon Trees(二维树状数组)
下一篇: HDOJ 2852 KiKi's K-Number(树状数组)
Uranux
博客等级 码龄15年 16粉丝 53原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值