hdu 5358 First One 2015多校联合训练赛#6 枚举
来源:互联网 发布:协同办公自动化软件 编辑:程序博客网 时间:2024/05/11 12:38
First One
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 142 Accepted Submission(s): 37
Problem Description
soda has an integer array a1,a2,…,an . Let S(i,j) be the sum of ai,ai+1,…,aj . Now soda wants to know the value below:∑i=1n∑j=in(⌊log2S(i,j)⌋+1)×(i+j)
Note: In this problem, you can considerlog20 as 0.
Note: In this problem, you can consider
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 integern (1≤n≤105) , the number of integers in the array.
The next line containsn integers a1,a2,…,an (0≤ai≤105) .
The first line contains an integer
The next line contains
Output
For each test case, output the value.
Sample Input
121 1
Sample Output
12
Source
2015 Multi-University Training Contest 6
推公式即可。
但是找log值相同的区间,需要用log(sum)*n的复杂度预处理出来,如果每次二分位置会超时。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;#define ll long long#define maxn 100007ll num[maxn];ll pos[maxn][36];int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i = 0;i < n; i++){ scanf("%I64d",&num[i]); } num[n] = 0; for(ll i = 0;i < 36; i++){ ll di = 1LL<<(i+1); ll su = num[0]; int p = 0; for(int j = 0;j < n; j++){ if(j) su -= num[j-1]; while(su < di && p < n){ su += num[++p]; } pos[j][i] = p; } } ll ans = 0,res; for(int i = 0;i < n; i++){ ll p = i,q; for(int j = 0;j < 36 ;j ++){ q = pos[i][j]; res = (j+1)*((i+1)*(q-p)+(p+q+1)*(q-p)/2); ans += res; p = q; } } printf("%I64d\n",ans); } return 0;}
0 0
- hdu 5358 First One 2015多校联合训练赛#6 枚举
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
- 多校第六场 1006 hdu 5358 First One(枚举)
- HDU 5358 First One(枚举)
- hdu 5303 Delicious Apples 2015多校联合训练赛2 dp+枚举
- hdu 5386 Cover 2015多校联合训练赛#8 枚举
- hdu 5400 Arithmetic Sequence 2015多校联合训练赛#9 枚举
- hdu 5416 CRB and Tree 2015多校联合训练赛#10 枚举
- hdu 5358 First One (2015多校第六场第6题)尺取法枚举区间和
- HDU 5358 First One(枚举)
- HDU 5358 First One(枚举+尺举法)
- hdu 5358 First One [枚举+尺取法]
- 2015多校联合训练赛 hdu 5305 Friends 2015 Multi-University Training Contest 2 枚举+剪枝
- HDU 5371 (2015多校联合训练赛第七场1003)Hotaru's problem(manacher+二分/枚举)
- hdu 5326 work 搜索 2015多校联合训练赛
- hdu 5417 RGCDQ 2015多校联合训练赛
- hdu 5387 Clock 2015多校联合训练赛#8
- hdu 5406 2015 多校联合训练赛#10 dp
- 杭电3787A+B
- HDU 1058Humble Numbers
- noip1996 砝码称重 - 提高组 (多重背包)
- 多校第六场 1011 hdu 5363Key Set(组合数学)
- linux_shell 特殊符号的介绍
- hdu 5358 First One 2015多校联合训练赛#6 枚举
- linux共享库的动态加载
- 我的游戏开发笔记(四):Animator的初步运用(一)
- 使用python爬虫抓取页面之后,将页面保存到Mysql数据库中
- WebKit javascript扩展
- 【web基础3】让网页处理你的数据怎么样?---前端处理
- HDU 5353 Average
- nyoj488&&hdu1016 素数环(DFS)
- Detect the target host network whether can ping through or not(shell script)