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 ...
随机推荐
- 【WPF系列】Textbox
Style定义实例 给Textbox定义一个阴影效果. <Style x:Key="{x:Type TextBox}" TargetType="{x:Type Te ...
- AC日记——校门外的树 洛谷 P1047
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...
- [No00007B]DreamweaverCC 的CSS代码格式化
Dreamweaver自带的代码格式化功能. 1.步骤:命令 -> 应用源格式. 2.你可以选择你的偏好.特别是css代码,有些人喜欢每个属性单独一行,有些人喜欢把所有属性写在同一行.步骤:编辑 ...
- IIS短文件名暴力枚举漏洞利用脚本
import sys import httplib import urlparse import threading import Queue import time class Scanner(): ...
- iOS第八课——Navigation Controller和Tab bar Controller
今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 大数据支持分表优化
公司的短信平台,数据量越来越大了,需要对数据进行一些优化,下面是拆分后的数据库量参考. 新开发的软件模块,必须支持分表,拆表的功能一个数据表里,不适合保存1000万以上的记录新开发的业务模块,能分表的 ...
- bench.sh 跑分测速
#!/bin/bash #==============================================================# # Description: bench te ...
- 分享 Ionic 开发 Hybrid App 中遇到的问题以及后期发布 iOS/Android 的方方面面
此篇文章主要整理了最近在使用 Ionic 开发 Hybrid App 过程中遇到的一些疑难点以及后期发布生成 iOS 和 Android 版本过程中的种种问题. 文章目录 Ionic 简介和项目需求介 ...
- php面向对象编程(三)
<? class Person { // 下面是人的成员属性 var $name; // 人的名子 var $sex; // 人的性别 var $age; // 人的年龄 // 定义一个构造方法 ...
- 软件打包为exe NSIS单文件封包工具V2.3
NSIS单文件封包工具V2.3 这是一款基于NSIS模块的封包制作工具,lzma算法最大压缩率,支持制作单文件,以及NSIS自定义解压封包. 支持注册dll,exe,reg,bat文件 默认提取设置程 ...