https://hihocoder.com/problemset/problem/1586

线段树操作,原来题并不难。。。。。

当时忽略了一个重要问题,就是ax*ay要最小时,x、y可以相等,那就简单了!结果显然是模最小的数的平方或者是个负数。

要求乘积最小只要求区间内最大值、最小值和绝对值小的数,再判断min,max正负就行了。

下面的代码相当于建了三个树分别存Min,Max,Mid(abs(Min))

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long ll;
const int maxn=(<<)+;
int Max[maxn<<],Min[maxn<<],Mid[maxn<<]; int mid(int a,int b)
{
if(abs(a)<abs(b)) return a;
else return b;
} void PushUpMax(int rt)
{
Max[rt]=max(Max[rt<<],Max[rt<<|]);
} void PushUpMin(int rt)
{
Min[rt]=min(Min[rt<<],Min[rt<<|]);
} void PushUpMid(int rt)
{
Mid[rt]=mid(Mid[rt<<],Mid[rt<<|]);
} void Build(int l,int r,int rt)
{
if(l==r){
scanf("%d",&Max[rt]);
Min[rt]=Mid[rt]=Max[rt];
return;
}
int m=(l+r)>>;
Build(lson);
Build(rson);
PushUpMax(rt);
PushUpMin(rt);
PushUpMid(rt);
} void Update(int pos,int val,int l,int r,int rt)
{
if(l==r){
Mid[rt]=Min[rt]=Max[rt]=val;
return;
}
int m=(l+r)>>;
if(pos<=m) Update(pos,val,lson);
else Update(pos,val,rson);
PushUpMax(rt);
PushUpMin(rt);
PushUpMid(rt);
} int QueryMax(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
return Max[rt];
}
int m=(l+r)>>;
int res=-maxn-;
if(L<=m) res=max(res,QueryMax(L,R,lson));
if(R>m) res=max(res,QueryMax(L,R,rson));
return res;
} int QueryMin(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
return Min[rt];
}
int m=(l+r)>>;
int res=maxn+;
if(L<=m) res=min(res,QueryMin(L,R,lson));
if(R>m) res=min(res,QueryMin(L,R,rson));
return res;
} int QueryMid(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
return Mid[rt];
}
int m=(l+r)>>;
int res=maxn;
if(L<=m) res=mid(res,QueryMid(L,R,lson));
if(R>m) res=mid(res,QueryMid(L,R,rson));
return res;
} int main()
{
int T,n,m,k,a,b;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
n=<<n;
Build(,n,);
scanf("%d",&m);
while(m--)
{
scanf("%d%d%d",&k,&a,&b);
a++;
if(k==){
b++;
ll t1=(ll)QueryMax(a,b,,n,);
ll t2=(ll)QueryMin(a,b,,n,);
ll t3=(ll)QueryMid(a,b,,n,);
if((t1>=)&&(t2<=))
printf("%lld\n",t1*t2);
else if(t1<||t2>)
printf("%lld\n",t3*t3);
}
else Update(a,b,,n,);
}
}
return ;
}

