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的更多相关文章

  1. CodeForces 459D Pashmak and Parmida's problem

    Pashmak and Parmida's problem Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  2. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

  3. 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 ...

  4. 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 ...

  5. 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, ...

  6. 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). 解法:分别从左到右,由右到 ...

  7. 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预处理出  ...

  8. 【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 ...

  9. codeforces459D:Pashmak and Parmida's problem

    Description Parmida is a clever girl and she wants to participate in Olympiads this year. Of course ...

随机推荐

  1. PCAP 抓包

    PCAP是一个数据包抓取库, 很多软件都是用它来作为数据包抓取工具的. WireShark也是用PCAP库来抓取数据包的.PCAP抓取出来的数据包并不是原始的网络字节流,而是对其进行从新组装,形成一种 ...

  2. Performance Tuning of Spring/Hibernate Applications---reference

    http://java.dzone.com/articles/performance-tuning For most typical Spring/Hibernate enterprise appli ...

  3. ASP.NET Web API(一):使用初探,GET和POST数据

    概述 REST(Representational State Transfer表述性状态转移)而产生的REST API的讨论越来越多,微软在ASP.NET中也添加了Web API的功能 项目建立 在安 ...

  4. DataGrid缓冲加载数据

    当datagrid的滚动条拉到4/3的时候去加载数据.. public MainWindow() { InitializeComponent(); ; i <= ; i++) { Class1 ...

  5. Android开发之意图解析

     android中意图(intent)就是告诉系统要做某件事情.比如要拨打电话或者发送短信. 或者在一个Activity中点击按钮跳转到另外一个activity时也用到意图.意图分为两种:显示意图和隐 ...

  6. WPF加载Winform窗体时 报错:子控件不能为顶级窗体

    一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为 ...

  7. Hadoop 2.6.3动态增加/删除DataNode节点

    假设集群操作系统均为:CentOS 6.7 x64 Hadoop版本为:2.6.3 一.动态增加DataNode 1.准备新的DataNode节点机器,配置SSH互信,可以直接复制已有DataNode ...

  8. VIM中文乱码(_vimrc配置文件备份)

    _vimrc在用户目录下: set fileencodings=ucs-bom,utf-,cp936,gb18030,big5,euc-jp,euc-kr,latin1 set encoding=ut ...

  9. Eclipse将项目部署tomcat的webapps目录

      Eclipse将项目部署tomcat的webapps目录 >>>>>>>>>>>>>>>>>& ...

  10. Handler 原理分析和使用(一)

    我为什么写Handler,原因主要还在于它在整个 Android 应用层面非常之关键,他是线程间相互通信的主要手段.最为常用的是其他线程通过Handler向主线程发送消息,更新主线程UI. 下面是一个 ...