Pashmak and Parmida's problem(树状数组)
题目链接: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(树状数组)的更多相关文章
- 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). 解法:分别从左到右,由右到 ...
- 玲珑学院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 ...
- 2019icpc徐州现场赛 H Yuuki and a problem (树状数组套主席树)
题意 2e5的数组,q个操作 1.将\(a[x]\)改为y 2.求下标l到r内所有的\(a[i]\)通过加法不能构成的最小的值 思路 通过二操作可以知道需要提取l到r内的值及其数量,而提取下标为l到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 ...
- CF #261 div2 D. Pashmak and Parmida's problem (树状数组版)
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants he ...
- 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 ...
- 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预处理出 ...
- A Simple Problem with Integers_树状数组
Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operation ...
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- Linux下yum与apt-get
linux系统基本上分两大类: 1.RedHat系列:Redhat.Centos.Fedora等 2.Debian系列:Debian.Ubuntu等 RedHat 系列 1 常见的安装包格式 rpm包 ...
- 微信小程序——获取openGid
小编使用的Node版本的解密方式(其他方式自行替换写法也是 一样的) 1.到微信小程序官网下载解密demo包 2.获取用户[openid] 3.调用 [wx.showShareMenu] 并且设置 w ...
- MyBatis 示例-传递多个参数
映射器的主要元素: 本章介绍 select 元素中传递多个参数的处理方式. 测试类:com.yjw.demo.MulParametersTest 使用 Map 传递参数(不建议使用) 使用 MyBat ...
- .NET Core 3.0 本地工具
.NET Core从最早期的版本就开始支持全局工具了.如果仅仅需要在某个项目中或某个文件夹中使用特定的工具,那么.NET Core 3.0就允许您这样做. 使用.NET Core 3.0,您可以在特定 ...
- 解决SpringBatch/Cloud Task的SafeMode下的报错问题
问题描述 一般公司都有DBA,DBA极有可能开启了Safe mode,也就是不支持不带索引条件过滤的update操作. 而Spring Batch /Cloud Task就有一张表 JOB_SEQ或者 ...
- CPU爆满后的无助感
告警 晚七点刚好上地铁,握在手里的手机震动了好几下,根据震动这几下的手感已经判断出这是钉钉在告警了,十有八九就是线上的问题,通过Zabbix监控的一台线上服务器已经五分钟不可达,这应该不会是网络网络问 ...
- 元素“context:component-scan”的前缀“context”未绑定
首先报这个错误,你得明白,是什么原因导致的? 答:未引入命名空间,和约束文件 解决方法(加上标红色标记): <?xml version="1.0" encoding=&quo ...
- 最全的access2013教程 access 2010教程 access 2007教程 Access 2003教程
最全的access2013教程 access 2010教程 access 2007教程 Access 2003教程 都在这个access中国网站里 http://www.office-cn.net/o ...
- mysql 5.6.44 zip 安装教程(基于windows )
首先我们从官网下载最新版本的mysql 5.6.44版本,网页地址: ,我的电脑是64位的版本,所以我选择的是64位版本,如果是32位,根据实际情况下载所需要的安装包.
- Function题解
这个题最优策略一定是向左上走到某一列再往上一直走. n*q在线暴力可做,离线按y排序,单调栈维护凸壳. 具体来说:对于i<j若A[i]>A[j] 即j的斜率小而且纵截距小,一定比i优,并且 ...