First One

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 881    Accepted Submission(s): 273

 soda has an integer array $a_1,a_2,\dots,a_n$. Let $S(i,j)$ be the sum of $a_i,a_i+1,\dots,a_j$. Now soda wants to know the value below:
 \[\sum_{i = 1}^{n}\sum_{j = i}^{n}(\lfloor \log_{2}{S(i,j)} \rfloor + 1)\times (i+j) \]
Note: In this problem, you can consider $\log_{2}{0}$ as 0.
 
Input
There are 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 \geq n \leq 10^5)$,the number of integers in the array.
The next line contains n integers $0 \leq a_{i} \leq 10^{5}$
 
Output
For each test case, output the value.
 
Sample Input
1
2
1 1
 
Sample Output
12
 
Source
解题:这道题目有意思,我们可以发现 $a_{i} \leq 10^{5}$ 这是一个信息,破题的关键.
 
$\log_{2}{sum}$大概会在什么范围呢?sum最多是 $10^{5} \times 10^{5} = 10^{10}$
也就是说$\log_{2}{sum} \leq 34$ 
 
才35,sum的特点是什么?很明显都是非负数,那么sum必须是递增的,单调的,F-100. 我们可以固定$log_{2}{S(i,j)}$ 后 固定左区间j,找出以j作为左区间,然后当然是找出最小的r 和 最大的 R
 
最小 最大?当然是这样的区间,该区间的和取对数是我们刚刚固定的那个数。区间可以表示成这样 $[j,r\dots R]$ 那么从j到r,j到 r+1,...,j 到R ,这些区间的和取对数都会等于同一个数。。
 
好了如何算$[j,r\dots R]$ 的下标和?很明显吗。。j r,j r+1, j r+2,..., j R.把左区间下标一起算了,右区间是个等差数列,求和。
 
我们在最后把那个表达式里面的1加上
同样的计算方法
 
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
LL p[] = {},sum[maxn];
void init() {
for(int i = ; i <= ; ++i)
p[i] = (p[i-]<<);
}
int main() {
init();
int kase,n;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
for(int i = ; i <= n; ++i){
scanf("%I64d",sum+i);
sum[i] += sum[i-];
}
LL ret = ;
for(int i = ; i <= && p[i] <= sum[n]; ++i){
int L = ,R = ;
LL tmp = ;
for(int j = ; j <= n; ++j){
while(L <= n && sum[L] - sum[j-] < p[i]) ++L;
while(R + <= n && sum[R + ] - sum[j-] < p[i+]) ++R;
if(L <= R) tmp += (LL)j*(R - L + ) + 1LL*(L + R)*(R - L + )/;
}
ret += tmp*i;
}
for(int i = ; i <= n; ++i)
ret += LL(n + i)*(n - i + )/ + LL(i)*(n - i + );
printf("%I64d\n",ret);
}
return ;
}
 

2015 Multi-University Training Contest 6 hdu 5358 First One的更多相关文章

  1. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

  2. 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!

    Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  3. 2015 Multi-University Training Contest 8 hdu 5385 The path

    The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...

  4. 2015 Multi-University Training Contest 3 hdu 5324 Boring Class

    Boring Class Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  8. 2015 Multi-University Training Contest 6 hdu 5362 Just A String

    Just A String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence

    Easy Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. asp.net mvc-identity初步学习

    Install-Package Microsoft.AspNet.Identity.EntityFramework Install-Package Microsoft.AspNet.Identity. ...

  2. BA-siemens-PXC模块调试

    PXC24模块写地址步骤: 1.制作一根HMI线: 2.通过HMI+232转USB转接卡连接模块: 3.根据已经做好的系统架构表来配置模块: 写模块之前不要忘了格式化模块,主要命令如下: 视频教程:h ...

  3. Spring Boot由jar包转成war包

    Spring Boot由jar包转成war包 spring boot 默认是以jar包形式启动web程序,在新建spring boot项目时候可以选择war包的启动方式. 建议在开发的时候建立以jar ...

  4. poj 3356

    Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...

  5. (十一)Unity5新特性----实战2D游戏

    孙广东  2015.7.11 在本教程中,将了解到U5新功能.你通过本教程.您将了解下面内容: Changes in Component Access Physics Effectors Adding ...

  6. UVA 294 - Divisors 因子个数

    Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an ...

  7. angularjs1-4 事件指令

    <div ng-app="myApp"> <div ng-controller="firstController"> <div n ...

  8. UESTC--1269--ZhangYu Speech(模拟)

    ZhangYu Speech Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit ...

  9. MVC 全局异常处理(适用多人操作)

    自定义特性: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...

  10. FluentAPI关系映射配置

    都有哪几种关系? 1vs多,多vs多 1. 概念or关系映射相关方法: 1) 基本套路:this.Has***(o=>o.AAA).With***() 当前这个表和AAA属性的表关系是Has定义 ...