传送门

树状数组裸题

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100001 using namespace std; int n, m, ans;
int a[N], b[N], R[N], L[N], c[N]; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline void add(int x)
{
for(; x <= m; x += x & -x) c[x]++;
} inline int query(int x)
{
int ret = 0;
for(; x; x -= x & -x) ret += c[x];
return ret;
} int main()
{
int i;
n = read();
for(i = 1; i <= n; i++) a[i] = b[i] = read();
sort(b + 1, b + n + 1);
m = unique(b + 1, b + n + 1) - b - 1;
for(i = 1; i <= n; i++)
a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
for(i = 1; i <= n; i++)
{
add(a[i]);
L[i] = i - query(a[i]);
}
memset(c, 0, sizeof(c));
for(i = n; i >= 1; i--)
{
add(a[i]);
R[i] = (n - i + 1) - query(a[i]);
}
for(i = 1; i <= n; i++)
if(max(L[i], R[i]) > 2 * min(L[i], R[i]))
ans++;
printf("%d\n", ans);
return 0;
}

  

[luoguP3608] [USACO17JAN]Balanced Photo平衡的照片(树状数组 + 离散化)的更多相关文章

  1. [USACO17JAN]Balanced Photo平衡的照片 (树状数组)

    题目链接 Solution 先离散化,然后开一个大小为 \(100000\) 的树状数组记录前面出现过的数. 然后查询 \((h[i],n]\) 即可. 还要前后各做一遍. Code #include ...

  2. 洛谷P3608 [USACO17JAN]Balanced Photo平衡的照片

    P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a ...

  3. 【luogu P3608 [USACO17JAN]Balanced Photo平衡的照片】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3608 乍一看很容易想到O(N^2)的暴力. 对于每个H[i]从i~i-1找L[i]再从i+1~n找R[i], ...

  4. [USACO17JAN] 晋升者计数 dfs序+树状数组

    [USACO17JAN] 晋升者计数 dfs序+树状数组 题面 洛谷P3605 题意:一棵有点权的树,找出树中所有\((u,v)\)的对数,其中\(u,v\)满足\(val(u)\le val(v)\ ...

  5. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  7. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  8. 线段树合并 || 树状数组 || 离散化 || BZOJ 4756: [Usaco2017 Jan]Promotion Counting || Luogu P3605 [USACO17JAN]Promotion Counting晋升者计数

    题面:P3605 [USACO17JAN]Promotion Counting晋升者计数 题解:这是一道万能题,树状数组 || 主席树 || 线段树合并 || 莫队套分块 || 线段树 都可以写..记 ...

  9. 【BZOJ】1699: [Usaco2007 Jan]Balanced Lineup排队(rmq/树状数组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1699 我是用树状数组做的..rmq的st的话我就不敲了.. #include <cstdio& ...

随机推荐

  1. beta版本发布-团队

    一.β版本于α版本的不同 1.α版本先前只可电脑单机使用,β版本已成功解决联网问题,可以在不同电脑上正常使用 2.β版本相较于α版本修补了较多漏洞.进行了界面的优化且新增了学生个人信息维护功能.教师的 ...

  2. python hdfs初体验

    新建目录 chr 新建文件hdfstest1.txt并写入内容 复制hdfstest1.txt的内容到hdfstest2.txt

  3. java实现中文或其他语言及标点符号等转换成unicode字符串,或unicode的16进制码转换回文字或符号等

    package org.analysisitem20181016.test; public class Code128Test2019052201 { public static final Stri ...

  4. java 正则表达式如何提取中文的问题

    String regex="([\u4e00-\u9fa5]+)"; String str="132更新至456"; Matcher matcher = Pat ...

  5. 以太坊开发框架Truffle学习笔记

    from http://truffleframework.com/docs/getting_started/project 1. 安装node.js 8.11.2 LTS 2. 安装Truffle $ ...

  6. shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。

    [root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个htm ...

  7. (4)zabbix监控第一台服务器

    2. zabbix监控服务器 创建主机,选择模板以及录入基本信息,过一分钟左右,就可以看到cpu.内存.硬盘等等使用情况.本节以图文为主.by the way, zabbix中文翻译很烂,config ...

  8. Linux基础学习-使用iSCSI服务部署网络存储

    使用iSCSI服务部署网络存储 iSCSI技术实现了物理硬盘设备与TCP/IP网络协议的相互结合,使得用户可以通过互联网方便地访问远程机房提供的共享存储资源.下面介绍如何在Linux上部署iSCSI服 ...

  9. JavaWeb项目中集成Swagger API文档

    1.增加依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...

  10. perl的bareword

    perl的bareword可能被认为:label  . 句柄 .函数 . 普通字符串. 上下文不同,解释器有歧义. 最好用 use strict; use warning;