hkshakib

Untitled

Feb 2nd, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pi acos(-1.0)
  4. //cout << fixed << setprecision(8) << a << endl;
  5. //cout << "Case " << ca << ": " << ans << endl;
  6. #define Fast_Input ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  7. const int mx = 1e5+5;
  8. vector < long long > a(mx);
  9. int main()
  10. {
  11. int t;
  12. scanf("%d",&t);
  13. while(t--)
  14. {
  15. int n,q,i,j,c,sum2=0;
  16. scanf("%d%d",&n,&q);
  17. for(i=1; i<=n; i++)
  18. {
  19. long long int x;
  20. scanf("%lld",&x);
  21. c=0;
  22. while(x>1)
  23. {
  24. if(x%2==0)
  25. {
  26. x=x/2;
  27. c++;
  28. }
  29. else
  30. {
  31. x--;
  32. c++;
  33. }
  34. }
  35. a[i]=a[i-1]+c;
  36. }
  37. for(i=1; i<=q; i++)
  38. {
  39. int y,z;
  40. cin >> y >> z;
  41. printf("%d\n",a[z]-a[y-1]);
  42. }
  43.  
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment