这题一眼看就是水题,map随便计

然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层

我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽量不用

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = 3e6;
const LL mod = 1e9+;
map<LL,LL>mp;
int get(LL x){
for(int i=;;++i){
LL tmp1=(1ll<<i);
LL tmp2=(1ll<<(i+))-;
if(x>=tmp1&&x<=tmp2)return i;
}
}
int main(){
int q;
scanf("%d",&q);
while(q--){
LL u,v,w;
int op;
scanf("%d%I64d%I64d",&op,&u,&v);
int curu=get(u),curv=get(v);
if(curu<curv){swap(u,v);swap(curu,curv);}
if(op==){
scanf("%I64d",&w);
while(curu>curv){
if(mp.find(u)==mp.end())mp[u]=w;
else mp[u]+=w;
u>>=;--curu;
}
while(u!=v){
if(mp.find(u)==mp.end())mp[u]=w;
else mp[u]+=w;
if(mp.find(v)==mp.end())mp[v]=w;
else mp[v]+=w;
u>>=;v>>=;
}
}
else{
w=;
while(curu>curv){
if(mp.find(u)!=mp.end())w+=mp[u];
--curu;u>>=;
}
while(u!=v){
if(mp.find(u)!=mp.end())w+=mp[u];
if(mp.find(v)!=mp.end())w+=mp[v];
u>>=;v>>=;
}
printf("%I64d\n",w);
}
}
return ;
}

codeforces 696A Lorenzo Von Matterhorn 水题的更多相关文章

  1. codeforces 696A A. Lorenzo Von Matterhorn(水题)

    题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...

  2. 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn

    题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...

  3. CodeForces 696A Lorenzo Von Matterhorn (LCA + map)

    方法:求出最近公共祖先,使用map给他们计数,注意深度的求法. 代码如下: #include<iostream> #include<cstdio> #include<ma ...

  4. CodeForces 696A:Lorenzo Von Matterhorn(map的用法)

    http://codeforces.com/contest/697/problem/C C. Lorenzo Von Matterhorn time limit per test 1 second m ...

  5. #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 ...

  6. CF 696 A Lorenzo Von Matterhorn(二叉树,map)

    原题链接:http://codeforces.com/contest/696/problem/A 原题描述: Lorenzo Von Matterhorn   Barney lives in NYC. ...

  7. Lorenzo Von Matterhorn

    Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...

  8. C. Lorenzo Von Matterhorn LCA

    C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. Lorenzo Von Matterhorn(STL_map的应用)

    Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. PowerDesigner 逆向工程 从SQL文件转换成PDM 从PDM转成CDM

    从SQL文件逆向工程到PDM: ①选择file -> Reverse Engineer - > Database ②在General选项卡中选择MySQL数据库,点击确定. ③using ...

  2. 如何在Mininet中修改host的IP地址

    how to update virtual host's IP in mininet? I got it! do like this: mininet> py h1.setIP('10.0.0. ...

  3. springmvc环境的搭建

    最近应公司要求,用了2天时间学了springmvc的搭建,就简单总结一下: springmvc和struts2的比较,因为我是学过struts的,它们都是基于mvc模式而设计的web层框架 它们最大的 ...

  4. LR_问题_无法使用LR的Controller,提示缺少license

    问题描述 无法使用LR的Controller,提示缺少license 问题解决 使用开始->所有程序->HP LoadRunner->loadrunner,在打开界面的左上角选择co ...

  5. apache配置优化

    最近参加了很多面试,多多少少有点小感悟,可以说观念转变了不少,特别是对于作为一个开发人员的定位,原来只是认为开发人员就只需要写好代码就行了,所以只需要有数据结构,算法,设计模式,重构方面的知识就行了. ...

  6. HTML5入门6---视频播放按钮

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. DAO设计模式 -- 使用数据库连接类连接MySql数据库并实现添加用户

    1. DAO简介    DAO设计模式是属于J2EE数据库层的操作,使用DAO设计模式可以简化大量代码,增强程序的可移植性. 2. DAO各部分详解    DAO设计模式包括5个重要的部分,分别为数据 ...

  8. word文档标题级别批量更改——批量降级与升级实例

    word文档标题级别批量更改——批量降级与升级实例   word文档标题级别批量更改——批量降级实例 2012年12月21日16:30:44 现有一个3级文档结构的word文档,如下图所示 先需要将上 ...

  9. player/stage 学习---安装

    环境 ubuntu 14.04 一,工具安装 sudo apt-get install git cmake g++ fltk1.1-dev libjpeg8-dev libpng12-dev libg ...

  10. Java API —— BigDecimal类

    1.BigDecimal类概述  由于在运算的时候,float类型和double很容易丢失精度,演示案例.所以,为了能精确的表示.计算浮点数,Java提供了BigDecimal 不可变的.任意精度的有 ...