题目链接:Codeforces 486E LIS of Sequence

题目大意:给定一个数组。如今要确定每一个位置上的数属于哪一种类型。

解题思路:先求出每一个位置选的情况下的最长LIS,由于開始的想法,所以求LIS直接用线段树写了,没有改,能够用

log(n)的算法直接求也是能够的。然后在从后向前做一次类似LIS。每次推断A[i]是否小于f[dp[i]+1],这样就能够确定该位

置是否属于LIS序列。

然后为第三类的则说明dp[i] = k的仅仅有一个满足。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5; int N, A[maxn + 5], dp[maxn + 5], ct[maxn + 5], f[maxn + 5], v[maxn + 5]; #define lson(x) ((x)<<1)
#define rson(x) (((x)<<1)|1)
int lc[maxn << 2], rc[maxn << 2];
pii s[maxn << 2]; pii merge(pii a, pii b) {
if (a.first == b.first)
return make_pair(a.first, a.second + b.second);
else
return a.first > b.first ? a : b;
} void build (int u, int l, int r) {
lc[u] = l;
rc[u] = r; if (l == r) {
s[u] = make_pair(0, 1);
return;
} int mid = (l + r) >> 1;
build(lson(u), l, mid);
build(rson(u), mid + 1, r);
s[u] = merge(s[lson(u)], s[rson(u)]);
} pii query(int u, int l, int r) {
if (l <= lc[u] && rc[u] <= r)
return s[u]; int mid = (lc[u] + rc[u]) >> 1;
pii ret = make_pair(0, 1);;
if (l <= mid)
ret = merge(ret, query(lson(u), l, r));
if (r > mid)
ret = merge(ret, query(rson(u), l, r));
return ret;
} void modify(int u, int x, pii d) {
if (lc[u] == x && rc[u] == x) {
s[u] = merge(s[u], d);
return ;
} int mid = (lc[u] + rc[u]) >> 1;
if (x <= mid)
modify(lson(u), x, d);
else
modify(rson(u), x, d);
s[u] = merge(s[lson(u)], s[rson(u)]);
} int main () { scanf("%d", &N);
for (int i = 1; i <= N; i++)
scanf("%d", &A[i]); build(1, 0, maxn);
for (int i = 1; i <= N; i++) {
pii u = query(1, 0, A[i]-1);
dp[i] = u.first + 1;
modify(1, A[i], make_pair(dp[i], 1));
}
int ans = query(1, 1, maxn).first; f[ans + 1] = maxn + 1;
for (int i = N; i; i--) {
if (A[i] < f[dp[i]+1]) {
v[i] = 1;
ct[dp[i]]++;
f[dp[i]] = max(f[dp[i]], A[i]);
}
} for (int i = 1; i <= N; i++) {
if (v[i])
printf("%c", '2' + (ct[dp[i]] == 1 ? 1 : 0));
else
printf("1");
}
printf("\n");
return 0;
}

Codeforces 486E LIS of Sequence(线段树+LIS)的更多相关文章

  1. codeforces 374D. Inna and Sequence 线段树

    题目链接 给m个数, n个操作, 一个数列, 初始为空.一共有3种操作, 在数列末尾加0, 加1, 或删除位置为a[i]的数, a[i]为初始给的m个数, 如果a[i]大于数列长度, 那么什么也不发生 ...

  2. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  3. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  4. Hdu 3564 Another LIS 线段树+LIS

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  6. hdu_3564_Another LIS(线段树+LIS)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意:给你N个数的位置.数i的位置为第i个数,比如 0 0 2,表示1插在第0个位置,此时数列为 ...

  7. luogu5010 HMR的LIS III (dp+线段树)

    这个东西和最长上升子序列很像 考虑如果已经知道每个位置为开头的LIS长度和个数 f[i],我可以扫一遍 判断这个个数和K的大小,找到第一个长度=len而且个数<K的,这个位置就是要选的 然后K- ...

  8. Codeforces 438D The Child and Sequence - 线段树

    At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...

  9. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模

    D. The Child and Sequence   At the children's day, the child came to Picks's house, and messed his h ...

随机推荐

  1. java 邮箱验证

    1.需要加入发送邮件的mail.jar: http://www.oracle.com/technetwork/java/javamail/index-138643.html 2.将字符串通过MD5进行 ...

  2. xfce-OpenVAS自动化安全风险评估指南

    1.  登录系统 在客户端,打开浏览器,在地址栏输入https://IP:9392/ 看到如下界面: 我们要信任此网站,点击继续浏览此网站,进入系统登录界面,如下图: 输入我提供的通用登录账号:wdl ...

  3. Consecutive Subsequence (DP+map)

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

  4. 【Android】android:ellipsize的使用以及一个点解决方法

    EidtText和textview中内容过长的话自动换行,使用android:ellipsize与android:singleine可以解决,使只有一行. EditText不支持marquee 用法如 ...

  5. iOS第三方-百度地图地图SDK(一)

    前言 最近项目忙完了准备把百度地图的方法都熟悉一遍,基于百度地图2.10.0,写demo的同时也写下博客来记录下 模拟器设置 我直接就复制我以前写过的一篇的图了,懒得截图... 获取百度地图KEY 让 ...

  6. HDU 5833 Zhu and 772002 ——线性基

    [题目分析] 这题貌似在UVA上做过,高精度高斯消元. 练习赛T2,然后突然脑洞出来一个用Bitset的方法. 发现代码只需要30多行就A掉了 Bitset大法好 [代码] #include < ...

  7. BZOJ 1821 [JSOI2010]Group 部落划分:MST

    Description 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成 ...

  8. 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb

    [AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...

  9. hdu 1390

    #include<stdio.h> int main() { int t,n,a[1001]; scanf("%d",&t); while(t--) { sca ...

  10. STL中heap用法

    #include<cstdio> #include<iostream> #include<algorithm> using namespace std; ]={,, ...