题目链接: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的个数和。

 1 /***Good Luck***/
 2 #define _CRT_SECURE_NO_WARNINGS
 3 #include <iostream>
 4 #include <cstdio>
 5 #include <cstdlib>
 6 #include <cstring>
 7 #include <string>
 8 #include <algorithm>
 9 #include <stack>
10 #include <map>
11 #include <queue>
12 #include <vector>
13 #include <set>
14 #include <functional>
15 #include <cmath>
16
17 #define Zero(a) memset(a, 0, sizeof(a))
18 #define Neg(a)  memset(a, -1, sizeof(a))
19 #define All(a) a.begin(), a.end()
20 #define PB push_back
21 #define inf 0x3f3f3f3f
22 #define inf2 0x7fffffffffffffff
23 #define ll long long
24 using namespace std;
25 //#pragma comment(linker, "/STACK:102400000,102400000")
26 void get_val(int &a) {
27     int value = 0, s = 1;
28     char c;
29     while ((c = getchar()) == ' ' || c == '\n');
30     if (c == '-') s = -s; else value = c - 48;
31     while ((c = getchar()) >= '0' && c <= '9')
32         value = value * 10 + c - 48;
33     a = s * value;
34 }
35 const int maxn = 1000010;
36 int arri[maxn], arrj[maxn];
37 int arr2[maxn];
38 int arr1[maxn];
39 int A[maxn];
40 int n;
41 int  lowbit(int x) {
42     return x & (-x);
43 }
44
45 int sum(int i) {
46     int ret = 0;
47     while (i > 0) {
48         ret += A[i];
49         i -= lowbit(i);
50     }
51     return ret;
52 }
53
54 void update(int pos, int val) {
55     while (pos <= n) {
56         A[pos] += val;
57         pos += lowbit(pos);
58     }
59 }
60
61 int main() {
62     //freopen("data.out", "w", stdout);
63     //freopen("data.in", "r", stdin);
64     //cin.sync_with_stdio(false);
65
66     scanf("%d", &n);
67     for (int i = 1; i <= n; ++i) {
68         scanf("%d", arr1 + i);
69         arr2[i] = arr1[i];
70     }
71
72     sort(arr2, arr2 + n + 1);           // 离散化
73     int len = unique(arr2, arr2 + n) - arr2;
74     for (int i = 1; i <= n; ++i) {
75         arr1[i] = lower_bound(arr2, arr2 + len, arr1[i]) - arr2;
76     }
77     Zero(arr2);
78     for (int i = 1; i <= n; ++i) {
79         arri[i] = ++arr2[arr1[i]];
80
81     }
82     Zero(arr2);
83     for (int i = n ; i > 0; --i) {
84         arrj[i] = ++arr2[arr1[i]];
85     }
86     ll count = 0;
87     for (int i = n; i >= 1; --i) {
88
89         count += sum(arri[i] - 1) ;
90         update(arrj[i], 1);
91     }
92     cout << count << endl;
93     return 0;
94 }

转载于:https://www.cnblogs.com/yeahpeng/p/3927997.html

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. ICPC 徐州 H Yuuki and a problem (树状数组套主席树)

    Yuuki and a problem 先不管第一问的修改操作,考虑如何达到第二问的查询操作, 题目要我们给出一个区间[l,r][l, r][l,r]中,不能通过权值+++得到的最小的数字是什么, 假 ...

  3. POJ3468--A Simple Problem with Integers--线段树/树状数组 改段求段

    题目描述 You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type ...

  4. 2020ICPC(小米邀请赛2) - Data Structure Problem(线段树+树状数组)

    题目链接:点击查看 题目大意:给出一个长度为 n 的数列 a 和数列 b,然后需要维护一个前缀和 c,c 的定义如下:c[ i ] = max( c[ i - 1 ] + b[ i ] , a[ i ...

  5. HDU 4267 A Simple Problem with Integers [树状数组]

    根据%k=a中a和k的不同组合建立55棵树状数组,每次修改操作只对其中1棵树状数组进行操作,每次查询对其中10棵树状数组统计增量和. 1 #include <string.h> 2 #in ...

  6. A Simple Problem with Integers POJ - 3468(线段树+区间查询+区间修改+建树+懒惰标记模板)+(树状数组)

    题意: 有一个数组,有两种操作.1: Q a b 求[a,b]的和 2:C a b c 给[a,b] 的所有元素都加上c. 题目: You have N integers, A1, A2, ... , ...

  7. POJ3468-A Simple Problem with Integers【线段树,树状数组,分块】

    正题 题目链接:我是链接 其实洛谷线段树模板也是一样的:三种方法AC评测链接 题目大意 要求支持区间修改,区间求和. 线段树 直接用一个lazy标记,在之前的博客里有说 code1 #include& ...

  8. 【POJ - 3468 】 A Simple Problem with Integers (线段树模板 区间更新 + 区间和查询)(不能树状数组或差分数组)

    题干: You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type o ...

  9. poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段)

    1 /* 2 树状数组第三种模板(改段求段)不解释! 不明白的点这里:here! 3 */ 4 #include<iostream> 5 #include<cstring> 6 ...

  10. Problem - 1042D - D. Petya and Array(树状数组)

    D. Petya and Array 题目大意:给定长度为 n n n的序列 a a a,求出有多少组 l , r l,r l,r使得 a l + a l + 1 + a l + 2 + . . . ...

最新文章

  1. 【大作业】城市地铁线路最短路规划及路径输出(满分)
  2. 重磅!我国建成首个自动驾驶封闭高速公路测试环境
  3. sizeof 头文件_c/c++基础之sizeof用法
  4. 羊皮卷的故事-第十章-羊皮卷之三
  5. 区块链BaaS云服务(22)趣链BitXHub跨链平台
  6. plsql tables 没有表_天长视唱练耳辅导班收费表,安徽高考音乐培训学校,你知道吗...
  7. jsapi.php必须传openid,【微信统一支付】发起支付, returnCode != SUCCESS, returnMsg = JSAPI支付必须传openid...
  8. 关于管理的经典故事(员工激励)
  9. 解决JPA的枚举局限性
  10. JS让文本以打字效果呈现出来
  11. leetcode886.PossibleBipartition
  12. html2canvas保存网页到手机,利用html2canvas将当前网页保存为图片.
  13. win10家庭版添加组策略编辑器,禁用系统自动更新
  14. 十、垃圾回收策略概览
  15. 金蝶系统提示服务器不是有效的,金蝶服务器不是有效的,请重新设置问题
  16. 谈谈刚结束的全国大学生电子设计竞赛
  17. 浅谈功能测试-->自动化测试
  18. Python之OpenCV 007 《走近混沌》分形艺术Fractal之美
  19. 复制神器Ditto使用方法详细说明
  20. 汽车电瓶电压12V验证

热门文章

  1. C语言常见基础错误大全总结
  2. 锐度越高越好吗_德国瑞好和德国GC地暖哪个好
  3. python mysql api_python mysql api
  4. Java教程:Java中JVM、JRE和JDK三者有什么区别和联系?
  5. c# export server 调用sql_C#调用SQL Server参数过程传参
  6. windows linux内核版本,微软决定在Windows10中发布一个完整的Linux内核
  7. 接口规范 7. 按需录制相关接口
  8. 2020年日历电子版(打印版)_灵感 | 快来康康——2020年的日历设计的这么有创意?...
  9. Servlet之前端web数据与后台Java数据进行交互
  10. 深度学习目标检测网络FPN tensorflow升3d尝试