Advertisement
hkshakib

Untitled

Feb 2nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. scanf("%d",&t);
  7. while(t--)
  8. {
  9. int n,q;
  10. scanf("%d%d",&n,&q);
  11. long long a[n+5]={0};
  12. long long x;
  13. for(int i=1; i<=n; i++)
  14. {
  15. scanf("%lld",&x);
  16. long long c=0;
  17. while(x>1)
  18. {
  19. if(x%2==0)
  20. {
  21. x=x/2;
  22. c++;
  23. }
  24. else
  25. {
  26. x--;
  27. c++;
  28. }
  29. }
  30. a[i]=a[i-1]+c;
  31. }
  32. for(int i=1; i<=q; i++)
  33. {
  34. int y,z;
  35. scanf("%d%d",&y,&z);
  36. printf("%d\n",a[z]-a[y-1]);
  37. }
  38. for(int i=1;i<=n;i++)
  39. a[i]=0;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement