A weird bug on I/O

Правка en1, от duckladydinh, 2015-09-21 06:10:49

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 — __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) — 1); l-= u, r-= u, a+= u; } u = 1 << (len(r) — 1); u <<= (u + u — 1 == r && r > 1); cout << a+u-1 << "\n"; } return 0; } ` Thank you.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский duckladydinh 2015-09-21 06:14:16 42
en2 Английский duckladydinh 2015-09-21 06:12:22 28
en1 Английский duckladydinh 2015-09-21 06:10:49 1023 Initial revision (published)