【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

把序列生成的过程看成一颗树
会发现最后形成的是一颗二叉树。
每个二叉树上的节点就对应了序列中的一个数字。

如果我们把每个节点都往下投影的话。

(而且整棵树都是左右对称的。那么每个子树的根节点就是(l+r)/2了

就像是整个序列了。

(中序遍历

则我们可以用线段树求区间和的方法。

现在相当于告诉你1..n这个区间。

然后你要求l..r这个区间的和。

递归求就好。

【代码】

#include <bits/stdc++.h>
#define LL long long
using namespace std; LL n,l,r; LL dfs(LL n,LL L,LL R,LL l,LL r){
LL mid = (l+r)>>1;
LL temp = 0;
if (l==r) return n;
if (L<mid) temp+=dfs(n/2,L,R,l,mid-1);
if (mid<R) temp+=dfs(n/2,L,R,mid+1,r);
if(L<=mid && mid<=R) temp+=n%2;
return temp;
} int main()
{
cin >> n >> l >> r;
LL tot = 1,x = n;
while (x>1){
tot = tot + 1 + tot;
x>>=1;
}
cout<<dfs(n,l,r,1,tot)<<endl;
return 0;
}

【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1的更多相关文章

  1. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  2. 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...

  3. 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number

    发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...

  4. 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  6. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  7. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  8. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  9. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

随机推荐

  1. C语言基本语法——结构体、联合和枚举

    一.结构体 1.什么是结构体 2.结构体语法格式 3.结构体所占内存空间 4.结构体成员赋值 二.联合 1.什么是联合 2.联合语法格式 三.枚举 1.什么是枚举 2.枚举语法格式 一.结构体 1.什 ...

  2. PHP中的 Iterator 与 Generator

    在讲解生成器之前先介绍一下迭代器: 在 PHP 中,通常情况下遍历数组使用 foreach 来遍历. 如果我们要想让一个对象可以遍历呢? PHP 为我们提供了 Iterator 接口,只要实现了这个接 ...

  3. multiple definition of

    总结了解决multiple definition of的方法: 问题原因:    当多个文件包含同一个头文件时,并且你的.H里面没有加上条件编译#ifndef TEST_H#define TEST_H ...

  4. input输入框获取焦点是背景黄色去除

    input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset !important;}

  5. javascript-js常用插件集合

    area.js 中国地区分级的js代码  Scripts/crypto.js  CryptoJS (crypto.js) 为 JavaScript 提供了各种各样的加密算法               ...

  6. ASP.NET-表单验证-DataAnnotations

    DataAnnotations  [数据注解,数据注释] 需要引入两个脚本文件 <script src="@Url.Content("~/Scripts/jquery.val ...

  7. angular-数据库

    <div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng ...

  8. 洛谷——T P2136 拉近距离

    https://www.luogu.org/problem/show?pid=2136 题目背景 我是源点,你是终点.我们之间有负权环. ——小明 题目描述 在小明和小红的生活中,有N个关键的节点.有 ...

  9. java.util.UnknownFormatConversionException: Conversion = ''';

    今天在测试一个新的项目,在执行sql查询报表的时候.由于我的sql中带有%,导致在输出日志时报错“java.util.UnknownFormatConversionException: Convers ...

  10. jdk动态代理(转)

    一旦这样绑定后,那么在进入代理对象方法调用的时候就会到HelloServiceProxy的invoke方法上,invoke方法有三个参数:第一个proxy是代理对象,第二个是当前调用那个方法,第三个是 ...