Title: Log Warrior
ATM took part in the calculator training course, after hard cultivation, the logarithm of the base of 2 is fast, called the log heroes.
One day, log hero's friend DRD has some integer sequence needs to transform, the log warrior just displays the mana ...
The rule of transformation is that each integer of one of its subsequence becomes: [Log_2 (x) + 1] where [] means rounding down,
is to calculate the logarithm of 2 for each number and then remove the whole.
For example, after the sequence 3 4 2 is manipulated once, the sequence becomes 2 3 2.
DRD need to know how much the sequence will be after each such operation.
"Input Format"
The first line is two positive integers n m.
The second row n number, which represents the integer sequence, is positive.
Next m line, two number L R per line indicates that the ATM operation is interval [L, R], sequence number starting from 1.
"Output Format"
The output m line, in turn, represents the total sequence of the ATM after each operation.
For example, enter:
7 ·
5 6 4
1 2
2 3
1 3
The program should output:
10
8
6
"Data Range"
For 30% of data, N, M <= 10^3
For 100% of data, N, M <= 10^5
1#include <stdio.h>2#include <math.h>3 intMain () {4 intn,m;5 intsum=0;6scanf"%d%d",&n,&m);7 intA[n];8 for(intI=0; i<n;i++){9scanf"%d",&a[i]);Ten } One intL,r; A for(intI=0; i<m;i++){ -scanf"%d%d",&l,&R); - for(intj=l-1; j<=r-1; j + +){ the //for Element A[j], base 2 logarithm, plus 1, and then down rounding -A[J] = Floor (log2 (A[j]) +1); - } - for(intk=0; k<n;k++){ +sum+=A[k]; - } +printf"%d\n", sum); Asum=0;//sequence and placement 0 at } - return 0 ; -}
C language · Log Heroes