codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,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 水题的更多相关文章
- codeforces 696A A. Lorenzo Von Matterhorn(水题)
题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...
- CodeForces 696A Lorenzo Von Matterhorn (LCA + map)
方法:求出最近公共祖先,使用map给他们计数,注意深度的求法. 代码如下: #include<iostream> #include<cstdio> #include<ma ...
- CodeForces 696A:Lorenzo Von Matterhorn(map的用法)
http://codeforces.com/contest/697/problem/C C. Lorenzo Von Matterhorn time limit per test 1 second m ...
- #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 ...
- 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 ...
- Lorenzo Von Matterhorn(STL_map的应用)
Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- PHP-Phalcon框架中的数据库操作
> 本文描述了PHP-Phalcon框架中数据库操作方法,主要讨论Phalcon框架的Model组件中的操作方法.更详细的Model介绍请参考:官方文档 1. 连接数据库 在Phalcon框架中 ...
- 防止注入网上查了下用SqlParameter可以,那SqlParameter处理单引号时候是自动转义了吗
String sql = String.Format(); SqlCommand com = new SqlCommand(sql, con); 一般而言,把 一个单引号,替换成 两个单引号就可以了.
- HTML5入门4---HTML5 与 HTML4 同一网页的不同写法
HTML4写法 css: body { font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana ...
- ios开发--27个提升效率的iOS开源库推荐
超长慎入列表: DZNEmptyDataSet(UI,空表格视图解算器) PDTSimpleCalendar(UI,drop-in日历组件) MagicalRecord(实施活跃记录模式的Core D ...
- 开发版本控制git
git init 在git命令行中依次输入 touch readme.txt并回车, git add . 点代表所有, git commit -m "init first"并回车, ...
- NGUI中Button与原生2D精灵的混合使用
一些废话 每一篇的首段都是这个“一些废话”,原因是我太能逼逼了,不逼逼一些废话我就觉得难受.这是我第四篇关于Unity的博文,前两篇还是去年写的,“从一点儿不会开始”系列,类似教程和学习笔记的博文,这 ...
- TCL语言笔记:TCL中的数组
一.介绍 Tcl 中的数组和其他高级语言的数组有些不同:Tcl 数组元素的索引,或称键值,可以是任意的字符串,而且其本身没有所谓多维数组的概念.数组的存取速度要比列表有优势,数组在内部使用散列表来存储 ...
- 9、JPA_映射双向一对一的关联关系
双向一对一的关联关系 举例说明:经理Manager和部门Department是双向一对一关联关系.则Manager实体类中有Department实体对象的引用,反之亦然. 其实体属性定义如下: Lis ...
- [转]更新Debian软件源
转自:香神无涯 sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak #备份一下软件源sudo vi /etc/apt/sources.lis ...
- 量化生产力Quantifying Productivity
I'm always on a lookout for interesting datasets to collect, analyze and interpret. And what better ...