【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
2024-08-23 06:49:06
题目链接:
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 ;
}
/*
// //
*/
最新文章
- Login 页面
- Matlab验证公式取值范围
- Python的数据处理学习(二)
- How to delete a team project from Team Foundation Service (tfs.visualstudio.com)
- double 类型运算会出现精度问题
- js获取当前的时间(包含星期)
- 为iPhone6设计自适应布局(一)
- MPreview.js
- asp.net 总结
- Android Studio中.9.png文件出错问题
- str-字符串功能介绍
- c# 委托(Func、Action)
- How to resolve CSRF protection error while adding service through Ambari api
- JDK8 lameda表达式学习例子
- Centos6中Docker使用中国官方镜像加速
- C# 之TripleDESCryptoServiceProvider类加密/解密程序
- ubuntu 用 apt get 安装某个包的某个版本
- POJ 2503 单词映射(map)
- Redis 常用监控信息命令总结
- Python 3.6 安装pip