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 ...
随机推荐
- POJ 3070 Fibonacci(矩阵快速幂)
题目链接 题意 : 用矩阵相乘求斐波那契数的后四位. 思路 :基本上纯矩阵快速幂. #include <iostream> #include <cstring> #includ ...
- Linux查看机器型号
dmidecode | grep “Product Name”
- floodlight 中两个互相矛盾的地方
floodlight中,添加防火墙规则,0表示最高优先级,数字越大,优先级越低;但是在StaticFlowPusher中写flow的时候,0表示最低优先级,数字越大,优先级越高,32767为最高. f ...
- QQ拼音还是不行哇
QQ拼音还是不行啊,虽说没广告,但是很多词条没有,例如知乎.蒋京虎. 泰囧……
- hibernate.cfg.xml hibernate 配置文件模板
<?xml version='1.0' encoding='UTF-8'?> <!--表明解析本XML文件的DTD文档位置,DTD是Document Type Definition ...
- QAQ高精度模板笔记√
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #i ...
- json的数据格式(仔细查看)
1.json对象就是jsonObject,jsonobject里可以放入很多键值对,并以逗号为分隔符. jsonObject里还可以嵌套JsonObject对象,或者数组信息作为value,数组作为k ...
- SULogger:iOS日志可视化工具
前言 debug对于咋们程序员来说家常便饭,但有时候我们会遇到一种情况:开发某个功能时,需要在某个特定场景下进行调试,而这个场景并没有MacBook来进行连接debug,偏偏我们需要获得调试时的一些信 ...
- Photoshop:制作金属质感-不锈钢纹理
效果图 过程: 1.滤镜->渲染->云彩 2.滤镜->模糊->高斯模糊 3.滤镜->杂色->添加杂色 ,数量10 4.滤镜->模糊->径向模糊 5.滤镜 ...
- PowerDesigner连接Oracle数据库建表序列号实现自动增长
原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...