Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- //cout << fixed << setprecision(8) << a << endl;
- //cout << "Case " << ca << ": " << ans << endl;
- #define Fast_Input ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
- const int mx = 1e5+5;
- vector < long long > a(mx);
- int main()
- {
- int t;
- scanf("%d",&t);
- while(t--)
- {
- int n,q,i,j,c,sum2=0;
- scanf("%d%d",&n,&q);
- for(i=1; i<=n; i++)
- {
- long long int x;
- scanf("%lld",&x);
- c=0;
- while(x>1)
- {
- if(x%2==0)
- {
- x=x/2;
- c++;
- }
- else
- {
- x--;
- c++;
- }
- }
- a[i]=a[i-1]+c;
- }
- for(i=1; i<=q; i++)
- {
- int y,z;
- cin >> y >> z;
- printf("%d\n",a[z]-a[y-1]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment