#include<cstdio>
#include<iostream>
#define lowbit(x) x&(-x)
typedef long long ll;
using namespace std;
ll n,q,num,root;string s;
int main()
{
scanf("%I64d%I64d",&n,&q);
root=(n+)/;
for(ll q_i=;q_i<=q;q_i++)
{
cin>>num>>s;
for(int step=;step<s.size();step++)
{
ll lowbit_num=lowbit(num);//假设num这个节点是左子节点
if(s[step]=='U' && num!=root)
{
ll num_u=num+lowbit_num;//求出在假设情况下的num的父节点num_u
ll lowbit_num_u=lowbit(num_u);
if(num_u - lowbit_num_u/ == num) num=num_u;//如果根据父节点求出来的左孩子就是num,那么num确实是左子节点
else num=num-lowbit_num;//否则num就是右子节点
}
if(s[step]=='L') num-=lowbit_num/;
if(s[step]=='R') num+=lowbit_num/;
}
printf("%I64d\n",num);
}
}

思路来自http://blog.csdn.net/Courage_kn/article/details/69218592

用#define比定义一个lowbit函数快……不过好像很多时候不能像函数那样随便用,容易出问题……

这是分别用

long long lowbit(long long x){return x&(-x);}

#define lowbit(x) x&(-x)

情况下的耗时……

codeforces 792D - Paths in a Complete Binary Tree的更多相关文章

  1. 【codeforces 792D】Paths in a Complete Binary Tree

    [题目链接]:http://codeforces.com/contest/792/problem/D [题意] 给你一棵满二叉树; 给你初始节点; 给你若干个往上走,左走,右走操作; 让你输出一系列操 ...

  2. PAT1110:Complete Binary Tree

    1110. Complete Binary Tree (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  3. [Swift]LeetCode919. 完全二叉树插入器 | Complete Binary Tree Inserter

    A complete binary tree is a binary tree in which every level, except possibly the last, is completel ...

  4. A1110. Complete Binary Tree

    Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...

  5. PAT A1110 Complete Binary Tree (25 分)——完全二叉树,字符串转数字

    Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...

  6. PAT 甲级 1110 Complete Binary Tree

    https://pintia.cn/problem-sets/994805342720868352/problems/994805359372255232 Given a tree, you are ...

  7. 1110 Complete Binary Tree (25 分)

    1110 Complete Binary Tree (25 分) Given a tree, you are supposed to tell if it is a complete binary t ...

  8. [二叉树建树&完全二叉树判断] 1110. Complete Binary Tree (25)

    1110. Complete Binary Tree (25) Given a tree, you are supposed to tell if it is a complete binary tr ...

  9. PAT 1110 Complete Binary Tree[判断完全二叉树]

    1110 Complete Binary Tree(25 分) Given a tree, you are supposed to tell if it is a complete binary tr ...

随机推荐

  1. SpringMVC由浅入深day01_12.4 pojo绑定_12.5自定义参数绑定实现日期类型绑定_12.6集合类

    12.4 pojo绑定 页面中input的name和controller的pojo形参中的属性名称一致,将页面中数据绑定到pojo. 页面定义: controller的pojo形参的定义: 打断点测试 ...

  2. 5 -- Hibernate的基本用法 --1 2 基本映射方式

    ORM工具提供了持久化类和数据表之间的映射关系.实际上,所有的ORM工具大致上都遵循相同的映射思路,ORM基本映射有如下几条映射关系: ⊙ 数据表映射类 : 持久化类被映射到一个数据表.程序使用这个持 ...

  3. vuejs解析url地址

    函数: // url解析函数 // ?id=111&name=567 => {id:111,name:567} export function urlParse(){ let obj = ...

  4. MyBatis入门程序之Mapper代理方式

    Mapper代理的开发方式,程序员只需要编写mapper接口(相当于dao接口)即可,MyBatis会自动为mapper接口生成动态代理实现类. 一.开发规范 1.mapper接口的全限定名要和map ...

  5. 【代码审计】iZhanCMS_v2.1 后台存在多个SQL注入漏洞分析

      0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...

  6. 团购已满,O2O只是个笑话吗?

    团购的用户习惯经过多年的“发酵”以后,大多数用户的团购习惯已经养成,同样一张电影票团购和直接现场购买的差价在一倍以上,当然O2O领域的其他情况也差不多,面对明显的“优惠”,用户当然乐意使用团购服务. ...

  7. flask操作mongo两种方式--常规

    #manage.py #coding=utf-8 #Flask-Script是一个可以在flask应用外部编写脚本的扩展 #常用功能: #运行一个开发的服务器 #python shell中操作数据库看 ...

  8. STL——空间配置器(SGI-STL)

    一. 空间配置器标准接口 参见<STL源码剖析>第二章-2.1.<memory>文件. 二.具备次配置力的SGI空间配置器 1. SGI STL的配置器与众不同,也与标准规范不 ...

  9. JS 运行、复制、另存为 代码。

    //运行代码 function runEx(cod1) { cod = document.getElementById(cod1) var code = cod.value; if (code != ...

  10. linux 查看版本

    输入"uname -a ",可显示电脑以及操作系统的相关信息. 输入"cat /proc/version",说明正在运行的内核版本.输入"cat /e ...