[BZOJ 5055]膜法师
Description
Input
Output
Sample Input1
1 2 3 4
Sample Output1
Sample Input2
10
6 8 4 1 3 0 7 5 9 2
Sample Output2
1737
HINT
样例解释
对于样例 1
有满足条件的序列为
{1,2,3}——6
{1,2,4}——8
{1,3,4}——12
{2,3,4}——24
ans=6+8+12+24=50
数据范围
30%的数据n<=300
60%的数据n<=3000
100%的数据n<=300000
0<=a[i]<=2147483647
题解
我们枚举$j$很显然答案就是
$$\sum _{j=1} ^n (a[j]*{\sum _{i=1} ^{j-1} a[i]}*{\sum _{k=j+1} ^{n} a[k]})$$
树状数组+离散乱搞就可以了。
emmmmmm(恶膜某民命秒没)~
//It is made by Awson on 2017.10.3
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define LL long long
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define count COUNT
using namespace std;
const int N = ;
const LL MOD = ;
void read(LL &x) {
char ch; bool flag = ;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || ); ch = getchar());
for (x = ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
x *= -*flag;
} int n;
struct tt {
LL val;
int pos, rank;
}a[N+];
LL sum[N+], c[N+], ans;
bool comp(const tt &a, const tt &b) {
return a.val < b.val;
}
bool accomp(const tt &a, const tt &b) {
return a.pos < b.pos;
} void add(int x, LL key) {
for (; x <= n; x += lowbit(x)) c[x] = (c[x]+key)%MOD;
}
LL count(int x) {
LL cnt = ;
for (; x; x -= lowbit(x)) cnt = (cnt+c[x])%MOD;
return cnt;
}
void work() {
scanf("%d", &n);
for (int i = ; i <= n; i++) {
read(a[i].val); a[i].pos = i;
}
sort(a+, a+n+, comp);
a[].rank = ;
for (int i = ; i <= n; i++)
a[i].rank = a[i-].rank+(a[i].val != a[i-].val);
sort(a+, a+n+, accomp);
for (int i = ; i <= n; i++) {
sum[i] = count(a[i].rank-);
add(a[i].rank, a[i].val);
}
memset(c, , sizeof(c));
LL cnt = ;
for (int i = n; i >= ; i--) {
LL tmp = count(a[i].rank);
tmp = (cnt+MOD-tmp)%MOD;
ans = (ans+sum[i]*tmp%MOD*a[i].val)%MOD;
add(a[i].rank, a[i].val);
cnt = (cnt+a[i].val)%MOD;
}
printf("%lld\n", ans);
}
int main() {
work();
return ;
}
[BZOJ 5055]膜法师的更多相关文章
- bzoj 5055: 膜法师 -- 树状数组
5055: 膜法师 Time Limit: 10 Sec Memory Limit: 128 MB Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇 ...
- bzoj 5055: 膜法师——树状数组
Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然,他能为长者所续的时间,为这三个维度上能量的乘 ...
- bzoj 5055: 膜法师 树状数组+离散
先枚举每一个数,看它前面有几个比它小,算一下和为sum1,后面有几个比它大,算一下和为sum2,对答案的贡献为A[i]*sum1*sum2. 离散化后,树状数组就可以了. 就是倒着一边,顺着一边,统计 ...
- bzoj5055 膜法师
Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然,他能为长者所续的时间,为这三个维度上能量的乘 ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- JZOJ.5280【NOIP2017模拟8.15】膜法师
Description
- 【BZOJ5055】膜法师 树状数组
[BZOJ5055]膜法师 Description 题目描述 在给定的维度序列a中, 求出所有满足i<j<k且ai<aj<ak的ai*aj*ak的和 即 ∑ (a_i*a_j* ...
- [JZOJ5280]膜法师题解--思维+前缀和
[JZOJ5280]膜法师题解--思维+前缀和 题目链接 暴 力 过 于
- 【bzoj5055】膜法师(离散化+树状数组)
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=5055 这道题……不得不说,从标题到题面都能看出一股浓浓的膜法气息……苟…… 题意就是统计顺序 ...
随机推荐
- 关于hadoop集群下Datanode和Namenode无法访问的解决方案
HDFS架构 HDFS也是按照Master和Slave的结构,分namenode,secondarynamenode,datanode这几个角色. Namenode:是maseter节点,是大领导.管 ...
- alpha-咸鱼冲刺day7(后续一波)-紫仪
总汇链接 一,合照 emmmmm.自然还是没有的. 二,项目燃尽图 三,项目进展 正在写登陆+注册ing 注册搞出来了!!!!!!!!QAQ(喜极而泣!!!!.jpg) 四,问题困难 数据流程大概是搞 ...
- jQuery 写的textarea输入字数限制
//先判断浏览器是不是万恶的IE var bind_name = 'input';//默认事件 if (navigator.userAgent.indexOf(" ...
- sublime安装 和 插件安装
先从官网下载sublime https://www.sublimetext.com/3 安装完毕后 快捷键ctrl+` 或者View->Show Console,输入如下代码(sublime ...
- 【转】optach学习
[转自:https://yq.aliyun.com/articles/28007,仅作学习用途] 摘要: Opatch 是oracle公司开发的安装,卸载,检测patch冲突的工具,管理oracle所 ...
- 24.C++- 抽象类(存虚函数)、接口、多重继承
抽象类和接口 什么是抽象类 用来表示现实世界中的抽象概念 是一种只能定义类型,而不能产生对象的类 只能被子类继承,且抽象类的相关成员函数没有完整的体现,用来被子类重写. 比如图形(Shape)类, 就 ...
- 隐藏Easy UI 中parent.$.modalDialog 的button
例子: buttons : [ { text : '关闭', handler : function() { parent.$.modalDialog.handler.dialog('close'); ...
- GIT入门笔记(15)- 链接到私有GitLab仓库
GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源代码,管理 ...
- OrientDB入门(1)Getting Started
Running OrientDB the First Time First, download and extract OrientDB by selecting the appropriate pa ...
- 新概念英语(1-61)A bad cold
新概念英语(1-61)A bad cold What is good news for Jimmy? A:Where's Jimmy? B:He's in bed. A:What's the matt ...