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的更多相关文章

  1. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  2. New Training Table

          2014_8_15 CodeForces 261 DIV2 A. Pashmak and Garden 简单题   B. Pashmak and Flowers    简单题   C. P ...

  3. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  4. Codeforces Round #261 (Div. 2) B

    链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...

  5. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  6. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  7. Codeforces Round #261 (Div. 2) - E (459E)

    题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...

  8. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  9. 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 ...

随机推荐

  1. mysql5.7.13-windows 免安装版配置简介

    1.下载mysql5.7.13-windows版本 (1)mysql5.7.13-win64版本百度云下载链接分享地址:链接:http://pan.baidu.com/s/1slMl4Ah 密码:w6 ...

  2. C#创建委托实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyDe ...

  3. Vijos1881闪烁的繁星 [线段树]

    P1881闪烁的繁星  背景 繁星闪烁着--深蓝的太空何曾听得见他们对语沉默中微光里他们深深的互相颂赞了 描述 繁星, 漫天的繁星.繁星排成一列, 我数一数呀, 一共有N只小星星呢. 星星们是听话的好 ...

  4. C++的vector对象

    C++的vector使用 标签(空格分隔): C++ 标准库类型vector表示对象的集合,其中所有对象的类型都相同.集合中的每个对象都有一个与之对应的索引,索引用于访问对象,因为vector容纳着其 ...

  5. bzoj 1334: [Baltic2008]Elect

    Description N个政党要组成一个联合内阁,每个党都有自己的席位数. 现在希望你找出一种方案,你选中的党的席位数要大于总数的一半,并且联合内阁的席位数越多越好. 对于一个联合内阁,如果某个政党 ...

  6. iOS下的按钮css去除原生样式

    IOS环境下的按钮都是经过美化的,但通常我们在设计web app的时候不需要这些看上去老土的样式,所以,去除这些显得很有必要. 下面这句代码就是重置这些样式的: input[type=button]{ ...

  7. Js前端代码异常监控

    window.onerror = function(msg,url,line,col,error){ //没有URL不上报!上报也不知道错误 if (msg != "Script error ...

  8. FPGA与simulink联合实时环路系列—开篇

    FPGA与simulink联合实时环路系列—开篇 作为网络上第一个开源此技术,笔者迫不及待地想将此技术分享出来,希望大家多多支持.笔者从2011年接触FPGA以来,从各个方面使用FPGA,无论是控制. ...

  9. Windows操作系统组策略应用全攻略

    作者:佚名出处:IT专家网论坛2007-07-23 13:31 一.什么是组策略 (一)组策略有什么用? 说到组策略,就不得不提注册表.注册表是Windows系统中保存系统.应用软件配置的数据库,随着 ...

  10. JavaScript禁用回退

    javascript:window.history.forward(1); 比如:当前在B页面,点击后退会回退到A页面,那么该代码写在A页面,然后在B页面就不会回退到A了.