[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 ...
随机推荐
- iOS7 文本转语音 AVSpeechSynthesizer -转载-
http://www.cnblogs.com/qingjoin/p/3160945.html iOS7 的这个功能确实不错.我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音! Xco ...
- EasyDarwin在做拉模式转发海康RTSP摄像机视频流的过程中出现花屏问题的解决方案
问题描述 在3年前我当时基于EasyDarwin为用户开发了一款RTSP拉模式转发的程序,也发布了一篇博客<用Darwin开发RTSP级联服务器(拉模式转发)>,当时考虑的很简单,只要将R ...
- 使用IntelliJ IDEA 15和Maven创建Java Web项目(转)
1. Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和简单,所以这里也强调下,尽量使用此类工具进行项目构建, 它可以管理项目的整个生命周期. 可以通过其命令做所有相关的工 ...
- 九度OJ 1157:中位数 (中位数、排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2188 解决:1294 题目描述: 中位数定义:一组数据按从小到大的顺序依次排列,处在中间位置的一个数(或最中间两个数据的平均数). 给出一 ...
- Linux安装mariadb详细步骤
1.安装mariadb yum和源码编译安装的区别? 1.路径区别-yum安装的软件是他自定义的,源码安装的软件./configure --preifx=软件安装的绝对路径 2.yum仓库的软件,版本 ...
- 谷歌postman插件的安装与使用
下载地址:http://pan.baidu.com/s/1kTh1g4B 安装方法: 1.下载并解压 2.解压后.打开谷歌浏览器.选择很多其它工具→扩展程序,如图 3.勾选开发人员模式 4.选择载入正 ...
- (Android)react-native-splash-screen实践-解决react-native打包好后启动白屏的问题
1.安装 npm i react-native-splash-screen --save or yarn add react-native-splash-screen --save 2.自动配置 re ...
- (转)浅析三层架构与MVC模式的区别
MVC模式介绍: MVC全名是Model ViewController,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据 ...
- 使用urllib2打开网页的三种方法(Python2)
python2才有urllib2模块,python3把urllib和urllib2封装成了urllib模块 使用urllib2打开网页的三种方法 #coding:utf-8 import urllib ...
- 深入理解JVM - 线程安全与锁优化 - 第十三章
线程安全 当多个线程访问一个对象时,如果不用考虑这些线程在运行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方法进行任何其他的协调操作,调用这个对象的行为都可以获得正确的结果,那么这个对 ...