hdu-5792 World is Exploding(容斥+树状数组)
题目链接:
World is Exploding
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2⋯An.
1≤n≤50000
0≤Ai≤1e9
/************************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ ┏━┛ ┆
┆ ┃ ┃ ┆
┆ ┃ ┗━━━┓ ┆
┆ ┃ AC代马 ┣┓┆
┆ ┃ ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=5e4+10;
const int maxn=1e3+14;
const double eps=1e-8; int n,fa[N],pres[N],preb[N],nexs[N],nexb[N],sum[N];
struct node
{
int a,id;
}po[N];
int cmp(node x,node y)
{
if(x.a==y.a)return x.id<y.id;
return x.a<y.a;
}
int cmp1(node x,node y)
{
if(x.a==y.a)return x.id<y.id;
return x.a>y.a;
} int lowbit(int x){return x&(-x);} inline void update(int x)
{
while(x<=n)
{
sum[x]++;
x+=lowbit(x);
}
}
int query(int x)
{
int s=0;
while(x)
{
s+=sum[x];
x-=lowbit(x);
}
return s;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
For(i,1,n)read(po[i].a),po[i].id=i;
sort(po+1,po+n+1,cmp);
po[0].a=-1;
mst(sum,0);
For(i,1,n)
{
if(po[i].a==po[i-1].a)fa[i]=fa[i-1];
else fa[i]=i;
pres[po[i].id]=query(po[i].id)-(i-fa[i]);
nexs[po[i].id]=fa[i]-1-pres[po[i].id];
update(po[i].id);
}
mst(sum,0);
sort(po+1,po+n+1,cmp1);
For(i,1,n)
{
if(po[i].a==po[i-1].a)fa[i]=fa[i-1];
else fa[i]=i;
preb[po[i].id]=query(po[i].id)-(i-fa[i]);
nexb[po[i].id]=fa[i]-1-preb[po[i].id];
update(po[i].id);
}
sort(po+1,po+n+1,cmp1);
LL ans1=0,ans2=0,ans;
For(i,1,n)
{
ans1=ans1+pres[i];
ans2=ans2+preb[i];
}
ans=ans1*ans2;
For(i,1,n)
{
ans=ans-nexs[i]*nexb[i];//a==c
ans=ans-preb[i]*nexb[i];//a==d
ans=ans-pres[i]*nexs[i];//b==c
ans=ans-pres[i]*preb[i];//b==d
}
cout<<ans<<endl;
}
return 0;
}
hdu-5792 World is Exploding(容斥+树状数组)的更多相关文章
- bzoj4361:isn(dp+容斥+树状数组)
题面 darkbzoj 题解 \(g[i]\)表示长度为\(i\)的非降序列的个数 那么, \[ ans = \sum_{i=1}^{n}g[i]*(n-i)!-g[i+1]*(n-i-1)!*(i+ ...
- hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点)
hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点) 题意: 给一张无向连通图,有两种操作 1 u v 加一条边(u,v) 2 u v 计算u到v路径上桥的个数 ...
- HDU 5792 L - World is Exploding 。容斥原理 + 树状数组 + 离散化
题目,要求找出有多少对这样的东西,四个数,并且满足num[a]<num[b] &&num[c]>num[d] 要做这题,首先要懂得用树状数组,我设,下面的小于和大于都是严格 ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- HDU 5542 - The Battle of Chibi - [离散化+树状数组优化DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5542 Problem DescriptionCao Cao made up a big army an ...
- HDU 6278 - Just h-index - [莫队算法+树状数组+二分][2018JSCPC江苏省赛C题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6278 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...
- Hdu 5458 Stability (LCA + 并查集 + 树状数组 + 缩点)
题目链接: Hdu 5458 Stability 题目描述: 给出一个还有环和重边的图G,对图G有两种操作: 1 u v, 删除u与v之间的一天边 (保证这个边一定存在) 2 u v, 查询u到v的路 ...
- HDU 5869 Different GCD Subarray Query 离线+树状数组
Different GCD Subarray Query Problem Description This is a simple problem. The teacher gives Bob a ...
- HDU 4267 A Simple Problem with Integers --树状数组
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val 操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...
随机推荐
- 用C语言解决迷宫问题
#include <stdio.h> #include <stdlib.h> #define ROW 10 #define COL 10 /*迷宫中位置信息*/ typedef ...
- oracle 误删数据的回复操作
update operator t set t.username = (select username from operator AS OF TIMESTAMP TO_TIMESTAMP('201 ...
- 修改登陆织梦后台的“DedeCMS 提示信息”
修改方法: 在dedecms程序的include目录中找到文件common.func.php并对其进行编辑,把其中的“DedeCMS 提示信息”修改为自己想要的内容提示: 在dedecms程序的默认管 ...
- PowerBuilder -- 调试(Debug)
@.进入代码调试,执行下一步直接就退出了调试 原文:http://bbs.csdn.net/topics/390126005 处理方法:尝试把 Watch 中查看的变量全部删掉.
- SWT经常使用组件
1button组件(Button) (1)Button组件经常使用样式 SWT.PUSHbutton SWT.CHECK多选button SWT.RADIO单选button SWT.ARROW箭头bu ...
- CPU接口练习 (仅以此程序证明 某个同学真的有毒!有毒!!!)
1创建接口 package lianxi; public interface ICpu { public boolean neiCun();//内存接口 } 2创建一个类 连接这个接口 package ...
- MongoDB在win7上的安装(精简版)
1.下载mongdb的zip文件,解压后会发现有bin文件夹,在同层目录下建一个data目录, 2.在data目录下建一个log和db文件夹, 3.在log文件下建一个MongoDB.log 文件 4 ...
- 创建laravel项目
下载项目到本地 git clone https://github.com/251068550/LaraBlog.git compoer安装 cd LaraBlog composer install 如 ...
- 【总结】性能调优:JVM内存调优相关文章
[总结]性能调优:JVM内存诊断工具 [总结]性能调优:CPU消耗分析 [总结]性能调优:消耗分析 JVM性能调优
- PAT 天梯赛 L2-025. 分而治之 【图】
题目链接 https://www.patest.cn/contests/gplt/L2-025 思路 只要把被攻下的城市标记一下 与 其他城市之间的通路都取消 然后判断一下剩下的城市 是否都是孤立的 ...