http://acm.hfut.edu.cn/OnlineJudge/

中文题。

区间线段树,需要剪枝。n的大小有问题。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std;
#define ls rt<<1
#define rs rt<<1|1
#define lson l, m, rt<<1
#define rson m + 1, r, rt<<1|1
const int inf = 0x3f3f3f3f;
const int maxn = 2e4 + ; struct SegTree{
int maxv, minv;
int lx, rx, sumx;//该区间左边是否被淹,右边,总的小岛数
}seg[maxn << ];
struct Node{
int h, id;
}q[maxn];
int a[maxn]; void build(int l, int r, int rt){
seg[rt].lx = seg[rt].rx = seg[rt].sumx = ;
if (l == r){
seg[rt].maxv = seg[rt].minv = a[l];
return ;
}
int m = (l + r) >> ;
build(lson);
build(rson);
seg[rt].maxv = max(seg[ls].maxv, seg[rs].maxv);
seg[rt].minv = min(seg[ls].minv, seg[rs].minv);
}
void pushUp(int rt){
seg[rt].sumx = seg[ls].sumx + seg[rs].sumx - (seg[ls].rx & seg[rs].lx);
seg[rt].lx = seg[ls].lx;
seg[rt].rx = seg[rs].rx;
seg[rt].minv = min(seg[ls].minv, seg[rs].minv);//
}
void update(int h, int l, int r, int rt){
if (h < seg[rt].minv) return;
if (h >= seg[rt].maxv){
seg[rt].minv = inf;//这句表明接下来的h对这个区间都不会再有影响,相当于减掉了这个区间否则tle
seg[rt].rx = seg[rt].lx = seg[rt].sumx = ;
return ;
}
int m = (l + r) >> ;
update(h, lson);
update(h, rson);
pushUp(rt);
}
bool cmp(Node a, Node b){
return a.h < b.h;
}
int ans[maxn];
int main(){
int n, m;
scanf("%d", &n);
for (int i = ; i <= n; ++i){
scanf("%d", &a[i]);
}
build(, n, );
scanf("%d", &m);
for (int i = ; i < m; ++i){
scanf("%d", &q[i].h);
q[i].id = i;
}
sort(q, q + m, cmp);
for (int i = ; i < m; ++i){
update(q[i].h, , n, );
ans[q[i].id] = seg[].sumx;
}
for (int i = ; i < m; ++i){
printf("%d\n", ans[i]);
}
return ;
}

hfut 1287的更多相关文章

  1. mysql中,ENCODE警告---Warning Code : 1287

    mysql中,ENCODE警告 共 1 行受到影响, 1 个警告 执行耗时 : 0.072 sec传送时间 : 0.001 sec总耗时 : 0.073 sec Warning Code : 1287 ...

  2. 矩阵乘法 codevs 1287 矩阵乘法

    1287 矩阵乘法  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold       题目描述 Description 小明最近在为线性代数而头疼,线性代数确实很抽象 ...

  3. POJ 1287 Networking (最小生成树)

    Networking Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit S ...

  4. Codevs 1287 矩阵乘法&&Noi.cn 09:矩阵乘法(矩阵乘法练手题)

    1287 矩阵乘法  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 小明最近在为线性代数而头疼, ...

  5. Codevs No.1287 矩阵乘法

    2016-06-01 16:53:23 题目链接: 矩阵乘法 (Codevs No.1287) 题目大意: 给你两个可乘矩阵a,b,求a*b 解法: 定义....... //矩阵乘法 (Codevs ...

  6. POJ 1287 Networking

    题目链接: poj.org/problem?id=1287 题目大意: 你被分派到去设计一个区域的连接点,给出你每个点对之间的路线,你需要算出连接所有点路线的总长度. 题目输入: 一个数字n  代表有 ...

  7. CODEVS 1287 矩阵乘法

    1287 矩阵乘法  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 小明最近在为线性代数而头疼,线性代数确实很抽象(也很无聊) ...

  8. ZOJ1372 POJ 1287 Networking 网络设计 Kruskal算法

    题目链接:problemCode=1372">ZOJ1372 POJ 1287 Networking 网络设计 Networking Time Limit: 2 Seconds     ...

  9. POJ 1287:Networking(最小生成树Kruskal)

    id=1287">Networking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5976   Acce ...

随机推荐

  1. Ubuntu 10.10安装和使用pythonbrew简介

    http://blog.csdn.net/nuccch/article/details/17595161 一.安装Pythonbrew 通过pythonbrew工具实现多版本Python管理,首先安装 ...

  2. bzoj1710【Usaco2007 Open】Cheappal 便宜回文

    1710: [Usaco2007 Open]Cheappal 便宜回文 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 466  Solved: 262 ...

  3. 微信小程序 的文字复制功能如何实现?

    text设置属性  selectable="true" 就可以长按复制了 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing 欢迎关注,有 ...

  4. 网页视频播放方案chimee 组件使用

    1.概述 鉴于目前 H5-Video 在 Web 生态环境中存在较大差异化(兼容性)的表现,本文主要介绍使用奇舞团开发chimee 组件进行视频播放的用法. chimee 组件地址: http://c ...

  5. ibatis 动态查询

    http://www.iteye.com/topic/393042最近做了很多动态的查询,尤其是排序,以及一些状态字段,所以就做了一个总的动态查询,以不变应万变,呵呵 ibatis 里面的sql代码: ...

  6. FD_SET 详解

    http://blog.csdn.net/stephen_yin/article/details/7441165

  7. web常见几种处理图标方法 【转】

    方法一: 用background制作小图标 像这样,拿到设计稿后把所有的图标放在一张图片上,利用background-position.width.height来控制图标的位置及大小. 代码: .ic ...

  8. C# JSON序列化日期格式问题

    默认序列化日期为1970至今的时间戳 需要在json.convert中做一些设置 //JavaScriptSerializer js = new JavaScriptSerializer(); Iso ...

  9. SVN环境搭建(2)

    原文地址:http://www.penglig.com/post-73.html TortoiseSVN的使用. 首先打开VisualSVN Server Manager,如图: 可以在窗口的右边看到 ...

  10. C#中ArrayList类的使用

    ArrayList类 使用大小可按须要动态添加的数组实现IList接口 命名空间:System.Collections 程序集:mscorlib 语法: public class ArrayList: ...