题目链接:http://codeforces.com/contest/459/problem/D

题意: 数列A, ai表示 i-th 的值, f(i,j, x) 表示【i,j】之间x的数目, 问:当 1 <= i < j <= n, 满足 f(1, i, ai) < f(j,n, aj)的对数。

题解:分别求出两组数列  Ii = f(1, i, ai)(1<=i <= n) Jj =  f(j,n, aj)(1 <= j <= n), 然后, 从n开始, 在数列   Ij(i < j <= n)中求出   小于 Ii的个数和。

 /***Good Luck***/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath> #define Zero(a) memset(a, 0, sizeof(a))
#define Neg(a) memset(a, -1, sizeof(a))
#define All(a) a.begin(), a.end()
#define PB push_back
#define inf 0x3f3f3f3f
#define inf2 0x7fffffffffffffff
#define ll long long
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s; else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
}
const int maxn = ;
int arri[maxn], arrj[maxn];
int arr2[maxn];
int arr1[maxn];
int A[maxn];
int n;
int lowbit(int x) {
return x & (-x);
} int sum(int i) {
int ret = ;
while (i > ) {
ret += A[i];
i -= lowbit(i);
}
return ret;
} void update(int pos, int val) {
while (pos <= n) {
A[pos] += val;
pos += lowbit(pos);
}
} int main() {
//freopen("data.out", "w", stdout);
//freopen("data.in", "r", stdin);
//cin.sync_with_stdio(false); scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d", arr1 + i);
arr2[i] = arr1[i];
} sort(arr2, arr2 + n + ); // 离散化
int len = unique(arr2, arr2 + n) - arr2;
for (int i = ; i <= n; ++i) {
arr1[i] = lower_bound(arr2, arr2 + len, arr1[i]) - arr2;
}
Zero(arr2);
for (int i = ; i <= n; ++i) {
arri[i] = ++arr2[arr1[i]]; }
Zero(arr2);
for (int i = n ; i > ; --i) {
arrj[i] = ++arr2[arr1[i]];
}
ll count = ;
for (int i = n; i >= ; --i) { count += sum(arri[i] - ) ;
update(arrj[i], );
}
cout << count << endl;
return ;
}

Pashmak and Parmida's problem(树状数组)的更多相关文章

  1. 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). 解法:分别从左到右,由右到 ...

  2. 玲珑学院OJ 1023 - Magic boy Bi Luo with his excited math problem 树状数组暴力

    分析:a^b+2(a&b)=a+b  so->a^(-b)+2(a&(-b))=a-b 然后树状数组分类讨论即可 链接:http://www.ifrog.cc/acm/probl ...

  3. 2019icpc徐州现场赛 H Yuuki and a problem (树状数组套主席树)

    题意 2e5的数组,q个操作 1.将\(a[x]\)改为y 2.求下标l到r内所有的\(a[i]\)通过加法不能构成的最小的值 思路 通过二操作可以知道需要提取l到r内的值及其数量,而提取下标为l到r ...

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

  5. CF #261 div2 D. Pashmak and Parmida&#39;s problem (树状数组版)

    Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants he ...

  6. CF459D Pashmak and Parmida's problem (树状数组)

    Codeforces Round #261 (Div. 2)   题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a ...

  7. 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预处理出  ...

  8. A Simple Problem with Integers_树状数组

    Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operation ...

  9. A Simple Problem with Integers(树状数组HDU4267)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

  10. A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. 实用---GUI的搭建,windowbuilder的使用

    在进行GUI的搭建过程中,相信很多人对于一个图标的设置感觉写起来很麻烦,需要不断的添加,而在java中有一个windowbuilder窗口可以很好的帮助我们进行GUI的搭建 1.进入eclipse的页 ...

  2. Git推送到多个远程仓库

    Git推送到多个远程仓库 Grey 原文地址 准备工作 在码云和Github上分别新建两个不包括任何文件的空仓库(若是两个已经有文件的仓库,请参见关联已经存在的项目) https://github.c ...

  3. HDU 1276 士兵队列训练问题(队列)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1276 题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Othe ...

  4. java 连续数字数组分组

    问题: 1. 将Lis list = Arrays.asList(1,2,3,5,8,9,10), 拆分成 [1,2,3] .[5]. [8,9,10] , 2. 再传入一个数字 9, 将匹配数字9的 ...

  5. 百万年薪python之路 -- 模拟三次账号登录锁定功能

    用代码实现三次用户登录及锁定(选做,时间充足建议做一做) 项目分析: 一.首先程序启动,显示下面内容供用户选择: 1.注册 2.登录 a.用户选择登录的时候,首先判断用户名在userinfo.txt表 ...

  6. Swagger Learing - Spring Boot 整合swagger

    学习了一下swagger. 这是编写的Demo 源码 https://github.com/AmberBar/Learning/tree/master/swagger-learning/swagger ...

  7. java Int数据工具类

    1.在使用tcp协议传输数据时,使用到的 Int 数据的工具类方法 //将 Int 数据转换成字节数组 public static byte[] intToByteArray(int data){ b ...

  8. unity 开启外部摄像头

    在unity中建立一个image作为摄像头显示画面,然后通过命令render到image上即可. public WebCamTexture webTex; public string deviceNa ...

  9. fenby C语言 P32

    a[0] a[0][0] a[0][1] a[0][2] a[1] a[1][0] a[1][1] a[1][2]//一维数组 int a[2][3]//二维数组int (*p)[3]=a; #inc ...

  10. Spring框架学习笔记(6)——阿里云服务器部署Spring Boot项目(jar包)

    最近接外包,需要部署服务器,便是参考了网上的几篇博文,成功在阿里云服务器成功部署了Spring Boot项目,特记下本篇笔记 Spring Boot项目打包 这里说一下部署的一些问题 1.mysql驱 ...