#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. react native props上存在的属性,显示不存在

    问题:类型“Readonly<{}> & Readonly<{ children?: ReactNode; }>”上不存在属性“navigation”.ts(2339) ...

  2. flutter GestureDetector点击区域

    使用GestureDetector包裹Container,发现在Container内容为空的区域点击时,捕捉不到onTap点击事件. 解决方案:在GestureDetector里面添加属性: beha ...

  3. rocketMQ 订阅关系

    场景:2 个消费者进程中,创建了 2 个消费者,同属于 1 个消费组,但是订阅了不同的 topic,会因为订阅信息相互覆盖,导致拉不到消息. 原因是 rocketMQ 的订阅关系,是根据 group ...

  4. Struts+Hibernate+Spring面试题合集及答案

    Struts+Hibernate+Spring面试题合集及答案 Struts+Hibernate+Spring面试题合集 1 1. Hibernate部分 2 1.1. Hibernate工作原理 2 ...

  5. VTK中,定义imread()函数,读取“.vts"文件

    在本程序中,定义了一个imread()函数,用于读取“.vts”文件,第一个参数为文件路径,第二个参数为输出对象,可以输出为tkStructuredGrid型对象,也可以输出为vtkActor型对象. ...

  6. opencv的频域滤波

    下面是频域滤波示例程序: 在本程序中,共有五个自定义函数,分别是: 1. myMagnitude(),在该函数中封装了Opencv中的magnitude函数,实现对于复数图像的幅值计算. 2. dft ...

  7. Linux系统基本操作

      学习目标: 通过本实验掌握Linux的系统安装.磁盘分区.文件管理.IP地址配置.SSH远程管理.WinSCP文件传输.chmod文件权限管理.tar及gzip/bzip2压缩工具的使用,以及关机 ...

  8. Python Basics with Numpy

    Welcome to your first assignment. This exercise gives you a brief introduction to Python. Even if yo ...

  9. IDEA github 上传项目, 拉取, 删除

    1.IDEA登录github账号 settings -> Version Controller -> GitHub 用户名密码登录 或token登录都可以 2.VCS -> impo ...

  10. C++ string 详细用法

    string不是STL的容器(知道这一点的时候我也很吃惊),但是它与STL容器有着很多相似的操作,不需要担心长度问题,还封装了多种多样的方法,十分好用. 用到的库 #include <strin ...