ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 Minimum

本文介绍了一种使用树状数组或线段树解决区间查询及更新问题的方法,具体为查询指定区间内两数乘积的最小值,并允许更新指定位置的数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目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, -2≤ 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
题意:查询给定区间两个数字乘积的最小值 注意数字存在负数!!!!! 首先求出该区间的最小值和最大值,若最小值大于等于0,那么数字乘积的最小值就是最小值的平方;反之,如果最大值小于0,那乘积的最小值一定是正的,即为最大值的平方,否则就为最小值和最大值的乘积 求区间最值问题并修改  则用树状数组 或 线段树 代码如下:
#include <iostream>  
#include <stdio.h>  
#include <stdlib.h>  
using namespace std; 
typedef long  long int ll; 
   
const int MAXN =131084;  
const int INF=0x3f3f3f3f;
ll a[MAXN], h[MAXN], l[MAXN];  
ll n,m;
ll pow1(ll a,ll b)
{
    ll res=1,base=a;
    while(b)
    {
        if(b&1)
            res*=base;
        base*=base;
        b=b>>1;
    }
    return res;
}  
   
ll lowbit(ll x)  
{  
    return x & (-x);  
}  
void updata_min(ll x)  
{  
    ll lx, i;  
    while (x <= n)  
    {  
        h[x] = a[x];  
        lx = lowbit(x);  
        for (i=1; i<lx; i<<=1)  
            h[x] = min(h[x], h[x-i]);  
        x += lowbit(x);  
    }  
} 
void  updata_max(ll x)
{
	ll lx, i;  
    while (x <= n)  
    {  
        l[x] = a[x];  
        lx = lowbit(x);  
        for (i=1; i<lx; i<<=1)  
            l[x] = max(l[x], l[x-i]);  
        x += lowbit(x);  
    }  
}
ll query_max(ll x, ll y)  
{  
    ll ans = -INF;  
    while (y >= x)  
    {  
        ans = max(a[y], ans);  
        y --;  
        for (; y-lowbit(y) >= x; y -= lowbit(y))  
            ans = max(l[y], ans);  
    }  
    return ans;  
}  
ll query_min(ll x, ll y)  
{  
    ll ans = INF;  
    while (y >= x)  
    {  
        ans = min(a[y], ans);  
        y --;  
        for (; y-lowbit(y) >= x; y -= lowbit(y))  
            ans = min(h[y], ans);  
    }  
    return ans;  
}  
int main()  
{  
    ll i, j, x, y, ans_min,ans_max;  
    char c;  
    int t; 
    scanf("%d",&t);
    while(t--)
    {
    	scanf("%lld",&n);
    	n=pow1(2,n);
    	for (i=1; i<=n; i++)  
            h[i] = 0; 
        for (i=1;i<=n;i++)
        	l[i] = 0;
    	for (i=1; i<=n; i++)  
        {  
            scanf("%lld",&a[i]);  
            updata_min(i);  
            updata_max(i);
        }  
        scanf("%d",&m);
        for (i=1; i<=m; i++)  
        {  
        	int p;
            scanf("%d%lld%lld",&p,&x,&y); 
            //cout<<p<<endl;
            //cout<<endl;
			if(p==1) 
			{
				ans_min = query_min(x+1,y+1);
				//ans_max	= query_max(x+1,y+1);
				//cout<<ans_min<<"  "<<ans_max<<endl; 
				if(ans_min>=0)
					printf("%lld\n",ans_min*ans_min);
				else
				{
					ans_max	= query_max(x+1 ,y+1);
					if(ans_max<=0)
						printf("%lld\n",ans_max*ans_max);
					else	 
            			printf("%lld\n",ans_min*ans_max);  
				}
				
			}
			else
			{
				a[x+1]=y;
				updata_min(x+1);
				updata_max(x+1);
			}
        }  
    }  
    return 0;  
}



1. 用户与身体信息管理模块 用户信息管理: 注册登录:支持手机号 / 邮箱注册,密码加密存储,提供第三方快捷登录(模拟) 个人资料:记录基本信息(姓名、年龄、性别、身高、体重、职业) 健康目标:用户设置目标(如 “减重 5kg”“增肌”“维持健康”)及期望周期 身体状态跟踪: 体重记录:定期录入体重数据,生成体重变化曲线(折线图) 身体指标:记录 BMI(自动计算)、体脂率(可选)、基础代谢率(根据身高体重估算) 健康状况:用户可填写特殊情况(如糖尿病、过敏食物、素食偏好),系统据此调整推荐 2. 膳食记录与食物数据库模块 食物数据库: 基础信息:包常见食物(如米饭、鸡蛋、牛肉)的名称、类别(主食 / 肉类 / 蔬菜等)、每份重量 营养成分:记录每 100g 食物的热量(kcal)、蛋白质、脂肪、碳水化合物、维生素、矿物质量 数据库维护:管理员可添加新食物、更新营养数据,支持按名称 / 类别检索 膳食记录功能: 快速记录:用户选择食物、输入食用量(克 / 份),系统自动计算摄入的营养成分 餐次分类:按早餐 / 午餐 / 晚餐 / 加餐分类记录,支持上传餐食照片(可选) 批量操作:提供常见套餐模板(如 “三明治 + 牛奶”),一键添加到记录 历史记录:按日期查看过往膳食记录,支持编辑 / 删除错误记录 3. 营养分析模块 每日营养摄入分析: 核心指标计算:统计当日摄入的总热量、蛋白质 / 脂肪 / 碳水化合物占比(按每日推荐量对比) 微量营养素分析:检查维生素(如维生素 C、钙、铁)的摄入是否达标 平衡评估:生成 “营养平衡度” 评分(0-100 分),指出摄入过剩或不足的营养素 趋势分析: 周 / 月营养趋势:用折线图展示近 7 天 / 30 天的热量、三大营养素摄入变化 对比分析:将实际摄入与推荐量对比(如 “蛋白质摄入仅达到推荐量的 70%”) 目标达成率:针对健
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值