Multi-school questions, put the math problem, but did not want to come out, stupid explosion, before the half-day s[i][j] and, in fact, is a product. In fact, when the game I even log (S[i][j]) +1 is s[i][j] The number of bits have not seen, said to be ashamed.
After knowing this, we enumerate the binary number of each bit, because the elements are non-negative, so the sum of the array is non-descending, here used to the ruler, before also heard, should have done it, do not remember.
Because [2k-1,2k] the number of bits is k, when enumerating, fixed the left end, in the sum array to find the smallest greater than or equal to 2k-1, the largest point less than 2k, the middle point and the left end of the s[i][j] for the current K satisfies the condition, the answer to the answer, the complexity is O ( NLOGN)
In fact, my Code does not have AC, has been time-out, but I did some of the limits of the data on this machine is also the second out, of course, the reason for my program, but I do not know how the matter, spent so much time, and so on.
Haha turned out to be a compiler problem, before the C + +, just handed the hair g++ on a,
1#include <iostream>2#include <cstdio>3#include <fstream>4#include <algorithm>5#include <cmath>6#include <deque>7#include <vector>8#include <queue>9#include <string>Ten#include <cstring> One#include <map> A#include <stack> -#include <Set> - #defineLL Long Long the #defineINF 0x3f3f3f3f - #defineOpen_file - #defineMAXN 100005 - using namespacestd; + LL SUM[MAXN], P[MAXN]; - LL ans; + intMain () A { at #ifdef Open_file -Freopen ("In.txt","R", stdin); - //freopen ("OUT.txt", "w", stdout); - #endif //Open_file - intT; -scanf"%d", &T); inp[0] =0; -p[1] =2; to for(inti =2; I <= the; i++){ +P[i] = p[i-1] *2; - } the for(intCAS =1; CAS <= T; cas++){ * intN; $scanf"%d", &n);Panax Notoginsengmemset (SUM,0,sizeof(sum)); - intx; the for(inti =1; I <= N; i++){ +scanf"%d", &x); ASum[i] = sum[i-1] +x; the } +Ans =0; - for(inti =0; I <= -; i++){ $LL left =1, right =1; $ for(intj =1; J <= N; J + +){ -left =Max (LL) J, left); -right =Max (LL) J, right); the while(Left <= n && sum[left]-sum[j-1] <P[i]) { -left++;Wuyi } the //int right = left; - while(Right <= n && sum[right]-sum[j-1] < P[i +1]){ Wuright++; - } Aboutright--; $ if(Right >N) { -right =N; - } - if(Left <=Right ) { AAns + = (((left + right) * (Right-left +1)) /2) + (Right-left +1) * j) * (LL) (i +1); + } the } - if(P[i +1] >Sum[n]) { $ Break; the } the } theprintf"%i64d\n", ans); the } -}
HDU 5358 First one math + ruler