The Street

思路:

  动态开节点线段树;

  等差序列求和于取大,是两个独立的子问题;

  所以,建两颗线段树分开维护;

  求和:等差数列的首项和公差直接相加即可;

  取大:

    对于线段树每个节点储存一条斜率为等差数列公差的线段;

    当添加线段到已有线段的节点,下传一条线段,当前节点留下一条线段;

    当要添加的线段完全覆盖或者被覆盖当前节点储存的线段时,选择更新或者不更新;

  单点查询时,从根节点到叶节点的路径上去最大值;

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define ll long long
#define INF (1LL<<62) struct TreeNodeType {
ll a,b; bool if_; struct TreeNodeType *lc,*rc; TreeNodeType()
{
lc=NULL,rc=NULL,if_=false,a=,b=;
}
}; ll n,m; inline void in(ll &now)
{
ll if_z=;now=;
char Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} class SumTreeType {
public:
struct TreeNodeType *root; SumTreeType(){} inline void tree_down(TreeNodeType *&now,ll l,ll r)
{
if(now->lc==NULL) now->lc=new TreeNodeType;
if(now->rc==NULL) now->rc=new TreeNodeType;
now->lc->a+=now->a,now->lc->b+=now->b;
now->rc->a+=now->a+((l+r>>)-l+)*now->b,now->rc->b+=now->b;
now->a=,now->b=;
} void tree_add(TreeNodeType *&now,ll l,ll r,ll li,ll ri,ll a,ll b)
{
if(now==NULL) now=new TreeNodeType;
if(l==li&&r==ri)
{
now->a+=a,now->b+=b;
return ;
}
ll mid=l+r>>;
if(now->a!=&&now->b!=) tree_down(now,l,r);
if(li>mid) tree_add(now->rc,mid+,r,li,ri,a,b);
else if(ri<=mid) tree_add(now->lc,l,mid,li,ri,a,b);
else
{
tree_add(now->lc,l,mid,li,mid,a,b);
tree_add(now->rc,mid+,r,mid+,ri,a+(mid-li+)*b,b);
}
} ll tree_query(TreeNodeType *&now,ll l,ll r,ll to)
{
if(now==NULL) return ;
if(l==r) return now->a;
if(now->a!=||now->b!=) tree_down(now,l,r);
ll mid=l+r>>;
if(to<=mid) return tree_query(now->lc,l,mid,to);
else return tree_query(now->rc,mid+,r,to);
}
};
class SumTreeType ai; class MaxTreeType {
public:
ll X; bool op; struct TreeNodeType *root; MaxTreeType(){} inline double com(ll a1,ll b1,ll a2,ll b2)
{
if(a1==a2) return ;
return (double)(a1-a2)/(double)(b2-b1);
} void tree_down(TreeNodeType *&now,ll l,ll r,ll a,ll b)
{
if(now==NULL)
{
now=new TreeNodeType;
now->if_=true;
now->a=a,now->b=b;
return ;
}
if(!now->if_)
{
now->a=a,now->b=b,now->if_=true;
return ;
}
double xx=com(now->a-l*now->b,now->b,a-l*b,b),mid=l+r>>;
if(xx<=l||xx>=r)
{
if((mid-l)*b+a>(mid-l)*now->b+now->a) now->a=a,now->b=b;
return ;
}
if(xx<=mid)
{
if(now->b<b)
{
tree_down(now->lc,l,mid,now->a,now->b);
now->a=a,now->b=b,now->if_=true;
}
else tree_down(now->lc,l,mid,a,b);
}
else
{
if(now->b<b) tree_down(now->rc,mid+,r,a+(mid-l+)*b,b);
else
{
tree_down(now->rc,mid+,r,now->a+(mid-l+)*now->b,now->b);
now->a=a,now->b=b,now->if_=true;
}
}
} void tree_add(TreeNodeType *&now,ll l,ll r,ll li,ll ri,ll a,ll b)
{
if(now==NULL) now=new TreeNodeType;
if(l==li&&r==ri)
{
if(!now->if_)
{
now->if_=true;
now->a=a,now->b=b;
}
else tree_down(now,l,r,a,b);
return ;
}
ll mid=l+r>>;
if(ri<=mid) tree_add(now->lc,l,mid,li,ri,a,b);
else if(li>mid) tree_add(now->rc,mid+,r,li,ri,a,b);
else
{
tree_add(now->lc,l,mid,li,mid,a,b);
tree_add(now->rc,mid+,r,mid+,ri,a+(mid-li+)*b,b);
}
} void tree_query(TreeNodeType *&now,ll l,ll r,ll to)
{
if(now==NULL) return ;
if(now->if_) X=max(X,now->a+(to-l)*now->b);
if(l==r) return ;
ll mid=l+r>>;
if(to<=mid) tree_query(now->lc,l,mid,to);
else tree_query(now->rc,mid+,r,to);
}
};
class MaxTreeType bi; int main()
{
in(n),in(m);ll op,u,v,a,b;
for(ll i=;i<=m;i++)
{
in(op);
if(op==)
{
in(u),in(v),in(b),in(a);
bi.tree_add(bi.root,,n,u,v,a,b);
}
else if(op==)
{
in(u),in(v),in(b),in(a);
ai.tree_add(ai.root,,n,u,v,a,b);
}
else if(op==)
{
in(u);
bi.X=-INF;
bi.tree_query(bi.root,,n,u);
if(bi.X==-INF) printf("NA\n");
else printf("%lld\n",bi.X+ai.tree_query(ai.root,,n,u));
}
}
return ;
}

