HDU-problem-1754

I Hate It

Description

很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。


Input

本题目包含多组测试,请处理到文件结束。
在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目。
学生ID编号分别从1编到N。
第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩。
接下来有M行。每一行有一个字符 C (只取'Q'或'U') ,和两个正整数A,B。
当C为'Q'的时候,表示这是一条询问操作,它询问ID从A到B(包括A,B)的学生当中,成绩最高的是多少。
当C为'U'的时候,表示这是一条更新操作,要求把ID为A的学生的成绩更改为B。


Output

对于每一次询问操作,在一行里面输出最高成绩。

思路:简单的静态线段树构造,更新,查找

代码:
#include<stdio.h>
#include<iostream>
using namespace std;
#define len 200001
int tree[len];
struct Tree{
	int l;
	int r;
	int max;
}T[len*5];

int build(int l,int r,int x)  //建树
{
	T[x].l=l;
	T[x].r=r;
	if(l==r)
	{
		T[x].max=tree[l];
		return T[x].max;
	}
	int mid=(l+r)/2;
	build(l,mid,2*x);
	build(mid+1,r,2*x+1);
	return T[x].max=max(T[2*x].max,T[2*x+1].max);
}

void updata(int a,int b,int k)
{
	if(T[k].r>=a&&T[k].l<=a)
	{
		T[k].max=max(T[k].max,b);
		updata(a,b,2*k);
		updata(a,b,2*k+1);
	}
	else
		return;
}

int question(int a,int b,int m)  //询问【a,b】的最大值
{
	if(T[m].l==a&&T[m].r==b)    //T[m]在【a,b】内
	{
		return T[m].max; 
	}
	else if(T[2*m].r>=b)
		return question(a,b,2*m);
	else if(T[2*m+1].l<=a)
		return question(a,b,2*m+1);
	else{
		return max(question(a,T[2*m].r,2*m),question(T[2*m+1].l,b,2*m+1));
	}
}

