描述

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.

输入

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)

输出

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

样例输入

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

样例输出

1
1
4 分析得出,一区间的乘积最小值,只有三种情况
1.最大值的平方(最大值为负数)
2.最小值的平方(最小值为正数)
3.最大值与最小值的乘积(最大值是正,最小值为负)
得到此结果后,只需改一下线段树的模板,将每段区间的最大最小值保存下来即可。
 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const long long Max=;
int n;
struct node
{
long long b,s;
}Tree[Max<<];
long long bb,ss;
void build(int k,int l,int r)//建线段树,k表示子节点坐标
{
if(l == r)
{
scanf("%lld",&Tree[k].b);
Tree[k].s=Tree[k].b;
}
else
{
int mid = (l+r)/;
build(k*,l,mid);
build(k*+,mid+,r);
Tree[k].b=max(Tree[k*].b, Tree[k*+].b);
Tree[k].s=min(Tree[k*].s, Tree[k*+].s);
}
}
void query(int a,int b,int k,int l,int r)//a,b是当前查询区间,k是当前的根节点,l,r是要求查询区间
{
if(a >= l && b <= r)
{
bb=max(bb,Tree[k].b);
ss=min(ss,Tree[k].s);
//return min(min(Tree[k].b*Tree[k].b,Tree[k].b*Tree[k].s),Tree[k].s*Tree[k].s);
return;
}
else
{
//long long ans = Max*Max;
int mid = (a+b)/;
if(l <= mid)query(a,mid,k*,l,r);
if(r > mid) query(mid+,b,k*+,l,r);
return;
//return ans;
}
}
void update(int l,int r,int k,int pos,long long v)//l,r是查询区间,k是当前根节点,pos是查询位置
{
if(l == r)
{
Tree[k].b=v;
Tree[k].s=v;
}
else{
int mid = (l+r)/;
if(pos <= mid) update(l,mid,k*,pos,v);
if(pos > mid) update(mid+,r,k*+,pos,v);
Tree[k].b=max(Tree[k*].b, Tree[k*+].b);
Tree[k].s=min(Tree[k*].s, Tree[k*+].s);
}
} int main()
{
int T,l,r,pos;
long long val;
int k,c,order;
scanf("%d",&T);
for(int t=;t<=T;t++)
{ scanf("%d",&k);
n=pow(2.0,k);
build(,,n);
scanf("%d",&c);
while(c--)
{
scanf("%d",&order);
if(order==)
{
scanf("%d%d",&l,&r);
bb=-Max;ss=Max;
long long tmpans;
query(,n,,l+,r+);
tmpans= min(min(bb*bb,bb*ss),ss*ss);
printf("%lld\n",tmpans);
}
else if(order==)//点更新
{
scanf("%d%lld",&pos,&val);
update(,n,,pos+,val);
}
}
}
return ;
}

2017ICPC北京赛区网络赛 Minimum(数学+线段树)的更多相关文章

  1. 2017ICPC南宁赛区网络赛 Minimum Distance in a Star Graph (bfs)

    In this problem, we will define a graph called star graph, and the question is to find the minimum d ...

  2. 2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)

    描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0 ...

  3. hdu 4031 2011成都赛区网络赛A题 线段树 ***

    就是不知道时间该怎么处理,想了好久,看了别人的题解发现原来是暴力,暴力也很巧妙啊,想不出来的那种  -_-! #include<cstdio> #include<iostream&g ...

  4. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  5. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  6. 徐州网络赛G-Trace【线段树】

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy  ...

  7. Subsequence Count 2017ccpc网络赛 1006 dp+线段树维护矩阵

    Problem Description Given a binary string S[1,...,N] (i.e. a sequence of 0's and 1's), and Q queries ...

  8. HDU 4417 Super Mario(2012杭州网络赛 H 离线线段树)

    突然想到的节约时间的方法,感觉6翻了  给你n个数字,接着m个询问.每次问你一段区间内不大于某个数字(不一定是给你的数字)的个数 直接线段树没法做,因为每次给你的数字不一样,父节点无法统计.但是离线一 ...

  9. ACM学习历程—HDU 5023 A Corrupt Mayor's Performance Art(广州赛区网赛)(线段树)

    Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sel ...

随机推荐

  1. file 文件上传后缀转化小写

    1.上传的文件后缀是大写的我们做上传文件的时候考虑的比较少,所以我就想把客户上传的文件后缀统一一下,后面我解析附件的时候比较好解析.例子:我得到的文件名称:$infoFileName;$fileNam ...

  2. jquery解决file上传图片+图片预览

    js解决file上传图片+图片预览 demo案例中代码为js原生控制,可以根据项目的需求修改为jquery操作 <!DOCTYPE html><html lang="en& ...

  3. openssl实现双向认证教程(服务端代码+客户端代码+证书生成)

    一.背景说明 1.1 面临问题 最近一份产品检测报告建议使用基于pki的认证方式,由于产品已实现https,商量之下认为其意思是使用双向认证以处理中间人形式攻击. <信息安全工程>中接触过 ...

  4. redis集群搭建教程(以3.2.2为例)

    redis从3.0版本开始支持集群,2.X版本主支持sentinel主从模式:所以要搭建集群务必下载3.0以上版本,本教程以3.2.2版本为例. redis集群最少要有3个主节点,最典型的是3主3从组 ...

  5. URL加载jar

    // !/test.xml 是表示jar中的test.xml文件 final URL jarUrl = new URL("jar:file:/C:/proj/parser/jar/parse ...

  6. Transactional参数说明

     参数  说明 readOnly 该属性用于设置当前事务是否为只读事务,设置为true表示只读,false则表示可读写,默认值为false.例如:@Transactional(readOnly=tru ...

  7. China’s movie heroes 《红海行动》展现中国英雄本色

    Recent years have seen a trend for big military movies. Whether it was last year’s British hit Dunki ...

  8. assert用法

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: void assert( int expression ); assert的作用 ...

  9. do_bootrk

    1. LMB (logical memory blocks) lmb为uboot下的一种内存管理机制,用于管理镜像的内存.lmb所记录的内存信息最终会传递给kernel.在/include/lmb.h ...

  10. jquery插件artTxtCount输入字数限制,并提示剩余字数

    工作中用到,需要批量处理下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...