Codeforces Round #276 (Div. 2)

C. Bits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Let's denote as the number of bits set (">x.

You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l?≤?x?≤?r, and is maximum possible. If there are multiple such numbers find the smallest of them.

Input

The first line contains integer n — the number of queries (1?≤?n?≤?10000).vcD4KPHA+CkVhY2ggb2YgdGhlIGZvbGxvd2luZyA8ZW0+bjwvZW0+IGxpbmVzIGNvbnRhaW4gdHdvIGludGVnZXJzIDxlbT5sPC9lbT48ZW0+aTwvZW0+LD88ZW0+cjwvZW0+PGVtPmk8L2VtPiChqgogdGhlIGFyZ3VtZW50cyBmb3IgdGhlIGNvcnJlc3BvbmRpbmcgcXVlcnkgKDA/odw/PGVtPmw8L2VtPjxlbT5pPC9lbT4/odw/PGVtPnI8L2VtPjxlbT5pPC9lbT4/odw/MTAxOCkuPC9wPgoKCgpPdXRwdXQKPHA+CkZvciBlYWNoIHF1ZXJ5IHByaW50IHRoZSBhbnN3ZXIgaW4gYSBzZXBhcmF0ZSBsaW5lLjwvcD4KCgoKU2FtcGxlIHRlc3QocykKCgoKaW5wdXQKPHByZSBjbGFzcz0="brush:java;">3 1 2 2 4 1 10 output

1 3 7

Note

The binary representations of numbers from 1 to 10 are listed below:

110?=?12

210?=?102

310?=?112

410?=?1002

510?=?1012

610?=?1102

710?=?1112

810?=?10002

910?=?10012

1010?=?10102

看了我的代码,自己对照模拟下就知道思路了:

#include #include #include #include using namespace std; __int64 bit[65]; int main() { bit[0]=1; for(int i = 1; i r) { sum -= bit[j]; if(sum

点击复制链接 与好友分享!回本站首页
您对本文章有什么意见或着疑问吗?请到论坛讨论您的关注和建议是我们前行的参考和动力
上一篇:HDOJ1231DP
下一篇:BZOJ 3758 数数 分块打表
相关文章

Codeforces Round #124 (Div. 2)

Codeforces Round #131 (Div. 2)

CodeForces 180E Cubes--后续指针--

Codeforces Round #133 (Div. 2)

CodeForces Round #125 (198C) -

CodeForces Round #116 (180E) - Cubes

CodeForces Round #118 (185A) - Plant

CodeForces Round #118 - Mushroo

CodeForces Round #119 (187A)

CodeForces Round #119 (187B) -

图文推荐

Codeforces Round #276 (Div. 2)
ZOJ 3640 Help Me
Codeforces Round #276 (Div. 2)
CF 518C(Anya and
Codeforces Round #276 (Div. 2)
hdu 1016 Prime R
UVA - 11987 - A

分类:默认分类 时间:2015-03-05 人气:3
本文关键词:
分享到:

相关文章

Copyright (C) quwantang.com, All Rights Reserved.

趣玩堂 版权所有 京ICP备15002868号

processed in 0.066 (s). 10 q(s)