传送门: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. FPGA等占空比奇偶分频和半整数分频

    1. 偶数分频比较简单,如果分频系数是N(如果N是偶数,那么N/2是整数),那么在输入时钟的每隔N/2个周期时(计数器从0到N/2-1),改变输出时钟的电平即可得到50%固定占空比的时钟.需要的代码如 ...

  2. javac一次性编译多个包下的.java文件

    如题是我想要知道的,然后在网上搜了一下 下面是在某些帖子里看到别人说的只言片语 =========================================================== ...

  3. fiddler抓包-简单易操作(一)

    1.下载fiddler 可以到fiddler官网去下,网址:https://www.telerik.com/download/fiddler 下载完成后,安装即可. 2.运行fiddler,进入fid ...

  4. 对SE的认识

    对SE的认识 简述 “架构师”,也就是SE,总是给外人一种比较牛逼的感觉,其实踏实做开发的真的很少关注这个title. 抛开这个名词,这个角色的存在的确有一定的意义,因为项目中需要一个能“带领大家前进 ...

  5. Word2Vec词向量(一)

    一.词向量基础(一)来源背景  word2vec是google在2013年推出的一个NLP工具,它的特点是将所有的词向量化,这样词与词之间就可以定量的去度量他们之间的关系,挖掘词之间的联系.虽然源码是 ...

  6. Android—实现科大讯飞语音合成

    背景(可以不看) 实验室项目开发的APP需要有语音提示功能,之前的做法是人工录音,剪辑片段,调用Android的多媒体,播放,呵呵呵,,,这是21世纪!这样肯定显得有点low啊,且不说档次,应用场景也 ...

  7. 【Linux】如何设置Linux开机 ,默认进入图形界面或命令行界面?

    原创链接: https://blog.csdn.net/prophet10086/article/details/78501019 [7版本] 在root用户权限下: 查看当前启动模式 systemc ...

  8. redis-20180118

    1.redis hash  100% 2.redis list 100% 3.redis sentinel 20%

  9. css 3 filter

    css 3 filter image & PS effect https://api-platform.com#COMPANIES

  10. [剑指Offer] 25.复杂链表的复制

    /* struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : ...