题目传送门

 /*
题意:对于长度为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. Lambda 闭包 匿名 函数 类

    深入理解Java 8 Lambda(语言篇——lambda,方法引用,目标类型和默认方法) - _Luc_ - 博客园 https://www.cnblogs.com/figure9/p/java-8 ...

  2. Spark SQL is a Spark module for structured data processing.

    http://spark.apache.org/docs/latest/sql-programming-guide.html

  3. 编写自定义PE结构的程序(如何手写一个PE,高级编译器都是编译好的PE头部,例如MASM,TASM等,NASM,FASM是低级编译器.可以自定义结构)

    正在学PE结构...感谢个位大哥的文章和资料...这里先说声谢谢 一般高级编译器都是编译好的PE头部,例如MASM,TASM等一直都说NASM,FASM是低级编译器.可以自定义结构但是苦于无人发布相关 ...

  4. Mac开发必备工具(二)—— iTerm 2

    iTerm 2 简介 iTerm 2 is a terminal emulator for Mac OS X that does amazing things. iTerm 2 有很多能够提升效率的实 ...

  5. timestamp 转 date 处理后再转timestamp

    package com.jmu.ccjoin.service.impl; import java.sql.Timestamp;import java.util.Calendar;import java ...

  6. delphi 7中使用idhttp抓取网页 解决假死现象(使用TIdAntiFreezeControl控件)

    在delphi 7中使用idhttp抓取网页,造成窗口无反应的假死状态.通过搜索获得两种方法. 1.写在线程中,但是调用比较麻烦 2.使用delphi 提供的idantifreeze(必须安装indy ...

  7. hdu 5615 Jam's math problem(十字相乘判定)

    d. Jam有道数学题想向你请教一下,他刚刚学会因式分解比如说,x^2+6x+5=(x+1)(x+5) 就好像形如 ax^2+bx+c => pqx^2+(qk+mp)x+km=(px+k)(q ...

  8. Balancing Act(树的重心)

    传送门 Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14070   Accepted: 593 ...

  9. AndroidStudio修改主题外观和字体大小

    修改主题外观 File --> Settings --> Appearance & Behavior --> Appearance 右边 Theme 修改编辑器的字体大小 F ...

  10. ol 与ul 的区别

    1 <!DOCTYPE html> <html> <body> <ul> <li>咖啡</li> <li>牛奶< ...