[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】百度地图自定义弹出窗口
我们使用百度地图的时候,点击地图上的Marker,会弹出一个该地点详细信息的窗口,如下左图所示,有时候,我们希望自己定义这个弹出窗口的内容,或者,干脆用自己的数据来构造这样的弹出窗口,但是,在百度地图 ...
- [转]Unity3D Editor 编辑器简易教程
Star 自定义编辑器简易教程 an introduction to custom editors 原文地址 http://catlikecoding.com/unity/tutorials/star ...
- Objective-C 内存管理之dealloc方法中变量释放处理
本文转载至 http://blog.sina.com.cn/s/blog_a843a8850101ds8j.html (一).关于nil http://cocoadevcentral.com/d/ ...
- EasyPlayerPro windows播放器在播放RTMP视频显示重复异常问题解决
问题来源 2017.12.18 今日有杭州某教育领域客户反馈EasyPlayerPro在播放一个rtmp源时,画面显示异常的问题.截图如下: 问题复现 一番思考, 将显示格式改为D3D显示, 正常, ...
- JSON格式之GSON解析
JSON格式之GSON解析 最近在做websocket相关,项目需要JSON解析.相较之下感觉google的GSON解析不错. JAVA后台 Gson提供了fromJson()方法来实现从Json相关 ...
- HttpPost (URLConnection)传参数中文乱码
client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000000); client.getParams( ...
- 认识影片版本(CAM、TS、TC、DVD、HD、BD、TVRIP等)
许多朋友在下载电影的时候, 往往会被各种各样的版本标识弄糊涂,今天把各种版本的缩写收集在一起,希望对大家有所帮助 . 引用: 1.CAM(枪版) CAM 通常是用数码摄像机从电影院盗录.有时会使 ...
- sap 图标查看
showicon这个程序很不错,可以显示SAP里所有的ICON(图标). 用事务码SE38直接运行程序:showicon 即可. 显示列表之后,双击任何一个图标可以显示出每一个图标的详细信息.
- 【转】Unicode(UTF-8, UTF-16)令人混淆的概念
参考地址:http://www.cnblogs.com/kingcat/archive/2012/10/16/2726334.html Java中,char类型用UTF-16编码描述一个代码单元 为啥 ...
- 如何使用安信可 ESP 系列一体化开发环境【转】
本文转载自:http://wiki.ai-thinker.com/ai_ide_use 关于 Problems 报错 注意:Eclipse 只是一个代码编写工具,它并不能读取 makefile 里面的 ...