题目9 : Minimum

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

You are given a list of integers a0, a1, …, a2^k-1.

You need to support two types of queries:

1. Output Minx,y∈[l,r] {ax∙ay}.

2. Let ax=y.

输入

The first line is an integer T, indicating the number of test cases. (1≤T≤10).

For each test case:

The first line contains an integer k (0 ≤ k ≤ 17).

The following line contains 2k integers, a0, a1, …, a2^k-1 (-2k ≤ ai < 2k).

The next line contains a integer  (1 ≤ Q < 2k), indicating the number of queries. Then next Q lines, each line is one of:

1. 1 l r: Output Minx,y∈[l,r]{ax∙ay}. (0 ≤ l ≤ r < 2k)

2. 2 x y: Let ax=y. (0 ≤ x < 2k, -2k ≤ y < 2k)

输出

For each query 1, output a line contains an integer, indicating the answer.

样例输入
1
3
1 1 2 2 1 1 2 2
5
1 0 7
1 1 2
2 1 2
2 2 2
1 1 2
样例输出
1
1
4 典型的线段树单点更新与区间最大(小)值,没什么奥妙,但是自己还是打挫了,连WA带T13发,233,最终在一位小姐姐的指导小改掉一些细节错误成功A一发 附上AC代码:
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring> using namespace std; const int MAXNODE = (<<)+;
const int MAX = 2e7+;//2*10^6+10
const int INF = 0x7fffffff; struct NODE{
int maxvalue, minvalue;
int left, right;
}node[MAXNODE]; int father[MAX]; void BuildTree(int i, int left, int right)
{
node[i].minvalue = INF;
node[i].maxvalue = -INF;
node[i].left = left;
node[i].right = right;
if(right == left)
{
father[left] = i;
return;
}
BuildTree(i<<, left, (int)(floor(left+right)/2.0));
BuildTree((i<<)+, (int)(floor(left+right)/2.0)+, right);
} //自底向上更新
void UpdateTree(int ri)
{
if(ri <= )
return;
int fi = ri/;
int a = node[fi<<].maxvalue;
int b = node[(fi<<)+].maxvalue;
node[fi].maxvalue = max(a, b);
a = node[fi<<].minvalue;
b = node[(fi<<)+].minvalue;
node[fi].minvalue = min(a, b);
UpdateTree(ri/);
} int Max, Min; //自顶向上查询
void Query_max(int i, int l, int r)
{
if(node[i].left == l && node[i].right == r)
{
Max = max(Max, node[i].maxvalue);
return;
} i <<= ;
if(l <= node[i].right)
{
if(r <= node[i].right)
{
Query_max(i, l, r);
}
else
{
Query_max(i, l, node[i].right);
}
}
i++;
if(r >= node[i].left)
{
if(l >= node[i].left)
{
Query_max(i, l, r);
}
else
{
Query_max(i, node[i].left, r);
}
}
} void Query_min(int i, int l, int r)
{
if(node[i].left == l && node[i].right == r)
{
Min = min(Min, node[i].minvalue);
return;
} i <<= ;
if(l <= node[i].right)
{
if(r <= node[i].right)
{
Query_min(i, l, r);
}
else
{
Query_min(i, l, node[i].right);
}
}
i++;
if(r >= node[i].left)
{
if(l >= node[i].left)
{
Query_min(i, l, r);
}
else
{
Query_min(i, node[i].left, r);
}
}
} int main()
{
int k, t, n, g, a, b, c;
long long ans;
ios::sync_with_stdio(false);
cin>>t;
//cout<<INF<<-INF<<endl;
while(t--)
{
cin>>k;
BuildTree(, , <<k);
for(int i = ; i <= <<k; i++)
{
cin>>g;
node[father[i]].maxvalue = node[father[i]].minvalue = g;
UpdateTree(father[i]);
}
cin>>n;
for(int i = ; i <= n; i++)
{
Max = -INF;
Min = INF;
cin>>a>>b>>c;
if(a == )
{
Query_max(, b+, c+);
Query_min(, b+, c+);
//cout<<Max<<" "<<Min<<endl;
if(Max <= )
{
ans = (long long)Max*Max;
cout<<ans<<endl;
}
else if(Min >= )
{
ans = (long long)Min*Min;
cout<<ans<<endl;
}
else
{
ans = (long long)Min*Max;
cout<<ans<<endl;
}
}
else if(a == )
{
node[father[b+]].maxvalue = node[father[b+]].minvalue = c;
UpdateTree(father[b+]);
}
}
}
return ;
}

ACM-ICPC北京赛区(2017)网络赛_Minimum的更多相关文章

  1. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  2. ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】

    题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...

  3. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  4. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  5. hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...

  6. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

  7. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  8. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

  9. 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum

    题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...

随机推荐

  1. jenkins 设置 gitlab web hooks

    背景 接口自动化期望代码push后触发实现持续集成,代码push后,自动化执行jenkins的job. 步骤 准备工作 工具:jenkins,gitlab jenkins需要安装插件:git plug ...

  2. Java入门(1) —— 变量、运算符、分支结构和程序员思维的理解

    1.计算机语言的发展史: 机器语言:机器语言是指一台计算机全部的指令集合. 汇编语言:为了减轻使用机器语言编程的痛苦,人们进行了一种有益的改进:用一些简洁的英文字母.符号串来替代一个特定的指令的二进制 ...

  3. web站点优化之使用tengine搭建静态资源服务器,静态资源合并加载案例剖析

    在一个项目还是单体架构的时候,所有的js,css,image都会在一个web网站上,看起来并没有什么问题,比如下面这样: 但是当web网站流量起来的时候,这个单体架构必须要进行横向扩展,而在原来的架构 ...

  4. Servlet知识点

    如果请求采用Get方式,则重写doGet()方法,如果请求采用Post方式,则重写doPost()方法. 下面是重写doGet()方法的servlet例子. servlet继承如下类: 整体结构: 在 ...

  5. [2013-07-22]varnish-cache 安装配置及体验笔记

    varnish安装 ubuntu12安装参考 其他系统参考 如果选择了直接从源安装的方式的话,就不要自己去编译了,以免出现意外(悲剧的我,varnishlog 有点问题,之前先编译安装了,再从源安装, ...

  6. Retrofit2.0源码解析

    欢迎访问我的个人博客 ,原文链接:http://wensibo.net/2017/09/05/retrofit/ ,未经允许不得转载! 今天是九月的第四天了,学校也正式开学,趁着大学最后一年的这大好时 ...

  7. 帆软的报表系统与泛微OA结合起来,这两个软件麦枫提供了经典的服务。

    一.集成配景泛微OA对企业的代价 泛微协同办公计划能向你供给一个协同的.集成的办公情况,使所有的办公职员都在统一且个性化的信息流派中一路事情, 解脱光阴和地区的限定,实现协同事情与知识治理. Eoco ...

  8. github+hexo搭建自己的博客网站(七)注意事项(避免read.me,CNAME文件的覆盖,手动改github page的域名)

    详细的可以查看hexo博客的演示:https://saucxs.github.io/ 绑定域名可以查看:http://www.chengxinsong.cn 可以查看在github上生成的静态文件(如 ...

  9. tomcat 和 jboss access log 日志输出详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt179 工作中nginx+jboss/tomcat反向代理集成,想打开后端jb ...

  10. oracle 索引失效的情况分析

    见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp54     1) 没有查询条件,或者查询条件没有建立索引 2) 在查询条件上 ...