题目链接:

  http://codeforces.com/problemset/problem/696/A

题目大意:

  一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边权都为0

  N(N<=1000)个操作,操作两种,1是从u到v的路径上的所有边权+w,2是求u到v的边权和。(1 ≤ v, u ≤ 1018, v ≠ u, 1 ≤ w ≤ 109)

题目思路:

  【STL】【模拟】

  用map写很快,第一次用很生疏。现学只看了一点点。

  因为是满二叉树所以直接暴力求LCA和求解,把每条边全加上w,因为数很大 所以用map映射查找修改。

 //
//by coolxxx
////<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 1004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
map<LL,LL>t;
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j;
LL x,y,z;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
for(i=;i<=n;i++)
{
scanf("%d",&j);j--;
if(!j)
{
scanf("%I64d%I64d%I64d",&x,&y,&z);
while(x!=y)
{
if(x>y)
t[x]+=z,x>>=;
else
t[y]+=z,y>>=;
}
}
else
{
scanf("%I64d%I64d",&x,&y);
z=;
while(x!=y)
{
if(x>y)z+=t[x],x>>=;
else z+=t[y],y>>=;
}
printf("%I64d\n",z);
}
}
}
return ;
}
/*
// //
*/

最新文章

  1. Login 页面
  2. Matlab验证公式取值范围
  3. Python的数据处理学习(二)
  4. How to delete a team project from Team Foundation Service (tfs.visualstudio.com)
  5. double 类型运算会出现精度问题
  6. js获取当前的时间(包含星期)
  7. 为iPhone6设计自适应布局(一)
  8. MPreview.js
  9. asp.net 总结
  10. Android Studio中.9.png文件出错问题
  11. str-字符串功能介绍
  12. c# 委托(Func、Action)
  13. How to resolve CSRF protection error while adding service through Ambari api
  14. JDK8 lameda表达式学习例子
  15. Centos6中Docker使用中国官方镜像加速
  16. C# 之TripleDESCryptoServiceProvider类加密/解密程序
  17. ubuntu 用 apt get 安装某个包的某个版本
  18. POJ 2503 单词映射(map)
  19. Redis 常用监控信息命令总结
  20. Python 3.6 安装pip

热门文章

  1. Oracle中wm_concat()的使用方法
  2. 第四篇:python基础之dict、set及字符
  3. 16、SQL Server 复制及常见错误处理
  4. 知识点摸清 - - position属性值之relative与absolute
  5. sql yog注册码
  6. 用PHP实现一个高效安全的ftp服务器(二)
  7. 40个DBA日常维护的SQL脚本--1113
  8. JSP技术
  9. javascript基础学习(六)
  10. (一)Nodejs - 框架类库 - Nodejs异步流程控制Async