Codeforces Round #276 (Div. 2) C. Bits (constructor)

Source: Internet
Author: User

You can directly construct the answer to this question.

For the binary representation of l, change it from right to left to 1. If it cannot be changed again (then l is greater than r), the answer is l.

This method ensures that the answer is greater than or equal to l and less than or equal to r, and that the value of 1 in binary representation is the most.

# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <cmath> # include <map> # include <set> # include <vector> # include <algorithm> # include <stack> # include <queue> # include <cctype> # include <sstream> using namespace std; # define pii pair <int, int> # define LL long intconst int eps = 1e-8; const int INF = 1000000000; const int maxn = 10000 + 5; int n; LL l, r, p; int main () {// freopen ("in9.txt", "r", stdin); // freopen ("out.txt", "w", stdout ); scanf ("% d", & n); while (n --) {scanf ("% I64d % I64d", & l, & r); p = 1; while (1) {if (l | p)> r) {printf ("% I64d \ n", l); break;} else {l | = p; p * = 2 ;}}// fclose (stdin); // fclose (stdout); return 0 ;}

 

Codeforces Round #276 (Div. 2) C. Bits (constructor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.