HDU 5,358-School 6th first one

Source: Internet
Author: User

First oneTime limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 672 Accepted Submission (s): 193


Problem Descriptionsoda have an integer array a 1 , a 2 ,... .., a n . Let S(i,J) Be the sum of a i , a i+1 ,... .., a J . Now soda wants to know the value below: ∑ i = 1 n ∑j=in (? log 2 S (I,J)?+1)x(I+J)
Note:in This problem, can consider log20 As 0.

Inputthere is multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤5 ) The number of integers in the array.
The next line contains n Integers a 1 , a 2 ,... .., a n ( 0 ≤ a i ≤ 10 5 " .
Outputfor each test case, output the value.
Sample Input
121 1

Sample Output
12

Source2015 multi-university Training Contest 6


First of all, test instructions is not a problem, is to give you the number of groups, let you ask that formula, s for I to J and.

Game time to think of a two-point, is the statistical log2 may appear, a total of 34, and then ask for a prefix and, prefix and is incremented, can be two points, wrote

Complexity is not good, thought 33*n*log (n) can, the result knelt an afternoon, yesterday so happy kneeling

After the game to say with two hands sweep again, have to spit Groove, MD is English.

Lenovo to a bestcoder there is a problem is to find a total sequence of two number and modulus of the largest, I used to do is the sort of two points, and the positive solution is two pointers sweep over, but I do not remember

This question on the card this log (n) but I just can't get through, eh, or the mind is limited

This morning, I got A * n.

Ideas:

The array is processed into a prefix and the log classification, there are 35 cases, the title of the log (0) is 0, the need for a special sentence, the maximum sum value of the title is 10^10, so there are 35 cases,

So, it's a matter of discussion, a loop, which is enumeration n. Then found two values one is sum[i-1] + 2^j position, there is a location of sum[i-1]+2^ (j+1), this interval of the log value is all J, with the arithmetic progression summation formula can be calculated instantly the value of this interval, and only two markers to sweep again, Why is it possible to sweep only once, the value of the sum array is incremented, the value to be looked up is also incremented, so the next time you look for it, you just need to continue to connect after the last search.

/****************************************** multi-university Training Contest 6** 1006 First one** HDU 5358** by Cala mity_coming**************************************/#include <bits/stdc++.h>using namespace Std;typedef long    Long Ll;const int max_long = 1e5;ll A[max_long + 10];ll Sum[max_long + 10];ll cf2[40];void init () {ll k = 1;    for (int i=0; i<=34; ++i) {Cf2[i] = (k<< (i));    }}int Main () {init ();    int t;    scanf ("%d", &t);        while (t--) {int n;        scanf ("%d", &n);        Sum[0] = 0;            for (int i=1; i<=n; ++i) {scanf ("%i64d", &a[i]);        Sum[i] = sum[i-1] + a[i];//prefix and processing} sum[n+1] = 1E17;        ll ans = 0;            0 for (int i=1; i<=n; ++i)//0 more special, to special dry {int p = i;            while (Sum[p]==sum[i-1] && p<=n+1) {++p;            }--p; if (p>=i) {ans + = (lL) (i*3+p) * (LL) (p-i+1)/2; }} for (int j=0; j<=33; ++j)//This is each case {int p1 = 0,P2 = 0;//with two pointers sweep over for (int I=1; i<=n;                ++i)//When I increments, the new p1,p2 must be in the back {ll ADC = Sum[i-1] + cf2[j];                while (SUM[P1]&LT;ADC && p1<=n) {++p1;                } ADC = Sum[i-1] +cf2[j+1];                while (SUM[P2]&LT;ADC && p2<=n+1) {++p2;                }--P2;                if (p2>=p1 && p2) {ans + = (j+1) * (LL) (I*2+P1+P2) * (LL) (p2-p1+1)/2;    }}} printf ("%i64d\n", ans); } return 0;}




Copyright NOTICE: This article is calamity_coming original article, cannot reprint without permission.

HDU 5,358-School 6th first one

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.