cf 697C Lorenzo Von Matterhorn 思维
题目链接:https://codeforces.com/problemset/problem/697/C
两种操作:
1是对树上u,v之间的所有边的权值加上w
2是查询树上u,v之间的边权和
树是满二叉树,用map存点到其父亲的边权值,对于操作一,当u!=v时我们先更新深度最大的点到其父亲的边权值,再令其等于其父亲,不断循环直至u=v。
操作二与操作一类似
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
#define ll long long
map<ll,ll>mp;
void update(ll x,ll y,ll val)
{
while(x!=y)
{
if(log(y)>log(x))swap(x,y);
mp[x]+=val;
x>>=;
}
}
ll query(ll x,ll y)
{
ll ret=;
while(x!=y)
{
if(log(y)>log(x))swap(x,y);
ret+=mp[x];
x>>=;
}
return ret;
}
int main()
{
mp.clear();
ll q,op,u,v,w;
cin>>q;
while(q--)
{
cin>>op;
if(op==)
{
cin>>v>>u>>w;
update(v,u,w);
}
else
{
cin>>v>>u;
cout<<query(v,u)<<endl;
}
}
return ;
}
cf 697C Lorenzo Von Matterhorn 思维的更多相关文章
- CF 696 A Lorenzo Von Matterhorn(二叉树,map)
原题链接:http://codeforces.com/contest/696/problem/A 原题描述: Lorenzo Von Matterhorn Barney lives in NYC. ...
- Lorenzo Von Matterhorn
Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...
- C. Lorenzo Von Matterhorn LCA
C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...
- #map+LCA# Codeforces Round #362 (Div. 2)-C. Lorenzo Von Matterhorn
2018-03-16 http://codeforces.com/problemset/problem/697/C C. Lorenzo Von Matterhorn time limit per t ...
- Lorenzo Von Matterhorn(STL_map的应用)
Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces 696A A. Lorenzo Von Matterhorn(水题)
题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...
- CodeForces 696A:Lorenzo Von Matterhorn(map的用法)
http://codeforces.com/contest/697/problem/C C. Lorenzo Von Matterhorn time limit per test 1 second m ...
- A. Lorenzo Von Matterhorn
A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 【CodeForces 697C】Lorenzo Von Matterhorn(LCA)
Least Common Ancestors 节点范围是1~1e18,至多1000次询问. 只要不断让深的节点退一层(>>1)就能到达LCA. 用点来存边权,用map储存节点和父亲连边的权 ...
随机推荐
- linux scull 的内存使用
在介绍读写操作前, 我们最好看看如何以及为什么 scull 进行内存分配. "如何"是需要全 面理解代码, "为什么"演示了驱动编写者需要做的选择, 尽管 sc ...
- linux scull 函数open 方法
open 方法提供给驱动来做任何的初始化来准备后续的操作. 在大部分驱动中, open 应当 进行下面的工作: 检查设备特定的错误(例如设备没准备好, 或者类似的硬件错误 如果它第一次打开, 初始化设 ...
- 中和IOS七层架构和TCP/IP四层架构的五层架构
五层架构分别为应用层.运输层.网络层.数据链路层.物理层. IOS架构把应用层又细分为应用层.表示层.会话层 TCP/IP把网络层改名网际层,数据链路层和物理层结合成网络接口层 其实只要学习五层协议, ...
- Canvas动画:地球绕着太阳转
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- ASP.NET MVC4.0+EF+LINQ+bui+bootstrap+网站+角色权限管理系统(4)
接下来就是菜单管理了,菜单分为两部分,一部分是菜单管理,另一部分是左边的树形菜单 数据库添加菜单表Menus USE [MVCSystem] GO /****** Object: Table [dbo ...
- 2018-10-23-WPF-使用-Pandoc-把-Markdown-转-Docx
title author date CreateTime categories WPF 使用 Pandoc 把 Markdown 转 Docx lindexi 2018-10-23 11:35:47 ...
- 2019前端学习路线心得-黑马程序员pink老师
在规划之前先给大家分享几点心得哈: 1. 学习,特别是在线学习,是非常辛苦的事情,为了少走弯路, 所以一定要系统学习,多借鉴与前辈们总结出来的经验. 2. 不要相信任何说 一周掌握 css, 一周学完 ...
- boostrap-非常好用但是容易让人忽略的地方【6】:role属性
普通样式,鼠标hover没有任何效果 <span>content</span> 加上role属性的样式,鼠标hover会有cursor:pointer的效果 <span ...
- Team Foundation Server 2015使用教程【3】:默认团队成员连接tfs及checkin操作
- RobotFramework+Appium 为了兼容iOS12,升级至Xcode10后,WebDriverAgent编译不通过:Undefind symbols for architecture x86_64
报错信息如下: Undefined symbols for architecture arm64: "_OBJC_CLASS_$_XCElementSnapshot", refer ...