题目链接:hdu 5773 The All-purpose Zero

官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。

     因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,统计结果的时候再算上0的数量。

为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的。

个人看法:对于显然把所以0放进去部分我解释一下:

  • 如果0位于最长上升子序列两边,这两个零要加进去是显然的
  • 如果有一个0夹于最长上升子序列之间,那么位于LIS中0左边的数应该比0右边的数小1,而因为预处理的效果,右边的数比左边的数至少大2,所以0是可以插进去的,举个例子:1 2 3 0 4 5 6->预处理后:1 2 3 0 3 4 5,最长是1 2 3 0 4(5) 5(6),括号里是原先的数,这个例子里0是替代了原序列0右边的4
  • 有许多个0夹于LIS的,同理可得
/**************************************************************
Problem:hdu 5773 The All-purpose Zero
User: youmi
Language: C++
Result: Accepted
Time:171MS
Memory:3148K
****************************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#define zeros(a) memset(a,0,sizeof(a))
#define ones(a) memset(a,-1,sizeof(a))
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scs(a) scanf("%s",a)
#define sclld(a) scanf("%I64d",&a)
#define pt(a) printf("%d\n",a)
#define ptlld(a) printf("%I64d\n",a)
#define rep(i,from,to) for(int i=from;i<=to;i++)
#define irep(i,to,from) for(int i=to;i>=from;i--)
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define lson (step<<1)
#define rson (lson+1)
#define eps 1e-6
#define oo 0x3fffffff
#define TEST cout<<"*************************"<<endl
const double pi=*atan(1.0); using namespace std;
typedef long long ll;
template <class T> inline void read(T &n)
{
char c; int flag = ;
for (c = getchar(); !(c >= '' && c <= '' || c == '-'); c = getchar()); if (c == '-') flag = -, n = ; else n = c - '';
for (c = getchar(); c >= '' && c <= ''; c = getchar()) n = n * + c - ''; n *= flag;
}
int Pow(int base, ll n, int mo)
{
if (n == ) return ;
if (n == ) return base % mo;
int tmp = Pow(base, n >> , mo);
tmp = (ll)tmp * tmp % mo;
if (n & ) tmp = (ll)tmp * base % mo;
return tmp;
}
//*************************** int n;
const int maxn=+;
int a[maxn];
int val[maxn];
int c[maxn];
int tot;
int lowbit(int x)
{
return x&(-x);
}
void update(int temp,int x)
{
while(x<=tot)
{
c[x]=Max(c[x],temp);
x+=lowbit(x);
}
}
int query(int x)
{
int res=;
while(x)
{
res=Max(c[x],res);
x-=lowbit(x);
}
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int T_T;
scanf("%d",&T_T);
for(int kase=;kase<=T_T;kase++)
{
sc(n);
zeros(c);
int cnt=;
int tt=;
int u;
rep(i,,n)
{
sc(u);
if(u==)
cnt++;
else
{
a[tt]=u-cnt;
val[tt]=a[tt];
tt++;
}
}
sort(val,val+tt);
tot=unique(val,val+tt)-val;
int ans=;
rep(i,,tt-)
{
int temp=lower_bound(val,val+tot,a[i])-val+;
int res=query(temp-)+;
ans=Max(ans,res);
update(res,temp);
}
printf("Case #%d: %d\n",kase,ans+cnt);
}
}

hdu 5773 The All-purpose Zero 最长上升子序列+树状数组的更多相关文章

  1. BZOJ 3173 最长上升子序列(树状数组+二分+线段树)

    给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? 由于序列是顺序插入的,所以当前插入的数字对之 ...

  2. bzoj3173: [Tjoi2013]最长上升子序列(树状数组+二分倒推)

    3173: [Tjoi2013]最长上升子序列 题目:传送门 题解:  好题! 怎么说吧...是应该扇死自己...看错了两次题: 每次加一个数的时候,如果当前位置有数了,是要加到那个数的前面,而不是直 ...

  3. HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...

  4. HDU 5618:Jam's problem again(CDQ分治+树状数组处理三维偏序)

    http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意:…… 思路:和NEUOJ那题一样的.重新写了遍理解了一下,算作处理三维偏序的模板了. #includ ...

  5. HDU 4918 Query on the subtree(动态点分治+树状数组)

    题意 给定一棵 \(n\) 个节点的树,每个节点有点权.完成 \(q\) 个操作--操作分两种:修改点 \(x\) 的点权.查询与 \(x\) 距离小于等于 \(d\) 的权值总和. \(1 \leq ...

  6. HDU 5618 Jam's problem again (cdq分治+BIT 或 树状数组套Treap)

    题意:给n个点,求每一个点的满足 x y z 都小于等于它的其他点的个数. 析:三维的,第一维直接排序就好按下标来,第二维按值来,第三维用数状数组维即可. 代码如下: cdq 分治: #pragma ...

  7. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  8. HDU 5773 The All-purpose Zero(树状数组)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长 ...

  9. hdu 4638 树状数组 区间内连续区间的个数(尽可能长)

    Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

随机推荐

  1. YII页面跳转

    $criteria = new CDbCriteria; $criteria->select = array('ziduan"); $res = Model::model()-> ...

  2. 【Effective Java】4、覆盖equals时请遵守通用约定

    package cn.xf.cp.ch02.item8.transitivity; public class Point { private final int x; private final in ...

  3. 非线性数据拟合-nls

    code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...

  4. ArrayList,Hashtable,List<T>,Dictionary<K,V>

    1.ArrayList ArrayList list = new ArrayList(); //for遍历 ; i < list.Count; i++) { SE se=(SE)list[i]; ...

  5. ahjesus不断完善的js小"内裤"

    String.prototype.isNullOrWhiteSpace = function () { /// <summary> /// 变量是undefined或者null或者空字符串 ...

  6. 【OpenCV & CUDA】OpenCV和Cuda结合编程

    一.利用OpenCV中提供的GPU模块 目前,OpenCV中已提供了许多GPU函数,直接使用OpenCV提供的GPU模块,可以完成大部分图像处理的加速操作. 基本使用方法,请参考:http://www ...

  7. android的Project has no default.properties file! Edit the project properties to set one. 的解决

    网上找来这种方法基本解决: 在我们导入Android工程时,有时候会出现如题所述的错误,打开工程目录可以看到,目录下的default.properties文件没有了或者多出了一个project.pro ...

  8. SDK Build Tools revision (19.0.3) is too low for project Min

    SDK Build Tools revision (19.0.3) is too low for project Min(转)       如果你正在使用Android Studio工具进行开发,且将 ...

  9. 跟踪js文件作为iframe页面不起作用时(淘宝天猫)

    跟踪文件 (function(win, doc) { var s = doc.createElement("script"), h = doc.getElementsByTagNa ...

  10. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q66-Q69)

    Question 66You have a custom theme named MyTheme. The theme is defined in a file named MyTheme.thmx. ...