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. FreeMarker 整合 springmvc

    一.添加 jar 包 <dependency> <groupId>org.freemarker</groupId> <artifactId>freema ...

  2. ES scroll(ES游标) 解决深分页

    ES scroll(ES游标) 解决深分页. Why 当Elasticsearch响应请求时,它必须确定docs的顺序,排列响应结果.如果请求的页数较少(假设每页20个docs), Elasticse ...

  3. JS中的call()(转)

    1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方 ...

  4. 工具-VS CODE安装

    在Linux下的安装 1.下载tar.gz文件包, 2.要注意加一条命令,这样在任何目录下就可以使用code .直接启动应用程序了 1 sudo ln -s /path/to/vscode/Code ...

  5. 漫说好管理vs.坏管理

    天地会珠海分舵注:本文英文版来自Medium今日热点头条.漫画简单明了,全文差点儿没有多余的语言去装饰.两天内获得两千三百多个推荐,且读者的反馈也相当的热烈.中文版由天地会珠海分舵编译后分享给大家. ...

  6. php PDO连接mysql

    近期在linux装了新的环境.php5.6+mysql5.5+nginx. 然后用原来的mysql链接数据库出现的错误. 原因就是说连接数据库的方法太旧.建议我用mysqli和PDO来连接数据库. 好 ...

  7. 9patch生成图片

    private Bitmap get_ninepatch(int id,int x, int y, Context context){ // id is a resource id for a val ...

  8. CocoaPods的简单介绍及安装和使用

    CocoaPods的简单介绍及安装和使用   一.CocoaPods是什么? 当你开发iOS应用时,会常常使用到非常多第三方开源类库.比方JSONKit.AFNetWorking等等. 可能某个类库又 ...

  9. TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPR

    TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPR ...

  10. win10中让Visual Studio默认使用Administrator权限运行

    https://stackoverflow.com/questions/9654833/how-to-run-visual-studio-as-administrator-by-default Win ...