题目链接: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. bs4--官方文档

    如何使用 将一段文档传入BeautifulSoup 的构造方法,就能得到一个文档的对象, 可以传入一段字符串或一个文件句柄. from bs4 import BeautifulSoup soup = ...

  2. pep-8要求归纳

    代码布局缩进每个缩进级别使用4个空格. 连续行应使用Python的隐式行连接括号,括号和大括号,或使用悬挂缩进 来垂直对齐包装元素.当使用悬挂式缩进时,应考虑以下内容:第一行应该没有任何争论,应该使用 ...

  3. win10系统中virtualbox无法安装64位系统

    win10系统中virtualbox无法安装64位系统 先总结下如果想在虚拟机中安装64位的Linux系统,最好能满足这几个条件: 64位CPU 64位操作系统 64位的虚拟机软件 开启BIOS虚拟化 ...

  4. Pyhton开发:Python基础杂货铺

    if 语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. Python中if语句的一般形式如下所示: if condition_1: stateme ...

  5. 17,时间模块 time,random模块

    表示时间的三种方式 在python中,通常有着三种方式来表示时间:时间戳,元祖,格式化的时间字符串: 1,时间戳(timestamp):通常来说时间戳表示的是从1970年1月1日00:00:00开始按 ...

  6. python 多线程、多进程、协程性能对比(以爬虫为例)

    基本配置:阿里云服务器低配,单核2G内存 首先是看协程的效果: import requests import lxml.html as HTML import sys import time impo ...

  7. php 修改

    <?php$id = $_GET['id'];$db = new mysqli("localhost","root","root",& ...

  8. BZOJ 3527 [Zjoi2014]力 ——FFT

    [题目分析] FFT,构造数列进行卷积,挺裸的一道题目诶. 还是写起来并不顺手,再练. [代码] #include <cmath> #include <cstdio> #inc ...

  9. 【霍夫曼树】poj 1339 poker card game (数组排序+辅助队列的方法,预处理O(nlogn),构造霍夫曼树O(n))

    poj.org/problem?id=1339 #include<iostream> #include<cstdio> #include<string> #incl ...

  10. 如何解决maven archetype加载太慢的方法

    有时候在构建maven项目时,archetype加载不出来,一直在Retrieving archetype...,现象如下: 有两种解决方法: ①点击链接下载:http://files.cnblogs ...