https://codeforces.com/contest/650/problem/D


原题?

http://210.33.19.103/contest/1024/problem/2

4s 520M


题解很明白了:

当初想错了,想用stormwind的做法去做,发现要维护

给出数组a,f,g
j<i<k,a[j]<a[k]
对于每个i,求f[j]+g[k]最大值

维护了极其长的时间,啥也没维护出来。。。

错误记录:

1.第一次用lower_bound离散化,出了一些奇怪的小错误(关键是小数据根本测不出错..)

2.主席树卡空间,只好强行改成不可持久化的

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int ld,rd;
namespace S
{ #define lc (num<<1)
#define rc (num<<1|1)
const int N=;
int maxn[N];
void clr(){memset(maxn,,sizeof(maxn));}
int qmax(int L,int R,int l,int r,int num)
{
if(L<=l&&r<=R) return maxn[num];
int mid=l+((r-l)>>);int ans=ld;
if(L<=mid) ans=max(ans,qmax(L,R,l,mid,lc));
if(mid<R) ans=max(ans,qmax(L,R,mid+,r,rc));
return ans;
}
void setmaxx(int L,int x,int l,int r,int num)
{
if(l==r)
{
maxn[num]=max(maxn[num],x);
return;
}
int mid=l+((r-l)>>);
if(L<=mid) setmaxx(L,x,l,mid,lc);
else setmaxx(L,x,mid+,r,rc);
maxn[num]=max(maxn[lc],maxn[rc]);
} }
int f[],g[];
int an1[];
int a[];
bool onlis[];
int n,m;
int lis;
int tmp[];
struct QQ
{
int fi,se,n;
}q[];
bool c1(const QQ &a,const QQ &b){return a.fi<b.fi;}
bool c3(const QQ &a,const QQ &b){return a.n<b.n;}
int tt[],t1[],t2[];
int main()
{
int i,j;
scanf("%d%d",&n,&m);
//n=400000;m=400000;
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
//a[i]=rand();
tt[++tt[]]=a[i];
}
for(i=;i<=m;i++)
{
scanf("%d%d",&q[i].fi,&q[i].se);
//q[i].fi=rand()%n+1;q[i].se=rand();
q[i].n=i;
tt[++tt[]]=q[i].se;
}
sort(tt+,tt+tt[]+);tt[]=unique(tt+,tt+tt[]+)-tt-;
for(i=;i<=n;i++) a[i]=lower_bound(tt+,tt+tt[]+,a[i])-tt;
for(i=;i<=m;i++) q[i].se=lower_bound(tt+,tt+tt[]+,q[i].se)-tt;
/*
for(i=1;i<=n;i++)
if(a[i]<=0||a[i]>tt[0])
exit(-1);
*/
ld=;rd=tt[]+;
//printf("6t%d %d\n",ld,rd);
sort(q+,q+m+,c1);
for(i=,j=;i<=n;i++)
{
//printf("1t%d %d %d %d\n",ld,a[i]-1,ld,rd);
f[i]=S::qmax(ld,a[i]-,ld,rd,)+;
while(j<=m&&q[j].fi<=i)
{
t1[q[j].n]=S::qmax(ld,q[j].se-,ld,rd,)+;
++j;
}
S::setmaxx(a[i],f[i],ld,rd,);
}
S::clr();
for(i=n,j=m;i>=;i--)
{
g[i]=S::qmax(a[i]+,rd,ld,rd,)+;
while(j>&&q[j].fi>=i)
{
t2[q[j].n]=S::qmax(q[j].se+,rd,ld,rd,)+;
--j;
}
S::setmaxx(a[i],g[i],ld,rd,);
}
for(i=;i<=n;i++)
lis=max(lis,f[i]);
//for(i=1;i<=n;i++)
// printf("ft%d\n",f[i]);
//for(i=1;i<=n;i++)
// printf("gt%d\n",g[i]);
S::clr();
for(i=n;i>=;i--)
{
onlis[i]=(S::qmax(a[i]+,rd,ld,rd,)+f[i])==lis;
if(onlis[i])
{
++tmp[f[i]];
S::setmaxx(a[i],g[i],ld,rd,);
}
}
for(i=;i<=n;i++)
if(onlis[i]&&tmp[f[i]]==)
an1[i]=lis-;
else
an1[i]=lis;
sort(q+,q+m+,c3);
for(i=;i<=m;i++)
{
//printf("1t%d %d\n",t1[i],t2[i]);
printf("%d\n",max(t1[i]+t2[i]-,an1[q[i].fi]));
}
return ;
}

