题意:区间内乘积最小值,带修改。
解题关键:线段树裸题,考场上以为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. Python中文编码过程中遇到的一些问题

    首先,要明确encode()和decode()的差别 encode()的作用是将Unicode编码的字符串转换为其它编码格式. 比如:st1.encode("utf-8")  这句 ...

  2. 【BZOJ1095】[ZJOI2007]Hide 捉迷藏 动态树分治+堆

    [BZOJ1095][ZJOI2007]Hide 捉迷藏 Description 捉迷藏 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩捉 ...

  3. .NET Winform 将引用的dll文件集成到exe中(转)

    Winform程序经常需要引用一些第三方dll文件,这些dll在发布后与exe文件保存在同一目录下,虽然将dll文件集成到exe中会增大文件尺寸,但程序目录会相对整洁. 下面介绍一种比较简单的集成方法 ...

  4. Tomcat学习笔记【4】--- Server.xml配置文件详解

    本文主要讲如何配置Tomcat服务器. 首先展示一个BS结构图: 1 server 一个server就表示一个Tomcat实例. 1)port 指定一个端口,这个端口负责监听关闭tomcat的请求: ...

  5. Hadoop集群部署-Hadoop 运行集群后Live Nodes显示0

    可以尝试以下步骤解决: 1 ,分别删除:主节点从节点的  /usr/local/hadoop-2.6.2/etc/tmp   下得所有文件; 2: 编辑cd usr/local/hadoop-2.6. ...

  6. mac下编译FFmpeg-Android

    参考: [史上最傻瓜的]mac下编译FFmpeg-Android http://blog.csdn.net/ashqal/article/details/9381037

  7. 使用wepy 小程序授权点击取消授权失败的方案

    在wepy里使用进行小程序页面授权,里面包含了用户点击取消的重新授权方案: //auth.js /* * @Author: Porco_Mar * @Date: 2018-04-11 15:49:55 ...

  8. 使用electron静默打印

    1.使用electron打印的理由 很多情况下程序中使用的打印都是用户无感知的.并且想要灵活的控制打印内容,往往需要借助打印机给我们提供的api再进行开发,这种开发方式非常繁琐,并且开发难度较大. e ...

  9. 关于SQL语句参数中为多个带‘,’的字符串

    案例分析:画面为多分数选项,根据画面选择的分数组合=@分数,以SELECT * FROM [table_name] WHERE sore IN (@分数) 其实这不算一个复杂的问题,可能由于着急下班, ...

  10. shell之起步

    初学者,先不要考虑好不好看,效率高不高!先要实现需求!需求是第一位! grep.sed.awk.三剑客! 学好shell,需要前提! 1.linux系统命令熟练 2.搞清楚正则,grep.sed.aw ...