-
Minimum
时间限制:
1000ms
单点时限:
1000ms
内存限制:
256MB
描述
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.将x处的值改为y
解题要分情况讨论:如果区间内有正有负,最小乘积积就是最小(负数)与最大(正数)的乘积(结果为负数),如果区间内都正或都负结果就是绝对值最小的数的平方。题目维护三个线段树,分别求区间最小、最大、和绝对值最小的数。
要注意下标是从0开始
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include