这题一眼看就是水题,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. POJ2002Squares

    http://poj.org/problem?id=2002 题意 : 就是给你很多点的坐标,任取四个,看能组成多少个不同的正方形,相同的四个点,不同顺序构成的正方形视为同一正方形. 思路 : 就是一 ...

  2. redis、memcache、mongoDB有哪些区别(转载)

    转载: http://leandre.cn/database/64.html Memcached Memcached的优点: Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS ...

  3. Minimum_Window_Substring两种方法求解

    题目描述: Given a string S and a string T, find the minimum window in S which will contain all the chara ...

  4. 什么是struts2?

    一.我对struts2的理解. 1.struts2 是一个按MVC模式设计放入web层框架,其实它就是一个servlet.这个servlet命名为ActionServlet,或者是它的一个子类.它的工 ...

  5. Java类的加载、链接和初始化

    一.Java的类加载机制回顾与总结: 我们知道一个Java类要想运行,必须由jvm将其装载到内存中才能运行,装载的目的就是把Java字节代码转换成JVM中的java.lang.Class类的对象.这样 ...

  6. NSArray 迭代

    NSObject *obj=[[NSObject alloc]init];        NSArray *array=[[NSArray alloc] initWithObjects:@" ...

  7. PHP程序员最常犯的11个MySQL错误

    对于大多数web应用来说,数据库都是一个十分基础性的部分.如果你在使用PHP,那么你很可能也在使用MySQL—LAMP系列中举足轻重的一份子. 对于很多新手们来说,使用PHP可以在短短几个小时之内轻松 ...

  8. ios绘图时的坐标处理

    在iOS中,进行绘图操作时,一般主要是在UIView:drawRect中调用 UIGraphicsBeginImageContextWithOptions等一系列函数,有时候直接画图就行,比如UIIm ...

  9. Android View 绘制过程

    Android的View绘制是从根节点(Activity是DecorView)开始,他是一个自上而下的过程.View的绘制经历三个过程:Measure.Layout.Draw.基本流程如下图: per ...

  10. oracle视图总结(转)

    视图简介: 视图是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改.视图基于的表称为基表.视图是存储在数据字典里的一条select语句. 通过创建视图可以提取数 ...