描述

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. Matlab-9:中心差分方法解常微分算例(SOR完整版)

    函数文件: function [x,n,flag]=sor(A,b,eps,M,max1) %sor函数为用松弛迭代法求解线性方程组 %A为线性方程组的系数矩阵 %b为线性方程组的常数向量 %eps为 ...

  2. python中json的使用

    在编写接口传递数据时,往往需要使用JSON对数据进行封装.python和json数据类型的转换,看作为编码与解码. 编码:json.dumps() Python JSON dict object li ...

  3. shiro权限管理的框架-入门

    shiro权限管理的框架 1.权限管理的概念 基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问而且只能 ...

  4. API验证插件

    前言 如果在访问某WebAPI过程中request信息被他人截获,若是get请求获取数据还好,如果是post提交数据,势必威胁数据安全,所以对于一个对安全性要求较高的API来说,对每个请求做身份验证显 ...

  5. drozer安装使用教程(Windows)

    drozer和adb一样,又不是新出的工具,本不该出了这么久还要由我这样半懂不懂的再写篇东西了.但是还是一样每次使用都得百度和筛选半天,所以记下来算给自己看.以后看到我还写些老掉牙的东西都是这个原因, ...

  6. Windows和Linux创建软链接和硬链接

    1.Wondows创建软链接和硬链接 mklink [/d] [/h] link target /d--创建目录软链接:默认为文件软链接:创建目录链接时必须使用该选项不然创出的软链接无效 /h--创建 ...

  7. git merge branch

    git branch   look at your branches git branch newbranch git checkout newbrach do something git check ...

  8. 蓝桥杯—BASIC-27 2n皇后问题(DFS)

    问题描述 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后, 使任意的两个黑皇后都不在同一行.同一列或同一条对角线上,任意的两个白皇后都不在同一行. 同一列或 ...

  9. 【Eclipse使用】在eclipse里添加源文件和Api的方法

    一.源代码添加 你的JDK安装目录下%Java_home%/src.zip文件就是源码,解压缩找到对应包下面的类即可. 如果是Eclipse开发,ctr+鼠标左击,出现不了源码的话,在弹出的视图中点击 ...

  10. 8188EU 在AM335X MC183上以AP+STA工作

    [目的] 8188EU 在AM335X MC183上以AP+STA工作. [环境] 1.  Ubuntu 16.04发行版 2.  linux-3.2.0-psp04.06.00.11 3.  MC1 ...