bzoj4759 [Usaco2017 Jan]Balanced Photo
传送门: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的更多相关文章
- bzoj4758: [Usaco2017 Jan]Subsequence Reversal(区间dp)
4758: [Usaco2017 Jan]Subsequence Reversal Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 76 Solved ...
- BZOJ1699: [Usaco2007 Jan]Balanced Lineup排队
1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 933 Solved: 56 ...
- BZOJ1636: [Usaco2007 Jan]Balanced Lineup
1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 476 Solved: 345[ ...
- BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队( RMQ )
RMQ.. ------------------------------------------------------------------------------- #include<cs ...
- BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队
1699: [Usaco2007 Jan]Balanced Lineup排队 Description 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. ...
- BZOJ_4756_[Usaco2017 Jan]Promotion Counting_树状数组
BZOJ_4756_[Usaco2017 Jan]Promotion Counting_树状数组 Description n只奶牛构成了一个树形的公司,每个奶牛有一个能力值pi,1号奶牛为树根. 问对 ...
- bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树
1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 772 Solved: 560线 ...
- [BZOJ4760][Usaco2017 Jan]Hoof, Paper, Scissors dp
4760: [Usaco2017 Jan]Hoof, Paper, Scissors Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 136 Solv ...
- [BZOJ4756][Usaco2017 Jan]Promotion Counting 树状数组
4756: [Usaco2017 Jan]Promotion Counting Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 305 Solved: ...
随机推荐
- 高德API+.NET解决租房问题(新增诚信房源)
作者:李国宝链接:https://zhuanlan.zhihu.com/p/22105008(欢迎点赞)来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 之前有小伙伴反应 ...
- javac、jar使用实录
因项目管理部署需要,记录一下过程,以免下次忘记了,再次使用又需要重头再来,只记录正确的操作方式,可能会提到某些错误 建立项目所在目录F:\www 案例一 其下建立项目的java源文件的包目录结构.ja ...
- 快速平方根算法的javascript实现
前几天看见了一个来自雷神之槌的平方根源码,原理多方有介绍,不赘述. 源码是c语言写的,我思考后发现这样的算法在javascript中也是可以完成的. function InvSqrt(x){ var ...
- 生产者与消费者-N:1-基于list
多个生产者/一个消费者: /** * 生产者 */ public class P { private MyStack stack; public P(MyStack stack) { this.sta ...
- Oracle 11g 审计跟踪管理
在Oracle11g之前,oracle数据库自带的审计功能是关闭的,考虑到性能和审计管理的复杂性,用户一般不打开审计功能.如果有审计要求,DBA会采用trigger来实现对DDL审计的方法来折中.例如 ...
- (原创)不过如此的 DFS 深度优先遍历
DFS 深度优先遍历 DFS算法用于遍历图结构,旨在遍历每一个结点,顾名思义,这种方法把遍历的重点放在深度上,什么意思呢?就是在访问过的结点做标记的前提下,一条路走到天黑,我们都知道当每一个结点都有很 ...
- 如何使用remix
---恢复内容开始--- 教程 | [Ethereum 智能合约开发笔记]使用 Remix Ajian | 3. Feb, 2018 | 621 次阅读 教程 Remix 开发工具 之前有自己开发过E ...
- C++ XML文件解析
使用tinyxml2库,git地址https://github.com/leethomason/tinyxml2 只需要使用tinyxml2.h tinyxml2.cpp即可,同时需要using na ...
- jqprint导入jqgrid表格时,内容溢出的原因以及解决方法
jqprint在导入表格的时候,会将原表格的样式全部拉过来,所以说原表格(如jqgrid的表格)的内容在有滚动条的时候,必须得将宽度设置为100%(等百分比的宽度),不能设置成固定宽度,不然表格内容会 ...
- linux消息队列通信
IPC机制 进程间通信机制(Inter Process Communication,IPC),这些IPC机制的存在使UNIX在进程通信领域手段相当丰富,也使得程序员在开发一个由多个进程协作的任务组成的 ...