【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
把序列生成的过程看成一颗树
会发现最后形成的是一颗二叉树。
每个二叉树上的节点就对应了序列中的一个数字。
如果我们把每个节点都往下投影的话。
(而且整棵树都是左右对称的。那么每个子树的根节点就是(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的更多相关文章
- 【博弈论】【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> ...
- 【概率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 ...
- 【基数排序】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 ...
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- POJ 2661Factstone Benchmark(斯特林公式)
链接:传送门 题意:一个人自命不凡,他从1960年开始每10年更新一次计算机的最长储存长数.1960年为4位,每10年翻一倍.给出一个年份y,问这一年计算机可以执行的n!而不溢出的最大n值 思路:如果 ...
- [COCI2007]PRAVOKUTNI
题目大意:在一个平面上,有\(N\)个点,求这些点构成的直角三角形个数.解题思路:枚举直角顶点,对于每个点,将这个点当做原点,对其他点按极角排序,然后双指针扫一遍,判断弧度差即可. C++ Code: ...
- myeclipse反编译安装 jd-gui.exe下载
一:在线安装 1.Help->Install New Site Name:** Location:http://jd.benow.ca/jd-eclipse/update 二:手动安装 1.下载 ...
- TCL命令(事务控制)
确认提交DML操作:commit; 撤销DML操作:rollback; 提示:rollback撤销的是与上一个commit之间 所做的DML操作.注意:仅对 ...
- SQL注入、占位符拼接符
一.什么是SQL注入 官方: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意 ...
- SQL SERVER-NULL
SQL SERVER判断NULL的函数 ISNULL().NVL().IFNULL() 和 COALESCE() 函数 来自为知笔记(Wiz)
- cocos2d-x学习笔记(18)--游戏打包(windows平台)
cocos2d-x学习笔记(18)--游戏打包(windows平台) 之前做好的游戏,都是在vs2008下编译执行的.假设说想把游戏公布到网上或者和其它人一起分享游戏,那就得对游戏 ...
- OS 中文斜体 Italic Font Chinese - iOS_Girl
CGAffineTransform matrix = CGAffineTransformMake(1, 0, tanf(15 * (CGFloat)M_PI / 180), 1, 0, 0); UI ...
- leetcode第一刷_Reverse Linked List II
翻转链表绝对是终点项目,应该掌握的,这道题要求的是翻转一个区间内的节点.做法事实上非常相似,仅仅只是要注意判定開始是头的特殊情况,这样head要更新的,还有就是要把翻转之后的尾部下一个节点保存好,要么 ...
- xcode5.1生成framework,支持arm64报错
错误例如以下: ld: Assertion failed: (_machoSection != 0), function machoSection, file /SourceCache/ld64/ld ...