hdu 6059 Kanade's trio(字典树)
Kanade's trio
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 960 Accepted Submission(s): 361
There are T test cases.
1≤T≤20
1≤∑n≤5∗105
0≤A[i]<230
For each test case , the first line consists of one integer n ,and the second line consists of n integers which means the array A[1..n]
题解:http://blog.csdn.net/dormousenone/article/details/76570172
这题:一直wa,把 tree[] 数组中的int改 long long 就错了,诶找了半天错误
#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std; struct node
{
int cnt,ext;
int nxt[];
}tree[*];
int a[+],num[],cnt[][];
long long ans,ext;
int T,n,tsize; void cal(int k,long long c)
{
ans+=(tree[k].cnt-)*tree[k].cnt/;
ext+=tree[k].cnt*(c-tree[k].cnt)-tree[k].ext;
} void solve()
{
int tmp=;
for(int i=;i<=;i++)
{
if (!tree[tmp].nxt[num[i]])
tree[tmp].nxt[num[i]]=++tsize;
if (tree[tmp].nxt[-num[i]])
cal(tree[tmp].nxt[-num[i]],cnt[i][-num[i]]);
tmp=tree[tmp].nxt[num[i]];
tree[tmp].cnt++;
tree[tmp].ext+=cnt[i][num[i]]-tree[tmp].cnt;
}
return;
} int main()
{
scanf("%d",&T);
for(;T>;T--)
{
scanf("%d",&n);
memset(cnt,,sizeof(cnt));
memset(tree,,tsize*+);
tsize=;
ans=ext=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
int tmp=a[i];
for(int j=;j>=;j--)
{
cnt[j][tmp%]++;
num[j]=tmp%;
tmp/=;
}
solve();
}
printf("%lld\n",ans+ext);
}
return ;
}
hdu 6059 Kanade's trio(字典树)的更多相关文章
- HDU 6059 - Kanade's trio | 2017 Multi-University Training Contest 3
思路来自题解(看着题解和标程瞎吉尔比划了半天) /* HDU 6059 - Kanade's trio [ 字典树 ] | 2017 Multi-University Training Conte ...
- hdu6059 Kanade's trio 字典树+容斥
转自:http://blog.csdn.net/dormousenone/article/details/76570172 /** 题目:hdu6059 Kanade's trio 链接:http:/ ...
- hdu 6059 Kanade's trio
题 OwO http://acm.hdu.edu.cn/showproblem.php?pid=6059 解 由于每个数字最多是30位,枚举数字每一位考虑, 建一棵记录前缀(位的前缀,比如10拆成10 ...
- hdu 6059---Kanade's trio(字典树)
题目链接 Problem Description Give you an array A[1..n],you need to calculate how many tuples (i,j,k) sat ...
- HDU 4287 Intelligent IME(字典树数组版)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4757 Tree 可持久化字典树
Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4757 Des ...
- hdu 4099 Revenge of Fibonacci 字典树+大数
将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- HDU 1251 统计难题(字典树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...
随机推荐
- 获取Json字符串中某个key对应的value
JSONObject jsonObj= JSONObject.fromObject(jsonStr); String value= jsonObj.getString(key);
- 资产证券化(ABS)+ 特殊目的信托(SPV)
资产证券化是指以基础资产未来所产生的现金流为偿付支持,通过结构化设计进行信用增级,在此基础上发行资产支持证券(Asset-backed Securities, ABS)的过程,通过将有形或者无形资产作 ...
- Linux学习笔记之Linux修改或增加ssh端口
1.什么是SSH SSH 为 Secure Shell 由 IETF 的网络工作小组(Network Working Group)所制定: SSH 是建立在应用层和传输层基础上的一种安全协议. SSH ...
- 非root权限 安装更新gcc
本文主要参考网络上文章,并根据自己安装出现的问题进行补充. 参考文章: 1.gcc和boost的升级步骤(非root权限):https://blog.csdn.net/u010246947/artic ...
- 20145322第四周JAVA程序设计基础学习总结
20145322 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 一.继承共同行为 何谓继承 1 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那么多个类无需再 ...
- c++ 使用WinHTTP实现文件下载功能
因为要项目中要想要实现一个软件自动更新的功能,之前是使用socket直接下载.但切换下载源的时候很麻烦.所以换用http方式. 网上找了很多资料,基本上就是下面几种: 1.curllib //功能强大 ...
- NOIP2014 T4 子矩阵 dfs+dp
最近在狂补题啊QAQ... 打算先把NOIP的干掉吧... 点我看题 链接还是放洛谷的了... 题意:给一个n*m的矩阵,在这个矩阵里选 r 行 c 列,然后这 r 行 c 列所相交的格子为新矩阵的, ...
- 【bzoj5177】[Jsoi2013]贪心的导游(分块)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=5177 在网上看到的题解基本都是用主席树,也就是带点骚操作的暴力直接艹过去的.这里分享一 ...
- [PyTorch]PyTorch中反卷积的用法
文章来源:https://www.jianshu.com/p/01577e86e506 pytorch中的 2D 卷积层 和 2D 反卷积层 函数分别如下: class torch.nn.Conv2d ...
- spring cloud feign 调用服务注意问题
服务端 rest api @RequestMapping(value = "/phone") public ResponsePhone getPhone(@RequestParam ...