题目传送门

 /*
题意:对于长度为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. sendmessage传递数组

    1.在初始化数组尤其是需要每次都初始化的时候,很多同学使用循环来进行,这样不但速度慢,而且写起来也很长.所以现在提供一个函数来实现这个功能... 原型:extern void *memset(void ...

  2. HashMap随机取值和迭代器取值的对比

    一共四中方法,前两种是迭代器取值,后两种是随机取值,循环了5000万次,时间分别为:迭代器读取的速度大约是随机读取的速度的1.5倍,数据量越大,差距越明显. 另外,插入是读取的100倍左右的时间(这个 ...

  3. 启用了不安全的HTTP方法解决办法 IBM APPSCAN

    启用了不安全的HTTP方法解决办法  IBM APPSCAN     安全风险:       可能会在Web 服务器上上载.修改或删除Web 页面.脚本和文件. 可能原因:       Web 服务器 ...

  4. quilt

    1 什么是quilt quilt是一个patch管理工具,特别适合于对多个patch进行管理. quilt是基于gnu patch和diff的. 2 使用quilt创建一个patch 第一步,quil ...

  5. (转)React Native 使用react-native-image-picker库实现图片上传功能

    react-native-image-picker作为一个集成相机和相册的功能的第三方库,因为其使用相对简单受到前端开发人员的喜爱. react-native-image-picker使用 首先,安装 ...

  6. jquery1.9是最后支持IE678

    bootstrap  需要 jquery 1.9.1或更高 jquery1.9是最后支持IE678

  7. div 下 的img水平居中

    设置text-align:center; 这个div必须要设置宽度: 如:{text-align:center; width:100%;}

  8. Vue : props 使用细节(父组件传递数据给子组件)

    props使用细节 在Vue.js中我们可以使用 props 实现父组件传递数据给子组件,下面我们总结一下props的使用细节 1.基础类型检查 2.必填数据 3.默认值 4.自定义验证函数 其中每一 ...

  9. Android ADB实现解析【转】

    本文转载自:http://blog.csdn.net/u010223349/article/details/41120255   ADB是Android系统提供的调试工具,整个ADB工具由三部分组成: ...

  10. SpringBoot配置文件详解

    自定义属性与加载 com.dongk.selfproperty.title=wangdkcom.dongk.selfproperty.name=10000 然后通过@Value("${属性名 ...