forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNonzero.cpp
75 lines (59 loc) · 1.32 KB
/
Nonzero.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define ll int
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pu push
#define db double
#define m_p make_pair
ll mod = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll arr[200001][22];
for(ll i=0;i<200001;i++)
{
for(ll j=0;j<22;j++)
arr[i][j]=0;
}
for(ll i=1;i<=200000;i++){
bitset<22> bset2(i);
for(ll j=0;j<22;j++)
{
if(bset2[j])
{
arr[i][j]=arr[i-1][j]+1;
}
else
{
arr[i][j]=arr[i-1][j];
}
}
}
ll t;
t=1;
cin>>t;
ll t1=t;
while(t1--)
{
///your code goes here/////
ll l,r;
cin>>l;
cin>>r;
ll ans=INT_MIN;
for(ll k=0;k<22;k++)
{
ll cur=arr[r][k]-arr[l-1][k];
ans=max(ans,cur);
}
ll ans1=(r-l)+1;
ans1-=ans;
cout<<ans1<<endl;
///code end here/////////////
}
return 0;
}