codeforces D. Pashmak and Parmida's problem
http://codeforces.com/contest/459/problem/D
题意:给你n个数,然后统计多少组(i,j)使得f(1,i,ai)>f(j,n,aj);
思路:先从左往右统计f(1,i,ai)记录在b[i],然后从右往左统计f(j,n,aj)记录在c[i],然后利用树状数组统计个数即可。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#define maxn 1000010
#define ll long long
using namespace std;
const int inf=<<; int n,m;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll y[maxn];
ll xx[maxn];
ll vis1[maxn],vis2[maxn]; int lowbit(int x)
{
return x&(-x);
} void Insert(int x,ll val)
{
while(x<maxn)
{
y[x]+=val;
x+=lowbit(x);
}
} ll Getsum(int x)
{
ll ans=;
while(x>)
{
ans+=y[x];
x-=lowbit(x);
}
return ans;
} int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%lld",&a[i]);
xx[i]=a[i];
}
sort(xx+,xx++n);
int cnt=;
for(int i=; i<=n; i++)
{
if(xx[i-]!=xx[i])
{
xx[++cnt]=xx[i];
}
}
for(int i=; i<=n; i++)
{
int pos=lower_bound(xx+,xx+cnt+,a[i])-xx;
vis1[pos]++;
b[i]=vis1[pos];
}
for(int i=n; i>=; i--)
{
int pos=lower_bound(xx+,xx+cnt+,a[i])-xx;
vis2[pos]++;
c[i]=vis2[pos];
}
ll ans=;
for(int i=n; i>=; i--)
{
ans+=Getsum(b[i]-);
Insert(c[i],);
}
printf("%I64d\n",ans);
return ;
}
codeforces D. Pashmak and Parmida's problem的更多相关文章
- CodeForces 459D Pashmak and Parmida's problem
Pashmak and Parmida's problem Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
- codeforces 459D D. Pashmak and Parmida's problem(离散化+线段树或树状数组求逆序对)
题目链接: D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megab ...
- cf459D Pashmak and Parmida's problem
D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes i ...
- codeforces 459 D. Pashmak and Parmida's problem(思维+线段树)
题目链接:http://codeforces.com/contest/459/problem/D 题意:给出数组a,定义f(l,r,x)为a[]的下标l到r之间,等于x的元素数.i和j符合f(1,i, ...
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组求逆序数 变形)
题目链接 题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求i和j的种类数. 我们可以用map预处理出 ...
- 【Codeforces 459D】Pashmak and Parmida's problem
[链接] 我是链接,点我呀:) [题意] 定义两个函数 f和g f(i)表示a[1..i]中等于a[i]的数字的个数 g(i)表示a[i..n]中等于a[i]的数字的个数 让你求出来(i,j) 这里i ...
- codeforces459D:Pashmak and Parmida's problem
Description Parmida is a clever girl and she wants to participate in Olympiads this year. Of course ...
随机推荐
- LabVIEW设计模式系列——事件结构中值改变事件
标准:1.将具有值改变事件的控件,放置在其事件结构的值改变页面里.
- Hack工具
黑客工具一般是由黑客或者恶意程序安装到您计算机中,用来盗窃信息.引起系统故障和完全控制电脑的恶意软件程序.同时也指黑客进行黑客任务时使用的工具.著名的有nmap,流光等等. 目录 1 种类 2 恶意程 ...
- java 内部类学习
类和内部类的关系就如同人和心脏的关系. 实例1:内部类的基本结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 //外部 ...
- NLog 安装使用
1:安装 Install-Package NLog.Config 或 通过Nuget 2:Log levels Trace 非常详细的信息,一般在开发时使用. Debug 比Trace稍微少一点一般不 ...
- javascript类继承系列二(原型链)
原型链是采用最主要的继承方式,原理:每一个类(构造器,js中的function)都有一个原型属性(prototype)指向一个原型对象,原型对象有一个构造器(constructor),它又指回到fun ...
- 第八章 CTE 递归 及 分组汇总 高级部分(多维数据集)
UNION 等集合操作符: UNION 等以第一个 SELECT 的 列明 作为 整个结果集的列明,整个结果集 唯一认可的 唯一逻辑处理阶段 是 ORDER BY 这个意思是说 只有 ORDER ...
- js EasyUI前台 价格=数量*单价联动的实现
废话,不多说,,效果图如下:
- Angularjs总结(四)$on、$emit和$broadcast的使用
开发中有时候会需要控制器之间的传值操作:下面几个操作可以达到所需, 注:无平级之间的操作 $emit只能向父 controller传递event与data$broadcast只能向子 controll ...
- ios专题 - sandbox机制
[原创]http://www.cnblogs.com/luoguoqiang1985 ios在安装APP时,把APP的偏好设置与数据放在sandbox里.sandbox通过一系列细颗粒度控制APP访问 ...
- PHP 内存不足
今天编写数据库备份类时,在运行的过程中,出现了内存不足的问题,提示:Fatal error: Allowed memory size of 25165824 bytes exhausted (trie ...