#1586 : Minimum

Time Limit:1000ms
Case Time Limit:1000ms
Memory Limit:256MB

Description

You are given a list of integers a0, a1, …, a2^k-1.

You need to support two types of queries:

1. Output Minx,y∈[l,r] {ax∙ay}.

2. Let ax=y.

Input

The first line is an integer T, indicating the number of test cases. (1≤T≤10).

For each test case:

The first line contains an integer k (0 ≤ k ≤ 17).

The following line contains 2k integers, a0, a1, …, a2^k-1 (-2k ≤ ai < 2k).

The next line contains a integer  (1 ≤ Q < 2k), indicating the number of queries. Then next Q lines, each line is one of:

1. 1 l r: Output Minx,y∈[l,r]{ax∙ay}. (0 ≤ l ≤ r < 2k)

2. 2 x y: Let ax=y. (0 ≤ x < 2k, -2k ≤ y < 2k)

Output

For each query 1, output a line contains an integer, indicating the answer.

Sample Input
1
3
1 1 2 2 1 1 2 2
5
1 0 7
1 1 2
2 1 2
2 2 2
1 1 2
Sample Output
1
1
4
 
 
 

这个题就是区间查询最大值和最小值,通过判断区间最大值和最小值的正负来得到区间最小乘积。

代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#define inf 0x7fffffff
#define lson l,m,rt<<1
typedef long long ll;
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn=1e6+;
struct node{
int left,right,maxx,minn;
}tree[maxn*];
int st_min[maxn<<],st_max[maxn<<];
inline int minn(int a,int b){return a>b?b:a;}
inline int maxx(int a,int b){return a>b?a:b;}
void PushUP(int rt){
st_min[rt]=minn(st_min[rt<<],st_min[rt<<|]);
st_max[rt]=maxx(st_max[rt<<],st_max[rt<<|]);
}
void build(int l,int r,int rt) {
if(l==r){
scanf("%d",&st_min[rt]);
st_max[rt]=st_min[rt];
return ;
}
int m=(l+r)>>;
build(lson);
build(rson);
PushUP(rt);
}
void update(int p,int num,int l,int r,int rt){
if(l==r){
st_max[rt]=num;
st_min[rt]=num;
return ;
}
int m=(l+r)>>;
if(p<=m)update(p,num,lson);
else update(p,num,rson);
PushUP(rt);
}
int query_min(int L,int R,int l,int r,int rt){
if (L<=l&&r<=R){
return st_min[rt];
}
int m=(l+r)>>;
int ret1=inf,ret2=inf;
if(L<=m)ret1=query_min(L,R,lson);
if(R>m) ret2=query_min(L,R,rson);
return minn(ret1,ret2);
}
int query_max(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R){
return st_max[rt];
}
int m=(l+r)>>;
int ret1=-inf,ret2=-inf;
if(L<=m)ret1=query_max(L,R,lson);
if(R>m) ret2=query_max(L,R,rson);
return maxx(ret1,ret2);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d",&n);
int k=pow(,n);
build(,k,);
scanf("%d",&m);
while(m--){
int h,a,b;
scanf("%d%d%d",&h,&a,&b);
if(h==)update(a+,b,,k,);
else{
ll ans1=query_min(a+,b+,,k,);
ll ans2=query_max(a+,b+,,k,);
if(ans1<&&ans2>=)
printf("%lld\n",ans2*ans1);
else if(ans1<&&ans2<)
printf("%lld\n",ans2*ans2);
else
printf("%lld\n",ans1*ans1);
}
}
}
return ;
}
 

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

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

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

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

    https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...

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

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

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

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

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

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

  6. 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. ...

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

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

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

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

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

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

随机推荐

  1. 662. Maximum Width of Binary Tree

    https://leetcode.com/problems/maximum-width-of-binary-tree/description/ /** * Definition for a binar ...

  2. 8 REST Framework 实现Web API 1

    1 参考博客: http://blog.csdn.net/SVALBARDKSY/article/details/50548073 2  准备工作 1. 环境 Python: Python 3.5 D ...

  3. Storm Ack容错机制

  4. 【Maximal Rectangle】cpp

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones ...

  5. 使用 SpiritManager 类管理在 XNA 游戏中的精灵(十四)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  6. 启用hyper后无法打开vmware

    十万火急,想办法先让虚拟机能够打开,毕竟经常用. 网上看了无数教程都是让在控制面板中关闭hyper-v,然而并没有用. 找了好久说是不能那样关闭,得用指令.管理员运行powershell,输入下列指令 ...

  7. win7装python3.6提示api-ms-win-runtime-1-1-0.dll丢失

    win7为MSDN下的旗舰版,没有servicepack1那个,刚开始安装python3.6提示必须得安装servicepack1,于是乎到微软官网下了个900mb大小的安装包. https://ww ...

  8. Struts2 标签库与OGNL的使用

  9. linux系统——hosts文件修改

    1. 关于/etc/host,主机名和IP配置文件 Hosts - The static table lookup for host name(主机名查询静态表) Linux 的/etc/hosts是 ...

  10. windows服务-监视文件

    配置一个xml其中有是否开启监视.监视时间.监视路径. FileSystemWatcher watcherName = new FileSystemWatcher(); watcherName.Inc ...