Is __lg(0) problematic?

Правка en1, от rgnerdplayer, 2021-07-03 11:20:36

I was just doing virtual on 1338A - Powered Addition.

I wrote the following code: <spoiler summary="#include <bits/stdc++.h> using namespace std;

typedef long long ll;

typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll;

define mp make_pair

define fr first

define sc second

void solve() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } if (is_sorted(A.begin(), A.end())) { cout << 0 << '\n'; return; } int ans = 0, mx = -1e9; for (int i = 0; i < N; i++) { mx = max(mx, A[i]); ans = max(ans, __lg(mx — A[i]) + 1); } cout << ans << '\n'; }

int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ifndef ONLINE_JUDGE

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

endif

int t = 1;
cin >> t;
while (t--) solve();

return 0;

}"> ...

and it out puts "63" on this test.

...

But I thought __lg(0) is -1?

Does anyone have any idea?

(Also I tried to use custom invocation and try to exit once "ans" is changed to 63 but nothing happened.)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский rgnerdplayer 2021-07-03 11:39:22 108
en5 Английский rgnerdplayer 2021-07-03 11:38:01 460
en4 Английский rgnerdplayer 2021-07-03 11:24:37 10 Tiny change: 'ation and try to exit o' -> 'ation and attempted to exit o'
en3 Английский rgnerdplayer 2021-07-03 11:23:35 27 Tiny change: ' -2, 7, 5}\n\nBut I ' -> ' -2, 7, 5} on both versions of C++17.\n\nBut I '
en2 Английский rgnerdplayer 2021-07-03 11:21:40 1006
en1 Английский rgnerdplayer 2021-07-03 11:20:36 1305 Initial revision (published)