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 ...
随机推荐
- linux bash下 快捷键
c + a # 光标跳转到最左 c + e # 光标跳转到最后 c + w # 删除最后输入的单词 c + u # 删除整行 c + k # 删除光标到末尾 c + l # 清屏 c + z # 挂起 ...
- chmod -R o+rX /data
When using chmod -R o+rx /data , you set the execute permission on all directories as well as files ...
- Oracle中not exists 与not in 的使用情况
1.在oracle11g以上版本,oracle已经做了优化,能够自动将in优化成exists方式,因此oracle11g以上版本,使用in和exists效果是一样的. 2.在oracle中,使用not ...
- ORA-00928: 缺失 SELECT 关键字
ORA-00928: 缺失 SELECT 关键字 一般是表的列名使用了关键字,解决办法就是加双引号 来自为知笔记(Wiz)
- 第一篇:APUE-操作系统IO模型
操作系统IO模型 操作系统IO模型 声明:如下内容是根据APUE和mycat两本著作中关于I/O模式的一些内容加上自己的一些理解整理而成,仅供学习使用. 本节内容 UNIX下可用的五种I/O模型 ...
- 百度知道的php爬虫
原文地址:百度知道的php爬虫作者:好宏杰软件 <?php class spider { private $content ; private $contentlen ; p ...
- gitcafe 使用hexo搭建博客
--缘由:因为看大家都用github等搭建博客,作为半个程序员的自己,也按捺不住了,终于有空来尝试一把了,选择了和github 相同功能的gitcafe网站,因为在国内比较快,这是大家的看法,下面写一 ...
- linux ssh rsa免输入密码
A为本地主机(即用于控制其他主机的机器) ; B为远程主机(即被控制的机器Server), 假如ip为172.24.253.2 ; 在A上的命令: ssh-keygen -t rsa (连续三 ...
- 'EntityValidationErrors' property for more details
很多小猿遇到这个Exception 的时候,都会有点无厘头.这个时候最好try-- catch下,找到出错的地方.本人习惯在页面上加个lable标签,把exc msg(exception messag ...
- windows服务启动 1053错误
1.问题描述 今天在启动一个Windows服务时,服务启动不了,且提示:1053错误 那么是什么导致了1053错误呢? 2.他山之石 百度了一下,发现有人作出下面的解释并给出了解决方法: “常常是因为 ...