0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:31:59 +00:00

B - And It's Non-Zero

https://codeforces.com/contest/1615/submission/140464543
This commit is contained in:
Baoshuo Ren 2021-12-24 22:59:02 +08:00
parent 2784afa33b
commit 523f43341f
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

25
CodeForces/1615/B/B.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int t, l, r, b[200005][32];
int main() {
for (int i = 1; i < 200005; i++) {
for (int k = 0; k < 32; k++) {
b[i][k] = b[i - 1][k] + ((i >> k) & 1);
}
}
cin >> t;
while (t--) {
cin >> l >> r;
int max = 0;
for (int k = 0; k < 32; k++) {
max = std::max(max, b[r][k] - b[l - 1][k]);
}
cout << r - l + 1 - max << endl;
}
return 0;
}