从[0,n-1]建树

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long ll;
const int maxn=(<<)+;
int Max[maxn<<],Min[maxn<<],Mid[maxn<<]; int mid(int a,int b)
{
if(abs(a)<abs(b)) return a;
return b;
} void PushUpMax(int rt)
{
Max[rt]=max(Max[rt<<],Max[rt<<|]);
} void PushUpMin(int rt)
{
Min[rt]=min(Min[rt<<],Min[rt<<|]);
} void PushUpMid(int rt)
{
Mid[rt]=mid(Mid[rt<<],Mid[rt<<|]);
} void Build(int l,int r,int rt)
{
if(l==r){
scanf("%d",&Max[rt]);
Min[rt]=Mid[rt]=Max[rt];
return;
}
int m=(l+r)>>;
Build(lson);
Build(rson);
PushUpMax(rt);
PushUpMin(rt);
PushUpMid(rt);
} void Update(int pos,int val,int l,int r,int rt)
{
if(l==r){
Max[rt]=Min[rt]=Mid[rt]=val;
return;
}
int m=(l+r)>>;
if(pos<=m) Update(pos,val,lson);
else Update(pos,val,rson);
PushUpMax(rt);
PushUpMin(rt);
PushUpMid(rt);
} int QueryMax(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
return Max[rt];
}
int m=(l+r)>>;
int res=-maxn;
if(L<=m) res=max(res,QueryMax(L,R,lson));
if(R>m) res=max(res,QueryMax(L,R,rson));
return res;
} int QueryMin(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
return Min[rt];
}
int m=(l+r)>>;
int res=maxn;
if(L<=m) res=min(res,QueryMin(L,R,lson));
if(R>m) res=min(res,QueryMin(L,R,rson));
return res;
} int QueryMid(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
return Mid[rt];
}
int m=(l+r)>>;
int res=maxn;
if(L<=m) res=mid(res,QueryMid(L,R,lson));
if(R>m) res=mid(res,QueryMid(L,R,rson));
return res;
} int main()
{
int T,n,m,c,a,b;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
n=<<n;
Build(,n-,);
scanf("%d",&m);
while(m--)
{
scanf("%d%d%d",&c,&a,&b);
if(c==){
ll t1=QueryMax(a,b,,n-,);
ll t2=QueryMin(a,b,,n-,);
ll t3=QueryMid(a,b,,n-,);
if(t1>=&&t2<=)
printf("%lld\n",t1*t2);
else
printf("%lld\n",t3*t3);
}
else Update(a,b,,n-,);
}
}
return ;
}

hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】的更多相关文章

  1. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

  2. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  3. hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...

  4. hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum Time Limit:1000ms Case Time Limit:1000ms Memory Limit:256MB Description You are give ...

  5. 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum

    题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...

  6. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  7. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  8. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  9. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

随机推荐

  1. Centos rpm 卸载

    参考网址: http://blog.sina.com.cn/s/blog_7d12ba3f01014gxv.html

  2. 基于bootstrap框架在ie8以下,兼容媒体查询[css样式]

    <style type="text/css"> /*基于bootstrap框架在ie8以下,兼容媒体查询*/ .row [class^="col-" ...

  3. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---装饰模式之StarBuzzCoffee[转]

     1  2{<HeadFirst设计模式>之装饰模式 }  3{ 本单元中的类为被装饰者         }  4{ 编译工具: Delphi7.0          }  5{ E-Ma ...

  4. C++ std::map用法简介

    #include "map" //引入头文件 初始化: std::map <int, std::string> _map1; //初始化 //c++11中引入的,可以直 ...

  5. NACOS集群搭建遇到的问题

    搭建NACOS官网教程: https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html 这里说的很详细了.也有中文的.我就记录一下在搭建集群的时候 ...

  6. 只需一步,DLA开启TableStore多元索引查询加速!

    一.背景介绍 Data Lake Analytics(简称DLA)在构建第一天就是支持直接关联分析Table Store(简称OTS)里的数据,实现存储计算分离架构,满足用户基于SQL接口分析Tabl ...

  7. 转:CentOS上安装LAMP之第三步:MySQL环境及安装过程报错解决方案(纯净系统环境)

    这是AMP运行环境中最后配置的环境: 惯例传送门: 1.编译安装MySQL cd /home/zhangatle/tar tar zxvf mysql-.tar.gz cd mysql- cmake ...

  8. Codeforces 113C

    题目链接 C. Double Happiness time limit per test 5 seconds memory limit per test 128 megabytes input sta ...

  9. Ajax中post方法400和404的问题

    1.从400变成404 我相信有很多人都用过Ajax技术来获取数据,一般都是使用get来获取的,但是敏感信息就不能继续用get了,于是就换成了post,但是用post的时候有时候发生一些奇怪的事情,比 ...

  10. DirectX11笔记(三)--Direct3D初始化2

    原文:DirectX11笔记(三)--Direct3D初始化2 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010333737/article/ ...