[hiho1586]Minimum
题意:区间内乘积最小值,带修改。
解题关键:线段树裸题,考场上以为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的更多相关文章
- [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 ...
- [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 ...
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Minimum Height Trees 最小高度树
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
- [LeetCode] Minimum Size Subarray Sum 最短子数组之和
Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...
- [LeetCode] Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值之二
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would ...
- [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 ...
- [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 ...
- [LeetCode] Minimum Window Substring 最小窗口子串
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
随机推荐
- Android重写FragmentTabHost来实现状态保存
近期要做一个类似QQ底部有气泡的功能,试了几个方案不太好.我想非常多开发人员使用TabHost都会知道它不保存状态.每次都要又一次载入布局.为了保存状态,使用RadioGroup来实现.状态是能够保存 ...
- windows 2008配置运行PHP5.5.X
1.安装web5.0平台安装程序.web5.0平台安装程序:http://www.iis.net/downloads (实际上更方便的是用WebPlalform安装PHP:http://www.mic ...
- HDU 2473 Junk-Mail Filter(并查集的删除操作)
题目地址:pid=2473">HDU 2473 这题曾经碰到过,没做出来. .如今又做了做,还是没做出来. ... 这题涉及到并查集的删除操作.想到了设一个虚节点,可是我把虚节点设为了 ...
- 开始使用gradle
前提配置gradle环境 每个gradle构建都是以一个脚本开始的.gradle构建默认的名称为build.gradle.当在shell中执行gradle命令时,gradle会去寻找为build.gr ...
- Trie树,又称单词查找树、字典
在百度或淘宝搜索时,每输入字符都会出现搜索建议,比如输入“北京”,搜索框下面会以北京为前缀,展示“北京爱情故事”.“北京公交”.“北京医院”等等搜索词.实现这类技术后台所采用的数据结构是什么?[中国某 ...
- iPhone,iPad如何获取WIFI名称即SSID
本文转载至 http://blog.csdn.net/wbw1985/article/details/20530281 2010年开始苹果清理了一批APP Store上的WIFI扫描软件, 缘由语焉 ...
- Awesome Vue.js vue.js学习资源链接大全 中文
https://blog.csdn.net/caijunfen/article/details/78216868
- Mybatis中resultMap的基础配置
一.概述 resultMap 元素是 MyBatis 中最重要最强大的元素.它就是让你远离 90%的需要从结果集中取出数据的 JDBC 代码的那个东西,而且在一些情形下允许你做一些 JDBC 不支持的 ...
- /etc/init.d/iptables stop
/etc/init.d/iptables stop systemctl stop firewalld.service [root@bigdata-server-01 myrestserve ...
- iOSapp内跳转到设置界面
从app内跳转到设置界面的代码如下: NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIAp ...