传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4759

【题解】

排序,从大到小插入,树状数组统计。

# include <vector>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 2e5 + , N = 4e5 + ;
const int mod = 1e9+; # define RG register
# define ST static # define lb(x) (x&(-x))
struct BIT {
int c[N], n;
inline void set(int _n) {
memset(c, , sizeof c);
n = _n;
}
inline void edt(int x, int d) {
for (; x<=n; x+=lb(x)) c[x] += d;
}
inline int sum(int x) {
int ret = ;
for (; x; x-=lb(x)) ret += c[x];
return ret;
}
inline int sum(int x, int y) {
if(x>y) return ;
return sum(y) - sum(x-);
}
}T; int n;
vector<int> ps;
struct pa {
int x, pos;
pa() {}
pa(int x, int pos) : x(x), pos(pos) {}
friend bool operator < (pa a, pa b) {
return a.x > b.x;
}
}p[M]; int L[M], R[M]; int main() {
cin >> n;
T.set(n);
for (int i=; i<=n; ++i) {
scanf("%d", &p[i].x);
p[i].pos = i;
ps.push_back(p[i].x);
} sort(ps.begin(), ps.end());
ps.erase(unique(ps.begin(), ps.end()), ps.end()); for (int i=; i<=n; ++i) p[i].x = lower_bound(ps.begin(), ps.end(), p[i].x) - ps.begin() + ; sort(p+, p+n+); for (int i=; i<=n; ++i) {
int j = i;
while(j<n && p[j+].x == p[i].x) ++j;
for (int k=i; k<=j; ++k) {
L[k] = T.sum(, p[k].pos-);
R[k] = T.sum(p[k].pos+, n);
}
for (int k=i; k<=j; ++k) T.edt(p[k].pos, );
i = j;
} int ans = ;
for (int i=; i<=n; ++i)
if(max(R[i], L[i]) > *min(R[i], L[i]))
++ans; cout << ans << endl; return ;
}

bzoj4759 [Usaco2017 Jan]Balanced Photo的更多相关文章

  1. bzoj4758: [Usaco2017 Jan]Subsequence Reversal(区间dp)

    4758: [Usaco2017 Jan]Subsequence Reversal Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 76  Solved ...

  2. BZOJ1699: [Usaco2007 Jan]Balanced Lineup排队

    1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 933  Solved: 56 ...

  3. BZOJ1636: [Usaco2007 Jan]Balanced Lineup

    1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 476  Solved: 345[ ...

  4. BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队( RMQ )

    RMQ.. ------------------------------------------------------------------------------- #include<cs ...

  5. BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队

    1699: [Usaco2007 Jan]Balanced Lineup排队 Description 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. ...

  6. BZOJ_4756_[Usaco2017 Jan]Promotion Counting_树状数组

    BZOJ_4756_[Usaco2017 Jan]Promotion Counting_树状数组 Description n只奶牛构成了一个树形的公司,每个奶牛有一个能力值pi,1号奶牛为树根. 问对 ...

  7. bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树

    1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 772  Solved: 560线 ...

  8. [BZOJ4760][Usaco2017 Jan]Hoof, Paper, Scissors dp

    4760: [Usaco2017 Jan]Hoof, Paper, Scissors Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 136  Solv ...

  9. [BZOJ4756][Usaco2017 Jan]Promotion Counting 树状数组

    4756: [Usaco2017 Jan]Promotion Counting Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 305  Solved: ...

随机推荐

  1. IAR工程名修改

    修改.dep..ewd..ewp..eww四个文件的文件名 删除.ewt文件(如果存在) 记事本打开.eww文件,修改<path></path>间的.ewp文件名 打开工程,打 ...

  2. PowerPC为什么会没落,我自己的反思学习总结

    PowerPC为什么会没落? Intel通过酷睿,拉大优势,使得苹果抛弃PowerPC   PowerPC当年异常强大,曾经是Xbox的处理器,是Mac的处理器,占据了服务器的半壁江山:当时刚刚接触C ...

  3. 发布npm包 登录报错 E409 Conflict

    1.到官网注册个账号,并且验证完邮箱:https://www.npmjs.com/ 2.打开cmd命令行 登录:$npm login 根据提示 一步步完成登录. 3.新建一个项目文件夹: npmtes ...

  4. zabbix 一些问题随记

    1. zabbix运行不了,显示被锁,去检查日志中的报错 2. 配置界面,连接不到数据库,检查server配置文件,mysql授权命令要准确,重启 3. 显示没有php文件,下载即可,或者修改网页访问 ...

  5. LeetCode 83 —— 删除排序链表中的重复元素

    1. 题目 2. 解答 从前向后遍历链表,如果下一个结点的值和当前结点的值相同,则删除下一个结点,否则继续向后遍历. /** * Definition for singly-linked list. ...

  6. 容器基础(三): 使用Cgroups进行资源限制

    Linux Cgroups Linux Cgroups 是 Linux 内核中用来为进程设置资源限制的一个重要功能. Cgroups将进程进行分组, 然后对这一组进程进行统一的资源监控和限制.Cgro ...

  7. 甲级1002 A+B for Polynomials (25)

    题目描述: This time, you are supposed to find A+B where A and B are two polynomials. Input Each input fi ...

  8. PAT 甲级 1003 Emergency

    https://pintia.cn/problem-sets/994805342720868352/problems/994805523835109376 As an emergency rescue ...

  9. spring笔记(二)

    共性问题: 1. 服务器启动报错,什么原因? * jar包缺少.jar包冲突 1) 先检查项目中是否缺少jar包引用 2) 服务器: 检查jar包有没有发布到服务器下: 用户库jar包,需要手动发布到 ...

  10. elasticsearch-1.7.1 (es Windows 64)

    elasticsearch-1.7.1 (es Windows 64) https://blog.csdn.net/qq_27093465/article/details/53544541 elast ...