【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
题目链接:
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 ;
}
/*
// //
*/
【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn的更多相关文章
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- 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 ...
- codeforces 696A A. Lorenzo Von Matterhorn(水题)
题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...
- #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 ...
- Lorenzo Von Matterhorn(STL_map的应用)
Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CF 696 A Lorenzo Von Matterhorn(二叉树,map)
原题链接:http://codeforces.com/contest/696/problem/A 原题描述: Lorenzo Von Matterhorn Barney lives in NYC. ...
- A. Lorenzo Von Matterhorn
A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Lorenzo Von Matterhorn
Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...
随机推荐
- linux系统时间同步更新
linux中的时钟分为系统时钟和硬件时钟.硬件时钟通过bioss进行设置,系统时钟通过linux kernel进行设置.当linux启动时,bioss会读取系统时钟的时钟设置.在linux中涉及时间设 ...
- oracle重建、更新索引、索引统计信息命令
在oracle中查找所有的表的索引的命令 select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_na ...
- rabbitmq 消息持久化
rabbitmq 消息持久化 2016-02-18 11:19 224人阅读 评论(0) 收藏 举报 分类: 综合(15) 版权声明:本文为博主原创文章,未经博主允许不得转载. 二: 任务分发 & ...
- [O] SQLite数据库报错:no such column
在SQLite数据库创建语句增加列,运行后报错:no such column 在语法规范的前提下,即 //SQLite数据库创建,逗号与空格须严格 String CREATE_NOTE = " ...
- c# 双问号运算
model.id??0 ??运算:如果运算符左边的值为NULL侧返回右边的值,否则返回左边的值
- 解决kernel headers报错
Make sure you have updated version $ sudo apt-get update Search for kernel version (optional) $ apt- ...
- magic_quotes_gpc、mysql_real_escape_string、addslashes的区别及用法
本篇文章,主要先重点说明magic_quotes_gpc.mysql_real_escape_string.addslashes 三个函数方法的含义.用法,并举例说明.然后阐述下三者间的区别.关系.一 ...
- 华硕_ZX50JX4200 安装ssd固态盘
本人亲身的一次经历,帮朋友的华硕手提装一个内存和ssd固态 内存5分钟搞定,但是ssd固态盘就经过了一番的折腾 首先要拧掉所有后盖的螺丝,把光驱拆下来,注意撬开键盘板的时候有排线,不能弄断了.然后一定 ...
- nginx 跨域。。。掉坑里了,小心
今天公司产品一个功能突然挂掉了...向客户演示之前出现了,手机端显示不能获取下载资源,可是急坏了一票人.. 通过手机端,调查服务器地址调用了http:/2342342.domain.hostname. ...
- [Client]动检参数讨论与ONVIF
[问题]客户端访问ONVIF设备动检 客户端要访问ONVIF设备(IPC)的动检,一是事件,二是设置: 此处就是讨论如何设置动检区域的. 通过Video Analytics/Cell Motion D ...