Zip-line Codeforces - 650D || 风筝的更多相关文章

  1. CodeForces - 650D:Zip-line (LIS & DP)

    Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long a ...

  2. Psychos in a Line CodeForces - 319B (单调栈的应用)

    Psychos in a Line CodeForces - 319B There are n psychos standing in a line. Each psycho is assigned ...

  3. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

  4. Day8 - A - Points on Line CodeForces - 251A

    Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. N ...

  5. Codeforces 650D - Zip-line(树状数组)

    Codeforces 题目传送门 & 洛谷题目传送门 我怕不是个 nt--一开始忽略了"询问独立"这个条件--然后就一直在想有什么办法维护全局 LIS--心态爆炸 首先离散 ...

  6. codeforces 650D. Zip-line 线段树

    题目链接 题目的意思很简单, 就是给你n个数, m个询问, 每次询问修改某一个位置的值, 然后问你修改完之后数列的lis是多少. 询问独立. 对于原数列, 我们将它离散化, 令dp1[i]为以i为结尾 ...

  7. Codeforces Round #345 (Div. 1) D. Zip-line 上升子序列 离线 离散化 线段树

    D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...

  8. codeforces #345 (Div. 1) D. Zip-line (线段树+最长上升子序列)

    Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long a ...

  9. 【Linux】解压分卷压缩的zip文件

    例如linux.zip.001, linux.zip.002, linux.zip.003. 1. cat linux.zip* > linux.zip #合并为一个zip包. 2. unzip ...

随机推荐

  1. [Vim 使用]vim 自动括号补全配置

    打开Vim的配置文件,windows 上面的配置文件在vim 的安装目录下,_vimrc,使用记事本或vim打开 在下方加入如下代码 inoremap ( ()<ESC>i inorema ...

  2. hadoop,帮我解了部分惑的文章

    http://blog.csdn.net/qianshangding0708/article/details/47423613

  3. c#设置系统时间后不起作用

    网上设置系统时间的代码很多,但是会出现设置后没有作用的问题 遇到以上问题可以按照如下办法解决 1.项目--属性--安全性--勾选启用ClickOne安全设置,如下图所示: 2.打开app.manife ...

  4. hdu-5750 Dertouzos(数论)

    题目链接: Dertouzos Time Limit: 7000/3500 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Other ...

  5. hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)

    题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  6. 001-将Python源码转换为不需要环境的可执行文件

    1 安装pyinstaller pip install pyinstaller #或者 pip3 install pyinstaller 2 生成打包文件 在命令行中输入 pyinstaller -F ...

  7. [WC 2006] 水管局长

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2594 [算法] 首先离线 , 将删边操作转化为倒序加边 假设我们已经维护出了一棵最小 ...

  8. 【linux+C】神器 vim + 指针相关客串

    前篇回顾 上篇介绍了linux下C编程基本环境配置以及相关工具使用选择. 不过10个大牛9个用vim,那么咱们就来玩vim.linux下玩c就别依靠图形界面.好吧告别Ide,命令行才是c的王道. 本篇 ...

  9. bzoj 2655 calc —— 拉格朗日插值

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2655 先设 f[i][j] 表示长度为 i 的序列,范围是 1~j 的答案: 则 f[i][ ...

  10. 洛谷P4092树——并查集

    题目:https://www.luogu.org/problemnew/show/P4092 利用并查集,倒序离线,那么从倒序来看被撤销标记的点就再也不会被标记,所以用并查集跳过: 莫名其妙的WA,调 ...