题目传送门

 /*
题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值
set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中
查找左右相邻的位置,更新长度为r - l - 1的最大值,感觉线段树结构体封装不错!
详细解释:http://blog.csdn.net/u010660276/article/details/46045777
其实还有其他解法,先掌握这种:)
*/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <cstring>
#include <set>
using namespace std; typedef long long ll;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1 const int MAXN = 2e5 + ;
const int INF = 0x3f3f3f3f; struct A
{
int v, id;
bool operator < (const A &a) const
{
return v < a.v;
}
}a[MAXN];
struct SegmentTree
{
int add[MAXN << ];
int mx[MAXN << ]; void push_down(int rt)
{
if (add[rt])
{
add[rt<<] = add[rt<<|] = add[rt];
mx[rt<<] = mx[rt<<|] = add[rt];
add[rt] = ;
}
} void build(int l, int r, int rt)
{
add[rt] = mx[rt] = ;
if (l == r) return ;
int mid = (l + r) >> ;
build (lson); build (rson);
} void updata(int ql, int qr, int c, int l, int r, int rt)
{
if (ql <= l && r <= qr) {mx[rt] = c; add[rt] = c; return ;}
push_down (rt);
int mid = (l + r) >> ;
if (ql <= mid) updata (ql, qr, c, lson);
if (qr > mid) updata (ql, qr, c, rson);
} int query(int x, int l, int r, int rt)
{
if (l == r) return mx[rt];
push_down (rt);
int mid = (l + r) >> ;
if (x <= mid) return query (x, lson);
return query (x, rson);
}
}tree; int ans[MAXN]; int main(void) //Codeforces Round #305 (Div. 2) D. Mike and Feet
{
int n;
while (scanf ("%d", &n) == )
{
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i].v); a[i].id = i;
}
sort (a+, a++n); tree.build (, n, );
set<int> S; S.insert (); S.insert (n + );
set<int>::iterator it;
for (int i=; i<=n; ++i)
{
int l, r;
it = S.lower_bound (a[i].id);
r = *it; it--; l = *it;
if (r - l - >= ) tree.updata (, r-l-, a[i].v, , n, );
S.insert (a[i].id);
} for (int i=; i<=n; ++i)
ans[i] = tree.query (i, , n, );
for (int i=; i<=n; ++i)
printf ("%d%c", ans[i], (i==n) ? '\n' : ' ');
} return ;
} /*
10
1 2 3 4 5 4 3 2 1 6
*/

 

 /*
jinye的解法:原理一样,找到最小值是a[i]的最长区间,用l[],r[]记录左右端点的位置
比线段树快多了:)
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 2e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN], l[MAXN], r[MAXN], ans[MAXN]; int main(void) //Codeforces Round #305 (Div. 2) D. Mike and Feet
{
int n;
while (scanf ("%d", &n) == )
{
memset (ans, , sizeof (ans));
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]);
l[i] = r[i] = i;
} for (int i=; i<=n; ++i)
{
while (l[i] > && a[i] <= a[l[i]-]) l[i] = l[l[i]-];
}
for (int i=n; i>=; --i) //倒过来回超时
{
while (r[i] < n && a[i] <= a[r[i]+]) r[i] = r[r[i]+];
} for (int i=; i<=n; ++i)
{
int x = r[i] - l[i] + ;
ans[x] = max (ans[x], a[i]);
} for (int i=n-; i>=; --i) //可能范围扩展的太厉害了
{
ans[i] = max (ans[i], ans[i+]);
} for (int i=; i<=n; ++i)
printf ("%d%c", ans[i], (i==n) ? '\n' : ' ');
} return ;
}

数组效率更高

set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet的更多相关文章

  1. Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈

    B. Mike and Feet Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...

  2. Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)

    题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...

  3. Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Codeforces Round #305 (Div. 2) D. Mike and Feet

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. Codeforces Round #305 (Div. 1) B. Mike and Feet

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  6. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  7. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  8. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  9. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

随机推荐

  1. java反射机制与动态加载类

    什么是java反射机制? 1.当程序运行时,允许改变程序结构或变量类型,这种语言称为动态语言.我们认为java并不是动态语言,但是它却有一个非常突出的动态相关机制,俗称:反射. IT行业里这么说,没有 ...

  2. vue实现单选多选反选全选全不选

    单选 当我们用v-for渲染一组数据的时候,我们可以带上index以便区分他们我们这里利用这个index来简单地实现单选 <li v-for="(item,index) in radi ...

  3. 使用sql compare生成的sql语句

    创建表以及主键 判断表是否存在 OBJECT_ID 判断主键是否存在 SELECT 1 FROM sys.indexes WHERE name = N'PK_LISA_NoUseWebpartRepl ...

  4. YTU 2455: Pefect 数字

    2455: Pefect 数字 时间限制: 1 Sec  内存限制: 128 MB 提交: 749  解决: 146 题目描述 小明和小林做数字游戏,他们的游戏规则如下: 小明说出一个数字n,小林说出 ...

  5. COGS-2049 疯狂动物城

    Description 你意外来到了一个未知的星球, 这里是一个动物乌托邦, 生活着一群拥有非凡智力的动物. 你遇到了一个叫做尼克的狐狸, 他准备给他的 GF 过生日 . 他将制作一个巨大的多层蛋糕, ...

  6. 利用PyCharm的Profile工具进行Python性能分析

    Profile:PyCharm提供了性能分析工具Run->Profile,如下图所示.利用Profile工具可以对代码进行性能分析,找出瓶颈所在. 测试:下面以一段测试代码来说明如何使用pych ...

  7. OCCI编程接口介绍

    OCCI简介 Oracle® C++ Call Interface (OCCI) 是一套应用程序编程接口,它允许C++程序与一个或者多个Oracle数据库进行交互.OCCI给予你强大的数据库操作能力, ...

  8. 【转】Darwin Streaming Server 核心代码分析

    无意中看到了dqzhangp的一篇博客,分析了DSS的核心架构,读完顿时感觉豁然开朗,茅塞顿开,写得非常的鞭辟入里,言简意赅,我想没有相当的功力是写不出这样的文章的,情不自禁转到自己空间来,生怕弄丢了 ...

  9. 酷版移动端iframe改变src,重新加载页面问题探究

    最近在酷版上我要做一个内嵌别人的网页的在线服务页面,于是必须用到iframe,以前我以为移动端不支持iframe呢,原来这样都可以....(呵呵,长见识了!我还是只菜鸟) 直接入正题,说说我遇到的困难 ...

  10. Table View Programming Guide for iOS---(二)----Table View Styles and Accessory Views

    Table View Styles and Accessory Views 表格视图的风格以及辅助视图 Table views come in distinctive styles that are ...