Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- scanf("%d",&t);
- while(t--)
- {
- int n,q;
- scanf("%d%d",&n,&q);
- long long a[n+5]={0};
- long long x;
- for(int i=1; i<=n; i++)
- {
- scanf("%lld",&x);
- long long c=0;
- while(x>1)
- {
- if(x%2==0)
- {
- x=x/2;
- c++;
- }
- else
- {
- x--;
- c++;
- }
- }
- a[i]=a[i-1]+c;
- }
- for(int i=1; i<=q; i++)
- {
- int y,z;
- scanf("%d%d",&y,&z);
- printf("%d\n",a[z]-a[y-1]);
- }
- for(int i=1;i<=n;i++)
- a[i]=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement