A weird bug on I/O
Difference between en2 and en3, changed 42 character(s)

Hi everyone.↵

I am working on 484A — Bits which should be an easy one. Unfortunately, I am facing a very strange thing that I have never seen before. Hope that someone can help me with it.↵

Below is my code, and the problem is this code gives WA on test 2, line 12th, when the statement a = 0 is after cin >> l >> r, but when I just put the statement a = 0 before cin >> l >> r, it gives WA on test 2, line 11th. However, in both cases, I test on my computer, both code are correct.↵



~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵
#define len(u) (64 
&mdash;- __builtin_clzll(u))↵

int n;↵
int64_t l, r, a, u;↵

int main(){↵
    cin >> n;↵
    while(n--){↵
        cin >> l >> r;↵
        a = 0;
/*HERE*/
        while(len(l) == len(r) && r > 0){↵
            u = 1 << (len(r) 
&mdash;- 1);↵
            l-= u, r-= u, a+= u;↵
        }↵
        u = 1 << (len(r) 
&mdash;- 1);↵
        u <<= (u + u 
&mdash;- 1 == r && r > 1);↵
        cout << a+u-1 << "\n";↵
    }↵
    return 0;↵
}↵

~~~~~↵



Thank you.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English duckladydinh 2015-09-21 06:14:16 42
en2 English duckladydinh 2015-09-21 06:12:22 28
en1 English duckladydinh 2015-09-21 06:10:49 1023 Initial revision (published)