hdu 5496 Beauty of Sequence(高效)
2015-10-11 22:32
429 查看
题目链接:hdu 5496 Beauty of Sequence
解题思路
考虑每个位置的贡献度。代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; struct Element { int val, pos; bool operator < (const Element& u) const { if (val != u.val) return val < u.val; return pos < u.pos; } }E[maxn]; int N, P[maxn]; int solve () { int ret = 0, del; sort(E, E + N); for (int i = 0; i < N; i++) { if (i == 0 || E[i].val != E[i-1].val) del = 0; int l = E[i].pos, r = N-E[i].pos-1; ret = (ret + 1LL * (P[l] - del + mod) * P[r] % mod * E[i].val % mod) % mod; del = (del + P[l]) % mod; } return ret; } int main () { P[0] = 1; for (int i = 1; i <= (int)1e5; i++) P[i] = P[i-1] * 2 % mod; int cas; scanf("%d", &cas); while (cas--) { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", &E[i].val); E[i].pos = i; } printf("%d\n", solve()); } return 0; }
相关文章推荐
- UIKit
- 有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?
- UI基础总结第一天
- 【IOS 开发学习总结-OC-43】★ios开发——UIButton(按钮)与 UISwitch(开关按钮)
- UI设计十戒--设计师的艺术
- UI交互设计体验--未来声控之路?
- UIButton 文字显示位置设置 字体的大小设置 字体的颜色设置 注意事项
- 移动界面UI颜色设计
- iOS开发- UICollectionView详解+实例
- 产品UI设计排版的四个基本原则
- Android UI学习系列-ActionBar你最熟悉却又陌生的她(上篇)
- some commands for mount equipment
- java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither user 10047 nor current process
- iOS:图像选取器控制器控件UIImagePickerController的详解
- String StringBuffer StringBuilder之间的区别
- 交互设计菜鸟稳健入门之路
- UI设计师产品构思过程需要有一个系统思维方向
- UI学习方法导航盘
- Android学习手记(5) 基本UI布局
- UI课程21 集合视图UICollectionView