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 consider log20 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≤n≤105),
the number of integers in the array.

The next line contains n integers a1,a2,…,an (0≤ai≤105).
 
Output
For each test case, output the value.
 
Sample Input
1
2
1 1
 
Sample Output
12
 
Source
 

因为下取整log(sum)的值是非常小的。

能够枚举每一个位置为開始位置,然后枚举每一个log(sum)仅仅需36*n的。

中间j的累加和

推公式就可以。

可是找log值同样的区间,须要用log(sum)*n的复杂度预处理出来,假设每次二分位置会超时。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define maxn 100007
ll 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;
}

hdu 5358 First One 2015多校联合训练赛#6 枚举的更多相关文章

  1. HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)

    pid=5358">HDU 5358 题意: 求∑​i=1​n​​∑​j=i​n​​(⌊log​2​​S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...

  2. hdu 5381 The sum of gcd 2015多校联合训练赛#8莫队算法

    The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  3. hdu 5361 2015多校联合训练赛#6 最短路

    In Touch Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total ...

  4. 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题

    I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 ...

  5. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  6. HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

    pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...

  7. HDU OJ 5317 RGCDQ( 2015多校联合训练第3场) 暴力打表+小技巧

    题目连接:Click here 题意:在一个[L,R]内找到最大的gcd(f[i],f[j])其中L<=i<j<=R,f[x]表示i分解质因数后因子的种类数.eg:f[10]=2(1 ...

  8. HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集

    题目连接:戳ME #include <iostream> #include <cstdio> #include <cstring> using namespace ...

  9. 2015多校联合训练赛 Training Contest 4 1008

    构造题: 比赛的时候只想到:前面一样的数,后面 是类似1,2,3,4,5,6....t这 既是:t+1,t+1...,1,2,3,...t t+1的数目 可能 很多, 题解时YY出一个N 然后对N   ...

随机推荐

  1. PAT Basic 1059

    1059 C语言竞赛 C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 0.冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……). ...

  2. 7,数据类型转换,set 集合,和深浅copy

    str转换成list  用split list转换成str  用join tuple转换成list tu1 = (1,2,3) li = list(tu1)(强转) tu2 = tuple(li)(强 ...

  3. luogu2569 [SCOI2010]股票交易

    题解看这里 #include <iostream> #include <cstring> #include <cstdio> using namespace std ...

  4. selenium 切换窗口的几种方法

    第一种方法: 使用场景: 打开多个窗口,需要定位到新打开的窗口 使用方法: # 获取打开的多个窗口句柄 windows = driver.window_handles # 切换到当前最新打开的窗口 d ...

  5. NYOJ 232 How to eat more Banana

    How to eat more Banana 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 A group of researchers are designing ...

  6. Working out (DP)

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  7. MySQL 待解决死锁

    官方文档:https://dev.mysql.com/doc/refman/5.6/en/innodb-locks-set.html 线上出现一个死锁现象,信息显示的是两条对同一个表的不同记录的upd ...

  8. EasyUI 打印当前页

    function CommonPrint(printDatagrid, type) { var tableString = '<table cellspacing="0" c ...

  9. VM上完美运行macos

    VM上完美运行macos 作者:方辰昱 时间:十月三号 效果图 简要步骤 下载安装VM 下载镜像文件链接,darwin.iso,unlocker,beamoff.合集下载链接:https://pan. ...

  10. BZOJ 4161 Shlw loves matrixI ——特征多项式

    矩阵乘法递推的新姿势. 叉姐论文里有讲到 利用特征多项式进行递推,然后可以做到k^2logn #include <cstdio> #include <cstring> #inc ...