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. 运行SparkStreaming程序时出现 Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.ArrowA异常

    Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.ArrowA 这个问题是版本不统一导致的 ...

  2. Java从后台重定向(redirect)到另一个项目的方法

    (1)通过ModelAndView跳转 @RequestMapping("alipayforward") public ModelAndView alipayforward(Htt ...

  3. BFC相关知识

    一.什么是BFC css布局主要采用盒子模型(BOX),元素的类型和 display 属性,决定了 Box 的类型,常见的盒子类型有两种: block-level box:display 属性为 bl ...

  4. 孤荷凌寒自学python那些事第二天

    孤荷凌寒自学python第二天 Python的变量声明 (完整学习过程屏幕记录视频在文末,手写笔记在文末) Python的变量声明不必要显式指定变量类型 甚至也不需要进行显式的声明 比javascri ...

  5. 巧用Fiddler代理来禁止资源缓存,从而达到每次都是从服务器加载最新的资源

    Fiddler ->  Rules ->  Performance  -> Disable Caching 直接设置禁用缓存,再在没有清除缓存功能的APP 中重新加载最新的页面, 每 ...

  6. git使用及一些配置、问题

    安装https://git-for-windows.github.io/ 一.绑定用户名.邮件地址 git config --global user.name "Your Name" ...

  7. iPhone新建项目不能全屏

    上个周做项目的时候,发现新建了一个项目不能全屏.伤透了我的脑筋,然后又请教了团队里其他两个大牛帮我搞定了这个问题. 虽然是搞定了,但也看的出大牛也是云里雾里.歪打正着解决的. 今天又想新做个项目,这个 ...

  8. Git 提交修改

    今天发现前几天的某一个提交因为忽略文件的问题而导致有几个文件没有提交,需要修改一下某个提交,研究一下可以用rebase命令来完成,执行过程模拟如下: 1. 环境搭建,版本库如下: 文件目录如下: 假设 ...

  9. Spark on Yarn——spark1.5.1集群配置

    写在前面: spark只是一种计算框架,如果要搭建集群要依托与一定的组织模式. 目前来说,Spark集群的组织形式有三种: 1.      Standalone:使用akka作为网络IO组件,mast ...

  10. 如何写出高质量的JavaScript代码

    优秀的Stoyan Stefanov在他的新书中(<Javascript Patterns>)介绍了很多编写高质量代码的技巧,比如避免使用全局变量,使用单一的var关键字,循环式预存长度等 ...