#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int maxm = ;
int h[maxm], num[maxn];
int n, m;
int lowbit(int x)
{
return x & (-x);
}
void update(int x)
{
while (x <= n)
{
h[x] = num[x];
for (int i = ; i < lowbit(x); i <<= )
{
h[x] = max(h[x], h[x - i]);
}
x += lowbit(x);
}
return ;
}
int findans(int begin, int end)
{
int ans = ;
while (end >= begin)
{
ans = max(ans, num[end]);
end--;
for (; end - lowbit(end) >= begin; end -= lowbit(end))
{
ans = max(ans, h[end]);
}
}
return ans;
}
int main()
{
n=;
int ans = -;
int teshu = ;
int now;
memset(h, , sizeof(h));
while (scanf("%d", &now) != EOF)
{
if (now < )
{
continue;
}
if (now >= )
{
now %= ;
if (now == )
{
teshu += ;
}
else
{
int cur = max(findans(, now), teshu) + ;
ans = max(ans, cur);
num[now] = cur;
update(now);
}
}
else
{
if (now == )
{
teshu += ;
}
else
{
int cur = max(findans(, now), teshu) + ;
ans = max(ans, cur);
num[now] = cur;
update(now);
}
}
}
cout<<ans<<endl;
return ;
}

2017 ICPC 南宁 L 带权最大递增子序列的更多相关文章

  1. 2017 icpc 南宁网络赛

    2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...

  2. [程序员代码面试指南]最长递增子序列(二分,DP)

    题目 例:arr=[2,1,5,3,6,4,8,9,7] ,最长递增子序列为1,3,4,8,9 题解 step1:找最长连续子序列长度 dp[]存以arr[i]结尾的情况下,arr[0..i]中的最长 ...

  3. 2017 ACM/ICPC 新疆赛区 I 题 A Possible Tree 带权并查集

    传送门 题意:给定一棵带权树的形态, 但是并不知道每天条边的具体权重. 然后给m个信息, 信息格式为u v val, 表示在树上u 到 v 的路径上经过的边的权重的异或和为val, 问前面最多有多少个 ...

  4. 2017 计蒜之道 初赛 第三场 D. 腾讯狼人杀 (点边都带权的最大密度子图)

    点边都带权的最大密度子图,且会有必须选的点. 求\(\frac{\sum w_e}{k*(2n-k)}\)的最大值,其中k为子图点数 设\[h(g) = \sum w_e - g*(2nk-k^2)\ ...

  5. 2017乌鲁木齐区域赛I(带权并查集)

    #include<bits/stdc++.h>using namespace std;int f[200010];//代表元long long rl[200010];//记rl[i]为结点 ...

  6. DP的各种优化(动态规划,决策单调性,斜率优化,带权二分,单调栈,单调队列)

    前缀和优化 当DP过程中需要反复从一个求和式转移的话,可以先把它预处理一下.运算一般都要满足可减性. 比较naive就不展开了. 题目 [Todo]洛谷P2513 [HAOI2009]逆序对数列 [D ...

  7. poj1417 带权并查集 + 背包 + 记录路径

    True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2713   Accepted: 868 Descrip ...

  8. poj1984 带权并查集(向量处理)

    Navigation Nightmare Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 5939   Accepted: 2 ...

  9. poj1984 带权并查集

    题意:有多个点,在平面上位于坐标点上,给出一些关系,表示某个点在某个点的正东/西/南/北方向多少距离,然后给出一系列询问,表示在第几个关系给出后询问某两点的曼哈顿距离,或者未知则输出-1. 只要在元素 ...

随机推荐

  1. 浏览器端-3WSchool-JavaScript:JavaScript Boolean 对象

    ylbtech-浏览器端-3WSchool-JavaScript:JavaScript Boolean 对象 1.返回顶部 1. Boolean 对象 Boolean 对象表示两个值:"tr ...

  2. ggsci: error while loading shared libraries: libnnz11.so: cannot open shared object file

    完整的错误信息如下: ggsci: error while loading shared libraries: libnnz11.so: cannot open shared object file: ...

  3. 根据md5去重文件

    import os import hashlib def get_md5(file): file = open(file,'rb') md5 = hashlib.md5(file.read()) fi ...

  4. ControlTemplate in WPF ——ScrollBar

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  5. ControlTemplate in WPF —— ItemsControl

    <ItemsControl Margin=" ItemsSource="{Binding Source={StaticResource myTodoList}}"& ...

  6. zabbix服务端安装

    1.安装zabbix服务(1)先rpm安装lamp环境 yum install -y httpd mysql mysql-libs php php-mysql mysql-server php-bcm ...

  7. enumerable 可枚举 属性

    一个对象的可枚举属性会在for...in中被访问到 (或是类似的迭代方法, Object.keys() 如果一个属性不是可枚举的,循环会忽略这个属性 var obj = { key: 'val' }; ...

  8. 阶段3 2.Spring_01.Spring框架简介_05.spring的优势

  9. redhat7.5 替换yum源

    Redhat 7自带的yum源需要付费注册,未注册情况下会报如下错误,且用yum repolist all检查源数目为0.这时候需要将RedHat 7自带的yum源 替换成CentOS 7免费源 解决 ...

  10. div 加滚动条 超过div宽度 自动换行 div居中

    一.div 中加滚动条 一. <div style=" overflow:scroll; width:400px; height:400px;”></div> 记住宽 ...