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 ...
随机推荐
- Day02 - Python 基本数据类型
1 基本数据类型 Python有五个标准的数据类型: Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 1.1 数字 数字数据类型用于 ...
- js--小结③
- SQL 建立临时表进行查询
SELECT min (maxrank) as minofmaxrank FROM (SELECT max(rank) as maxrank FROM tbl_core_staff WHERE st_ ...
- OpenXML: Asp.net利用OpenXML 导出Excel.
http://www.cnblogs.com/skyfei/archive/0001/01/01/Openxml.html
- 关于 ORA - 01861 文字与格式字符串不匹配问题(oracle存储过程)
一般问题(TO_DATE 和 TO_CHAR 两种格式互换)比如: 只要转化下格式就OK ,这里就不详细解释这两种格式的用法了! 今天把之前做好的模块拿到当地实习,不管怎么测 ,连续测试了好几个存储过 ...
- [Json] C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json (转载)
点击下载 ConvertJson.rar 本类实现了 C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json|等功能大家先预 ...
- AndroidStudio字体主题样式分享
最近慢慢在从eclipse往AndroidStudio习惯,但总觉得AS的默认字体颜色看的不舒服,便花了些时间将字体颜色样式改成了和原来类似的.以下是效果图. 这里是下载地址http://downlo ...
- 2.Oracle11g体系结构
2.1逻辑存储结构 2.1.1数据块(Data Blocks) 数据块是Oracle逻辑结构中最小的逻辑单位,也是执行数据库输入输出最小的存储单位.通常Oracle数据库是操作系统块的整数倍,如果操作 ...
- 数据库学习(整理)----6--Oracle如何快速备份和多次备份数表数据
1.说明: 这里假设一种应用场景! 假设,银行系统中有大量的数据需要及时备份,如何才能快速高效呢! 条件需求: (1).不能设置同步锁(设置的会影响银行正常业务进行!使得银行系统处于维护状态,这是不 ...
- ZOJ 3725 Painting Storages(DP+排列组合)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output ...