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. JAVA格式化时间日期

    JAVA格式化时间日期 import java.util.Date; import java.text.DateFormat; /** * 格式化时间类 * DateFormat.FULL = 0 * ...

  2. python学习笔记--Django入门二 Django 的模板系统

    为了使网站更干净简洁更容易维护,页面的设计和Python的代码必须分离开.我们可以使用Django的 模板系统 (Template System)来实现这种模式. 几个简单的模板标签(tag):   ...

  3. Java动态调用webService,axis2动态调用webService

    Java动态调用webService axis2动态调用webService >>>>>>>>>>>>>>>& ...

  4. 如何创建一个自己的【Composer/Packagist】包

    首先让我们踏着欢快的脚步去Github创建一个新库,这里取名 composer-car,又欢快的将它克隆到本地: $ git clone git@github.com:victorruan/compo ...

  5. java内存模型及分块

    转自:http://www.cnblogs.com/BangQ/p/4045954.html 1.JMM简介 2.堆和栈 3.本机内存 4.防止内存泄漏   1.JMM简介   i.内存模型概述 Ja ...

  6. C#语法糖之第二篇: 参数默认值和命名参数 对象初始化器与集合初始化器

    今天继续写上一篇文章C#4.0语法糖之第二篇,在开始今天的文章之前感谢各位园友的支持,通过昨天写的文章,今天有很多园友们也提出了文章中的一些不足,再次感谢这些关心我的园友,在以后些文章的过程中不断的完 ...

  7. angularjs中异常处理

    1.TypeError: Cannot read property '$valid' of undefined a. Add ng-submit attribute to the form: < ...

  8. Reporting Services 2: 参数化报表

    http://www.cnblogs.com/waxdoll/archive/2006/07/16/452467.html

  9. iOS 开发工具

    Github 社区 https://github.com/ iOS 开发类库 http://www.code4app.com/thread-7831-1-1.html (出处: Code4App-iO ...

  10. java 反射取得方法入参类型的泛形

    package TestReflectClass; import java.util.List; /** * Created by wangyang on 2016/12/16. */ public ...