题意:区间内乘积最小值,带修改。
解题关键:线段树裸题,考场上以为x y必须不等,还维护了次小值,尼玛嗨尼玛嗨,划水一整场,心态爆炸。

注意坐标需要+1

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<iostream>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=;
ll a[maxn],tree1[maxn<<],tree2[maxn<<];
void pushup(int rt){
tree1[rt]=max(tree1[rt<<|],tree1[rt<<]);
tree2[rt]=min(tree2[rt<<|],tree2[rt<<]);
}
void build(ll rt,ll l,ll r){
if(l==r){
tree1[rt]=tree2[rt]=a[l];
return;
}
ll mid=(l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
pushup(rt);
} void update(ll rt,ll l,ll r,ll p,ll c){
if(l>r) return;
if(l==r){
tree1[rt]=tree2[rt]=c;
return;
}
ll mid=(l+r)>>;
if(p<=mid) update(rt<<, l, mid, p, c);
else update(rt<<|, mid+, r, p, c);
pushup(rt);
} ll query1(ll rt,ll l,ll r,ll tl,ll tr){
if(tl>tr) return -inf;
if(tl<=l&&tr>=r){
return tree1[rt];
}
ll mid=(l+r)>>,res=-inf;
if(tl<=mid) res=max(res,query1(rt<<,l,mid,tl,tr));
if(tr>mid) res=max(query1(rt<<|,mid+,r,tl,tr),res);
return res;
} ll query2(ll rt,ll l,ll r,ll tl,ll tr){
if(tl>tr) return inf;
if(tl<=l&&tr>=r){
return tree2[rt];
}
ll mid=(l+r)>>,res=inf;
if(tl<=mid) res=min(res,query2(rt<<,l,mid,tl,tr));
if(tr>mid) res=min(query2(rt<<|,mid+,r,tl,tr),res);
return res;
} int main(){
ll n,m;
ios::sync_with_stdio();
cin.tie();
cout.tie();
ll t;
cin>>t;
while(t--){
cin>>n;
n=<<n;
memset(tree1, , sizeof tree1);
memset(tree2,,sizeof tree2);
memset(a,,sizeof a);
for(int i=;i<=n;i++) cin>>a[i];
build(, , n);
cin>>m;
for(int i=;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
if(a==){
ll ans1=query1(,,n,b+,c+);
ll ans2=query2(,,n,b+,c+);
if(ans1>=&&ans2<){
cout<<1ll*ans1*ans2<<"\n";
continue;
}
else if(ans1>=&&ans2>=){
cout<<1ll*ans2*ans2<<"\n";
continue;
}
else{
cout<<1ll*ans1*ans1<<"\n";
}
}
else{
update(, , n, b+, c);
}
}
} }

[hiho1586]Minimum的更多相关文章

  1. [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  2. [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  3. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  4. [LeetCode] Minimum Height Trees 最小高度树

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  5. [LeetCode] Minimum Size Subarray Sum 最短子数组之和

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  6. [LeetCode] Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值之二

    Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would ...

  7. [LeetCode] Find Minimum in Rotated Sorted Array 寻找旋转有序数组的最小值

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  8. [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. [LeetCode] Minimum Window Substring 最小窗口子串

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

随机推荐

  1. SWT经常使用组件

    1button组件(Button) (1)Button组件经常使用样式 SWT.PUSHbutton SWT.CHECK多选button SWT.RADIO单选button SWT.ARROW箭头bu ...

  2. 引用变量的类型强转以及InstanceOf方法的使用

    引用到的类: class Person{ String name; } class Student extends Person{ String sut_no; } class ClassMate e ...

  3. 一些重要的地址:md5在线解密破解

    md5在线解密破解:https://www.cmd5.com/

  4. 微信小程序 原生代码 转wepy 字符串处理

    import globimport os cwd = os.getcwd()sep = os.septarget = cwd + sep + 'pages' + sep + '*' + sep + ' ...

  5. power law 幂定律

    y=cx∧a 卖品销量排名与销量

  6. 【题解】Jury Compromise(链表+DP)

    [题解]Jury Compromise(链表+DP) 传送门 题目大意 给你\(n\le 200\)个元素,一个元素有两个特征值,\(c_i\)和\(d_i\),\(c,d \in [0,20]\), ...

  7. OSGI简介(转)

    原文地址 目前,业内关于OSGI技术的学习资源或者技术文档还是很少的.我在某宝网搜索了一下“OSGI”的书籍,结果倒是有,但是种类少的可怜,而且几乎没有人购买.因为工作的原因我需要学习OSGI,所以我 ...

  8. 数据结构ADT是什么

    抽象数据类型的缩写 abstract data type .表示数据结构的抽象模型.数据结构是一个数据概念的定义,通过各种工具对数据结构的概念类型的描述称之为抽象数据类型,简单地说是指一个数学模型以及 ...

  9. 学习c语言的第14天

    #include <stdio.h> #include <string.h> struct student { int age; char sex; char name[100 ...

  10. 9.1 NOIP普及组试题精解(1)

    9-1 series1.c #include <stdio.h> int main() { float s=0.0,k; int n; printf("输入数字k(1~15):& ...