hdu 5358 First One 2015多校联合训练赛#6 枚举
First One
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 142 Accepted Submission(s): 37
Let S(i,j) be
the sum of ai,ai+1,…,aj.
Now soda wants to know the value below:
Note: In this problem, you can consider log20 as
0.
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).
1
2
1 1
12
因为下取整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 枚举的更多相关文章
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
pid=5358">HDU 5358 题意: 求∑i=1n∑j=in(⌊log2S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...
- 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 ...
- hdu 5361 2015多校联合训练赛#6 最短路
In Touch Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...
- 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 ...
- 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 ...
- HDU 5371 (2015多校联合训练赛第七场1003)Hotaru's problem(manacher+二分/枚举)
pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...
- 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 ...
- HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集
题目连接:戳ME #include <iostream> #include <cstdio> #include <cstring> using namespace ...
- 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 ...
随机推荐
- nw.js学习地址
http://blog.sina.com.cn/s/blog_600e56a60102vqj2.html https://github.com/nwjs/nw.js/wiki/Manifest-For ...
- x86保护模式-六 控制转移
控制转移可以分为两大类 :同一任务内的控制转移 和 任务间的控制转移(任务切换) 同一个任务内的控制转移可以分为段内转移 .特权级不变的段间转移和特权级改变的段间转移 段内转移与实模式相同 ...
- 【LeetCode】Count and Say(报数)
这道题是LeetCode里的第38道题. 题目要求: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111 ...
- HDU 3947 River Problem
River Problem Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ...
- HDU 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- TOJ 4008 The Leaf Eaters
|A∪B∪C|=|A|+|B|+|C|-|A∩B|-|A∩C|-|B∩C|+|A∩B∩C| 这个是集合的容斥,交集差集什么的,这个在概率论经常用到吧 4008: The Leaf Eaters T ...
- POJ-3261 Milk Patterns,后缀数组+二分。。
Milk Patterns 题意:求可重叠的至少重复出现k次的最长的字串长. 这题的做法和上一题 ...
- 怎么样给CentOS6.5增加swap分区
再给服务器添加zabbix监控的时候,发现服务器有个报错“Lack of free swap space on localhost”,通过查找得知,在安装服务器的时候忘了划分swap分区.为了减少报错 ...
- [BZOJ1572] [Usaco2009 Open]工作安排Job(贪心 + 堆)
传送门 把任务按照d排序 一次加入到堆中,如果当前放不进堆中,并且比堆中最小的大, 就从堆中弹出一个数,再把当前的数放进去 #include <queue> #include <cs ...
- ubuntu问题解答集锦
一.su root提示认证失败 su root提示认证失败 ubuntu root是默认禁用了,不答应用root登陆,所以先要设置root密码. 执行:sudo passwd root 接着输入密 ...