codeforces 696 A. Lorenzo Von Matterhorn
来源:互联网 发布:淘宝买火车票靠谱吗 编辑:程序博客网 时间:2024/04/24 05:34
题意:
给出一棵二叉树,结点i和结点2*i,2*i+1相连,q次操作
操作1:将u->v路径上的权值加上c
操作2:询问u->v路径上权值和
分析:
乍一看以为是什么高级数据结构,然而仔细分析以下题目,其实并不是,根据二叉树的特性,结点i除以2就可以得到它的父节点,那么每次操作只需要u和v除2一直到u=v就能够得到这条路径,在路径上记录权值就不成问题了,由于结点范围较大,所以我用的map存
#include<cstring>#include<string>#include<iostream>#include<queue>#include<cstdio>#include<algorithm>#include<map>#include<cstdlib>#include<cmath>#include<vector>//#pragma comment(linker, "/STACK:1024000000,1024000000");using namespace std;#define INF 0x3f3f3f3fmap<long long ,long long>mp;int main(){ int t; cin>>t; while(t--) { int op; cin>>op; if(op==1) { long long a,b,c; cin>>a>>b>>c; while(a!=b) { if(a<b) swap(a,b); mp[a]+=c; a/=2; } } else { long long a,b,ans=0; cin>>a>>b; while(a!=b) { if(a<b) swap(a,b); ans+=mp[a]; a/=2; } cout<<ans<<endl; } } return 0;}
0 0
- Codeforces 696A Lorenzo Von Matterhorn ( LCA )
- codeforces 696 A. Lorenzo Von Matterhorn
- Codeforces 696A Lorenzo Von Matterhorn(LCA)
- Codeforces 696A. Lorenzo Von Matterhorn(map离散化)
- CodeForces 696 A. Lorenzo Von Matterhorn(水~)
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
- codeforces C. Lorenzo Von Matterhorn
- codeforces 696A Lorenzo Von Matterhorn (from:Codeforces Round #362 div 2)
- Codeforces Round #362 (Div. 1) A (696A) Lorenzo Von Matterhorn (LCA)
- codeforces #362(div2) C. Lorenzo Von Matterhorn
- Codeforces-697C Lorenzo Von Matterhorn
- Codeforces Round #362 Lorenzo Von Matterhorn
- CodeForces 697C Lorenzo Von Matterhorn
- Codeforces 697C Lorenzo Von Matterhorn 题解
- Codeforces Round #362 (Div. 1) A. Lorenzo Von Matterhorn(map&LCA)
- 解题报告:Codeforces Round #362 (Div. 1) A. Lorenzo Von Matterhorn 树状概率DP
- Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn(暴力)
- Codeforces Round #362 (Div. 2) C Lorenzo Von Matterhorn
- procfs文件系统
- 爬虫, 从python2 到 python3
- 循环队列(Circular Queue)
- cocoa touch——NSLabel——排版
- HTC Vive 新体验——奥秘之家VR实体店之行
- codeforces 696 A. Lorenzo Von Matterhorn
- C++自动创建命名的txt文件以及读写txt文件
- Activity之Task
- Iphone 客户端 exchange 配置
- Linux(3)RedHat7 基本命令二-ls命令详解
- 解决 Genymotion下无法安装apk的问题
- 互斥锁与条件变量
- 快速排序法 C++
- 将Ubuntu的“桌面”改为“Desktop”