• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ACM s1124yy
守りたいものが 強くさせること
博客园    首页    新随笔    联系   管理     

BestCoder Round #84 Bellovin

Bellovin

题意:

给个中文链接:戳戳戳

题解:

这个题其实就是让你求每一位的最长公共子序列,之后输出就好了,求这个有2个算法,一个是n方,另一个nlogn,所以显然是nlogn的算法,其实这就是个模版题。
但当时做的好坑,比如输出是 2 4 5 2 4 应该输出 1 2 3 1 2 但我当时以为要输出 1 2 3 3 3 脑袋短路了啊 = =

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int INF=0x3f3f3f3f;
typedef long long ll;
#define PU puts("");
#define PI(A) printf("%d\n",A)
#define SI(N) scanf("%d",&(N))
#define SII(N,M) scanf("%d%d",&(N),&(M))
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
const double EPS= 1e-9 ;

/*  /////////////////////////     C o d i n g  S p a c e     /////////////////////////  */

const int MAXN=100000 + 9 ;

int dp[MAXN];
int N;
int a[MAXN];
int b[MAXN],cnb;
int main()
{
    int o;
    SI(o);
    while(o--)
    {
        SI(N);
        rep(i,N) SI(a[i]);
        int k=N;
        int ans=-1;
        fill(dp,dp+k,INF);
        for (int i=0; i<k; i++)
        {
            *lower_bound(dp,dp+k,a[i])=a[i];
            b[i]=lower_bound(dp,dp+k,a[i])-dp;
            b[i]++;
        }
        rep(i,N) printf("%d%c",b[i],i==N-1?'\n':' ');
        cle(b,0);
        cnb=0;
    }
    return 0;
}
posted @ 2016-07-24 10:06  s1124yy  阅读(158)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3