[CC-STREETTA]The Street
[CC-STREETTA]The Street
题目大意:
给定两个长度为\(n(n\le10^9)\)的数列\(A\)和\(B\),开始数列\(A\)中每一项值为\(-\infty\),数列\(B\)中每一项值为\(0\)。\(m(m\le3\times10^5)\)次操作,操作包含以下\(3\)种:
- 数列\(A\)区间加一条等差数列。
- 数列\(B\)区间对一个等差数列取\(\max\)。
- 询问\(A_i+B_i\)。
思路:
每个结点维护一个解析式\(kx+b\)。
对于数列\(A\),使用李超树维护最大值。
对于数列\(B\),直接合并两个解析式。
时间复杂度\(\mathcal O(m\log n)\)。
源代码:
#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
register char ch;
register bool neg=false;
while(!isdigit(ch=getchar())) neg|=ch=='-';
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return neg?-x:x;
}
typedef long long int64;
const int SIZE=9e6;
struct Node {
int64 a,b;
void operator += (const Node &rhs) {
a+=rhs.a;
b+=rhs.b;
}
};
int64 calc(const Node &s,const int &x) {
return s.a*x+s.b;
}
class SegmentTree1 {
#define mid ((b+e)>>1)
private:
Node node[SIZE];
int left[SIZE],right[SIZE];
int sz,new_node() {
node[++sz]=(Node){0,LLONG_MIN};
return sz;
}
public:
int root;
void modify(int &p,const int &b,const int &e,const int &l,const int &r,Node s) {
p=p?:new_node();
if(b==l&&e==r) {
if(calc(node[p],b)<calc(s,b)) std::swap(node[p],s);
if(calc(node[p],e)>=calc(s,e)) return;
const double c=1.*(s.b-node[p].b)/(node[p].a-s.a);
if(c<=mid) {
modify(left[p],b,mid,b,mid,node[p]);
node[p]=s;
}
if(c>mid) modify(right[p],mid+1,e,mid+1,e,s);
return;
}
if(l<=mid) modify(left[p],b,mid,l,std::min(mid,r),s);
if(r>mid) modify(right[p],mid+1,e,std::max(mid+1,l),r,s);
}
int64 query(int &p,const int &b,const int &e,const int &x) {
p=p?:new_node();
int64 ret=calc(node[p],x);
if(b==e) return ret;
if(x<=mid) ret=std::max(ret,query(left[p],b,mid,x));
if(x>mid) ret=std::max(ret,query(right[p],mid+1,e,x));
return ret;
}
#undef mid
};
SegmentTree1 t1;
class SegmentTree2 {
#define mid ((b+e)>>1)
private:
Node node[SIZE];
int left[SIZE],right[SIZE];
int sz,new_node() {
return ++sz;
}
public:
int root;
void modify(int &p,const int &b,const int &e,const int &l,const int &r,const Node &s) {
p=p?:new_node();
if(b==l&&e==r) {
node[p]+=s;
return;
}
if(l<=mid) modify(left[p],b,mid,l,std::min(mid,r),s);
if(r>mid) modify(right[p],mid+1,e,std::max(mid+1,l),r,s);
}
int64 query(int &p,const int &b,const int &e,const int &x) {
p=p?:new_node();
int64 ret=calc(node[p],x);
if(b==e) return ret;
if(x<=mid) ret+=query(left[p],b,mid,x);
if(x>mid) ret+=query(right[p],mid+1,e,x);
return ret;
}
#undef mid
};
SegmentTree2 t2;
int main() {
const int n=getint(),m=getint();
for(register int i=0;i<m;i++) {
const int opt=getint();
if(opt==1) {
const int u=getint(),v=getint(),a=getint(),b=getint();
t1.modify(t1.root,1,n,u,v,(Node){a,b-(int64)u*a});
}
if(opt==2) {
const int u=getint(),v=getint(),a=getint(),b=getint();
t2.modify(t2.root,1,n,u,v,(Node){a,b-(int64)u*a});
}
if(opt==3) {
const int i=getint();
const int64 a=t1.query(t1.root,1,n,i),b=t2.query(t2.root,1,n,i);
if(a==LLONG_MIN) {
puts("NA");
} else {
printf("%lld\n",a+b);
}
}
}
return 0;
}
[CC-STREETTA]The Street的更多相关文章
- [CodeChef - STREETTA] The Street 李超线段树
大致题意: 给出两个序列A,B,A初始为负无穷,B初始为0,有三种操作 1.在A上区间[u,v]上加一个等差数列,取与原本A序列的最大值. 2.在B上区间[u,v]上加一个等差数列. 3.给出一个点X ...
- hive 下篇
由于spark on hive 问题,导致无法插入数据,暂时使用spark进行hive操作 向分区表插入数据 hive> show partitions customers;OKpartitio ...
- Spring -- 入门,装备集合,自动装配,分散装配,自定义编辑器
1. 概要 struts2:web hibernate:持久化 spring:业务层.管理bean的,容器.List Map Set. 体验spring: 1.创建java项目. 2.引入spring ...
- Codechef March Challenge 2014——The Street
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...
- Atitti.dw cc 2015 绿色版本安装总结
Atitti.dw cc 2015 绿色版本安装总结 1.1. 安装程序无法初始化.请下载adobe Support Advisor检测该问题.1 1.1.1. Adobe Application M ...
- 【Hello CC.NET】CC.NET 实现自动化集成
一.背景 公司的某一金融项目包含 12 个子系统,新需求一般按分支来开发,测完后合并到主干发布.开发团队需要同时维护开发环境.测试环境.模拟环境(主干).目前面临最大的两个问题: 1.子系统太多,每次 ...
- 浅谈iptables防SYN Flood攻击和CC攻击
------------------------本文为自己实践所总结,概念性的东西不全,这里粗劣提下而已,网上很多,本文主要说下目前较流行的syn洪水攻击和cc攻击------------------ ...
- 申请邓白氏编码的时候总是提示 Enter a valid Street Address 怎么办?
今天要申请一个苹果开发者公司(Company)账号,然后需要邓白氏编码,然后填写企业的基本信息.其中对于Street Address认真的对照着中文翻译为如下格式: Kang Hesheng buil ...
- checking for fcc ....no checking for cc .. no
源码编译,提示缺少gcc cc cl.exe 解决方案: yum install -y gcc glibc
- 编译器 cc、gcc、g++、CC 的区别
gcc 是GNU Compiler Collection,原名为Gun C语言编译器,因为它原本只能处理C语言,但gcc很快地扩展,包含很多编译器(C.C++.Objective-C.Ada.Fort ...
随机推荐
- struts集合类型封装
1.list类型封装
- Perl6多线程2: Promise new/keep/bread/status/result
来源于个人理解的翻译. 创建一个 promise: my $p = Promise.new; 可以打印运行 的Promise 状态: my $p = Promise.new(); $p.then({s ...
- 15 - reduce-pratial偏函数-lsu_cache
目录 介绍 1 reduce方法 2 partial方法(偏函数) 2.1 partial方法基本使用 2.2 partial原码分析 2.3 functools.warps实现分析 3 lsu_ca ...
- Ubuntu之镜像iso安装系统
ubuntu的安装 官网下载iso文件,网址:http://releases.ubuntu.com/16.04.4/, 选择:ubuntu-16.04.4-server-amd64.iso: 下载完毕 ...
- Arm-kernel 内存收集【转】
转自:http://blog.csdn.net/linyt/article/details/6627664 Linux kernel的内存管理子系统非常复杂,为了深入了解内存管理系统,我打算分多篇文章 ...
- HttpURLConnection传json
private static String sendToWangTing(DataRow dataRow) throws IOException{ String ip = Configuration. ...
- UFT12.续期的操作方法
安装完毕UFT后,页面中报install错误,此时报此错误的原因是因为UFT的许可证过期了,解决方法如下: 方法是找到C:\ProgramData目录下的SafeNet Sentinel文件夹将其删除 ...
- LightOJ 1410 Consistent Verdicts(找规律)
题目链接:https://vjudge.net/contest/28079#problem/Q 题目大意:题目描述很长很吓人,大概的意思就是有n个坐标代表n个人的位置,每个人听力都是一样的,每人发出一 ...
- git的一些配置
git使用socks代理加速 原来git可以配置socks代理的,真好,从github上clone了opencv的代码,基本上是满速了. 首先需要配置shadowsocks,然后通过GUI客户端(或命 ...
- java-list-分组
Map<String, List<Hb12Domain>> groupBy = hb18DomainList.stream().collect(Collectors.group ...