AC日记——The Street codechef March challenge 2014的更多相关文章

  1. Codechef March Challenge 2014——The Street

    The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...

  2. codechef January Challenge 2014 Sereja and Graph

    题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...

  3. 【分块+树状数组】codechef November Challenge 2014 .Chef and Churu

    https://www.codechef.com/problems/FNCS [题意] [思路] 把n个函数分成√n块,预处理出每块中各个点(n个)被块中函数(√n个)覆盖的次数 查询时求前缀和,对于 ...

  4. CodeChef November Challenge 2014

    重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: #include <cstdio> #include ...

  5. 刷漆(Codechef October Challenge 2014:Remy paints the fence)

    [问题描述] Czy做完了所有的回答出了所有的询问,结果是,他因为脑力消耗过大而变得更虚了:).帮助Czy恢复身材的艰巨任务落到了你的肩上. 正巧,你的花园里有一个由N块排成一条直线的木板组成的栅栏, ...

  6. [Codechef October Challenge 2014]刷漆

    问题描述 Czy做完了所有的回答出了所有的询问,结果是,他因为脑力消耗过大而变得更虚了:).帮助Czy恢复身材的艰巨任务落到了你的肩上. 正巧,你的花园里有一个由N块排成一条直线的木板组成的栅栏,木板 ...

  7. Codechef December Challenge 2014 Chef and Apple Trees 水题

    Chef and Apple Trees Chef loves to prepare delicious dishes. This time, Chef has decided to prepare ...

  8. CodeChef March Challenge 2019题解

    传送门 \(CHNUM\) 显然正数一组,负数一组 for(int T=read();T;--T){ n=read(),c=d=0; fp(i,1,n)x=read(),x>0?++c:++d; ...

  9. CODECHEF Oct. Challenge 2014 Children Trips

    @(XSY)[分塊, 倍增] Description There's a new trend among Bytelandian schools. The "Byteland Tourist ...

随机推荐

  1. react事件处理及动态样式添加

    多数据的事件绑定,循环数据来进行绑定.如下方式就是循环绑定事件的基本代码: this.state.lists.map(function(value,index,array){//代码片段}.bind( ...

  2. 《Cracking the Coding Interview》——第2章:链表——题目2

    2014-03-18 02:24 题目:给定一个单链表,找出倒数第K个节点. 解法:让一个指针先走K步,然后俩指针一起走到尽头.当然也可以先走到尽头数出链表的长度,然后第二次少走K步.其实耗费的工夫是 ...

  3. [译]15-spring 自动装配

    前面的章节我们已经学习了如何使用bean元素在xml配置文件中声明一个bean.也学习了如何使用bean的子元素contructor-arg 和property进行bean的依赖项的注入. 之前bea ...

  4. (原)Unreal渲染模块 管线 - 着色器(1)

    @author: 白袍小道 转载悄悄说明下 随缘查看,施主开心就好 说明: 本篇继续Unreal搬山部分的渲染模块的Shader部分, 主要牵扯模块RenderCore, ShaderCore, RH ...

  5. sql 删除重复的类型并且时间相同的项

    delete RemoteDetection WHERE REMOTEDETECTIONID IN ( select ID from ( select MIN(REMOTEDETECTIONID) I ...

  6. [错误解决]pandas DataFrame中经常出现SettingWithCopyWarning

    先从原dataframe取出一个子dataframe,然后再对其中的元素赋值,例如 s = d[d['col_1'] == 0] s.loc[:, 'col_2'] = 1 就会出现报错: Setti ...

  7. J2EE的十三个技术——EJB之实体Bean

    概述: 实体Bean与会话Bean不同,实体Bean是持久的,即使应用程序结束,它仍然存在.它允许共享访问,具有主键. 组成: 1)本地(Local)接口 本地访问EJB,只有在EJB与客户在同一个应 ...

  8. js 回车触发点击事件

    $(document).keyup(function(event){ if(event.keyCode ==13){ $("#submit").trigger("clic ...

  9. Codeforces Round #364 (Div. 1) 700B(树)

    题目大意 在n颗结点的树上有2k个需要配对的点,把他们两两配对,使得路程和最大并输出 选取一个点v lv表示v与父亲的边 那么考虑lv被经过的次数,对于一个最大的情况,lv应该为min(sv, 2*k ...

  10. [洛谷P4346][CERC2015]ASCII Addition

    题目大意:给一个像素的$a+b$,每个数字为$7\times5$的像素,每两个数字之间有间隔 题解:乱搞读入 卡点:无 C++ Code: #include <cstdio> #inclu ...