int main()
{
	int n,m,i;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=1;i<=n;i++)
		{
			scanf("%d",&tree[i]);
		}
		build(1,n,1);   //开始建树
		char c;
		int a,b;
		for(int i=0;i<m;i++)
		{
			cin>>c>>a>>b; //这里我尝试scanf输入c、a、b失败了。哪位大佬会的话留言告知下,谢谢!
			if(c=='U')//改变分数
			{
				updata(a,b,1);
			}
			else if(c=='Q'){
			cout<<question(a,b,1)<<endl;
			}
		}
	}
	return 0;
}

                   
豌豆代理(又称豌豆 IP)是一款一站式国内代理 IP 服务平台,主打高匿名、低延迟、高可用的 IP 资源,支持 HTTP/HTTPS/SOCKS5 协议,适配 Windows、Mac、Android、iOS 多平台。 多类型 IP 资源与高覆盖节点 提供动态住宅 IP、静态独享 IP、数据中心 IP,覆盖全国 200 + 城市,可用率 99%+;支持省市精准选择或全国混拨,适配不同业务合规与稳定性需求。 使用:在客户端 “节点 / 线路” 页,按城市 / 类型筛选,一键连接目标 IP,适合爬虫、电商多账号运营等场景。 秒级 IP 切换与灵活调度 支持手动一键切换、秒级动态切换(切换速度低至 100ms)、定时切换(自定义时长),并自动过滤重复 IP,避免重复使用导致风险。 使用:在 “设置” 中开启 “自动切换” 并设时间间隔,或按 Ctrl+Q 快捷键一键换 IP,适配反爬虫、批量测试等高频切换场景。 全协议支持与多端适配 兼容 HTTP/HTTPS/SOCKS5 主流代理协议,可对接浏览器、爬虫脚本、客户端软件;支持 Windows、Mac、安卓、iOS 多端同步使用,跨设备无缝切换。 使用:在客户端 “协议设置” 选择对应协议,生成代理地址与端口,直接填入目标软件即可生效。 隐私安全与数据加密 自研传输加密技术保护数据传输,搭配高匿名 IP 隐藏真实地址,同时支持自动清除 Cookie / 缓存,降低隐私泄露与追踪风险。 使用:在 “安全设置” 中开启 “数据加密” 与 “自动清理缓存”,公共 WiFi 环境下优先启用,提升隐私防护等级。 智能筛选与稳定网络优化 系统自动筛选低延迟、高可用 IP,过滤失效 / 重复地址;依托自建纯净机房与独享带宽,搭配 BGP 多线接入,保障连接稳定性与速度。 使用:无需手动配置,客户端默认智能匹配合适节点,复杂网络环境可在 “网络
在网络高速发展的时代,众多的软件被开发出来,给用户带来了很大的选择余地,而且人们越来越追求更个性的需求。在这种时代背景下,商家只能以用户为导向,以商品的持续创新作为商家最重要的事项。 在新发展的时代,人们对幼儿资源互助共享平台越来越重视,才能实现幼儿资源互助共享平台的有效发挥,本文将通过幼儿资源互助共享平台的信息,分析在日常生活中对幼儿资源互助共享平台存在哪些问题探讨出进一步提升效率,管理能力的对策。 系统采用了Java技术,将所有模块采用以浏览器交互的模式,选择MySQL作为系统的数据库,来进行系统的设计。基本实现了幼儿资源互助共享平台应有的主要功能模块,本系统有管理员:首页、个人中心、用户管理、卖家管理、咨询师管理、萌宝信息管理、幼儿知识管理、保姆推荐管理、音频资源管理、二手商品管理、商品分类管理、资源分类管理、交流论坛、系统管理,用户;首页、个人中心、萌宝信息管理、保姆推荐管理、音频资源管理,卖家;首页、个人中心、二手商品管理、订单管理,咨询师;首页、个人中心、幼儿知识管理,前台首页;首页、萌宝信息、幼儿知识、保姆推荐、音频资源、二手商品、交流论坛、个人中心、后台管理、购物车等功能。 对系统进行测试后,改善了程序逻辑和代码。同时确保系统中所有的程序都能正常运行,所有的功能都能操作,本系统的开发获取幼儿资源互助共享平台信息能够更加方便快捷,同时也使幼儿资源互助共享平台信息变的更加系统化、有序化。系统界面较友好,易于操作。
### HDU 1466 Problem Description and Solution The problem **HDU 1466** involves calculating the expected number of steps to reach a certain state under specific conditions. The key elements include: #### Problem Statement Given an interactive scenario where operations are performed on numbers modulo \(998244353\), one must determine the expected number of steps required to achieve a particular outcome. For this type of problem, dynamic programming (DP) is often employed as it allows breaking down complex problems into simpler subproblems that can be solved iteratively or recursively with memoization techniques[^1]. In more detail, consider the constraints provided by similar problems such as those found in references like HDU 6327 which deals with random sequences using DP within given bounds \((1 \leq T \leq 10, 4 \leq n \leq 100)\)[^2]. These types of constraints suggest iterative approaches over small ranges might work efficiently here too. Additionally, when dealing with large inputs up to \(2 \times 10^7\) as seen in reference materials related to counting algorithms [^4], efficient data structures and optimization strategies become crucial for performance reasons. However, directly applying these methods requires understanding how they fit specifically into solving the expectation value calculation involved in HDU 1466. For instance, if each step has multiple outcomes weighted differently based on probabilities, then summing products of probability times cost across all possible states until convergence gives us our answer. To implement this approach effectively: ```python MOD = 998244353 def solve_expectation(n): dp = [0] * (n + 1) # Base case initialization depending upon problem specifics for i in range(1, n + 1): total_prob = 0 # Calculate transition probabilities from previous states for j in transitions_from(i): # Placeholder function representing valid moves prob = calculate_probability(j) next_state_cost = get_next_state_cost(j) dp[i] += prob * (next_state_cost + dp[j]) % MOD total_prob += prob dp[i] %= MOD # Normalize current state's expectation due to accumulated probability mass if total_prob != 0: dp[i] *= pow(total_prob, MOD - 2, MOD) dp[i] %= MOD return dp[n] # Example usage would depend heavily on exact rules governing transitions between states. ``` This code snippet outlines a generic framework tailored towards computing expectations via dynamic programming while adhering strictly to modular arithmetic requirements specified by the contest question format.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值