Codeforces #261 D
Codeforces #261 D
D. Pashmak and Parmida's problem
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r andak = x. His task is to calculate the number of pairs of indicies i, j (1 ≤ i < j ≤ n) such that f(1, i, ai) > f(j, n, aj).
Help Pashmak with the test.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 106). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print a single integer — the answer to the problem.
简单的树状数组求逆序数。。。开始怎么也没想到。。。
答案没用long long wa一次
#include <cstring> #include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <map> #include <cstdlib> #define M(a,b) memset(a,b,sizeof(a)) using namespace std; int n; int num[]; int savefro[],saveb[]; int ans[]; int flag[]; map<int,int> front,back; int bit[],cnn; int sum(int i) { int res = ; while(i>) { res+=bit[i]; i-=i&-i; } return res; } void add(int i,int x) { while(i<=cnn) { bit[i]+=x; i+=i&-i; } } int main() { while(scanf("%d",&n)==) { front.clear(); back.clear(); M(saveb,); M(savefro,); M(ans,); M(flag,); M(bit,); long long res = ; for(int i = ;i<n;i++) { scanf("%d",&num[i]); } for(int i = ;i<n;i++) { savefro[i] = ++front[num[i]]; } cnn = n; for(int i = n-;i>=;i--) { saveb[i] = ++back[num[i]]; add(saveb[i],); res+=sum(savefro[i-]-); // cout<<' '<<sum(savefro[i-1]-1)<<' '<<savefro[i-1]<<endl; } /*cout<<"savefro"<<endl; for(int i = 0;i<n;i++) { cout<<savefro[i]<<' '; } cout<<endl; cout<<"saveb"<<endl; for(int i = 0;i<n;i++) { cout<<saveb[i]<<' '; } cout<<endl; cout<<"flag"<<endl; for(int i = 0;i<n;i++) { cout<<flag[i]<<' '; } cout<<endl;*/ printf("%I64d\n",res); } return ; }
Codeforces #261 D的更多相关文章
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- New Training Table
2014_8_15 CodeForces 261 DIV2 A. Pashmak and Garden 简单题 B. Pashmak and Flowers 简单题 C. P ...
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- Codeforces Round #261 (Div. 2) - E (459E)
题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
随机推荐
- Fast RCNN 训练自己的数据集(3训练和检测)
转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ https://github.com/YihangLou/fas ...
- Dialog详解(包括进度条、PopupWindow、自定义view、自定义样式的对话框)
Dialog详解(包括进度条.PopupWindow.自定义view.自定义样式的对话框) Android中提供了多种对话框,在实际应用中我们可能会需要修改这些已有的对话框.本实例就是从实际出发, ...
- zookeeper安装
http://blog.itpub.net/27099995/viewspace-1394831/ http://blog.csdn.net/huwei2003/article/details/491 ...
- http、tcp、udp、OAUTH2.0网络协议区别
一.先来一个讲TCP.UDP和HTTP关系的 1.TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层. 在网络层有IP协议.ICMP协议.ARP协议.RAR ...
- ThinkPHP常用配置路径
//系统常量定义 //去THinkPHP手册中进行查找 echo "<br>"."网站的根目录地址".__ROOT__." "; ...
- JQUERY获取当前页面的URL信息
以前在做网站的时候,经常会遇到当前页的分类高亮显示,以便让用户了解当前处于哪个页面.之前一直是在每个不 同页面写方法.工程量大,也不便于修改.一直在想有什么简便的方法实现.后来在网上查到可以用获取当前 ...
- 电改:OPower资料调研
0.简介 power公司是于 2007 年创办,是全球领先的家庭能源管理企业.家庭能源数据分析公司.Opower 与公用电力公司合作,抢占家庭消费者"入口",获取家庭消费者 ...
- DbUtility v3
DbUtility v3 历史 七年前,也就是2007年,我在博客园写了一篇博文,开源并发布了恐怕是我第一个开源项目,DbUtility.其设计的初衷就是为了简化ADO.NET繁琐的数据库访问过程,提 ...
- 85 megacli-查看raid信息
文章本身我不做过多修改了,在这里我就把自己在安装时候碰到的难点跟大家提下.1.何处下载?首先,根据文章中的路径已经下载不到相应的文件了,在此我们就自己到http://www.lsi.com的网站上去搜 ...
- @Autowired的使用
1.benas的xml文件中需要加入如下代码 <bean class="org.springframework.beans.factory.annotation.AutowiredAn ...