HDU-I Hate It
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
在每个测试的第一行,有两个正整数 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。
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
6
5
9
Huge input,the C function scanf() will work better than cin
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std; #define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 const int MX = 222222;
int sum[MX<<2];
int n, q; void push_up(int rt) {
sum[rt] = max(sum[rt<<1], sum[rt<<1|1]);
}
void Build(int l, int r, int rt) {
if (l == r) {
scanf("%d", &sum[rt]);
return ;
}
int m = (l + r)>>1;
Build(lson);
Build(rson);
push_up(rt);
}
void update(int pos, int add, int l, int r, int rt) {
if (l == r) {
sum[rt] = add;
return ;
}
int m = (l + r)>>1;
if (pos <= m) update(pos, add, lson);
else update(pos, add, rson);
push_up(rt);
}
int Query(int L, int R, int l, int r, int rt) {
if (L <= l && r <= R) {
return sum[rt];
}
int m = (l + r)>>1;
int Max = -INF;
if (L <= m) Max = max(Max, Query(L, R, lson));
if (R > m) Max = max(Max, Query(L, R, rson));
return Max;
}
int main() {
//freopen("input.txt", "r", stdin);
while (scanf("%d %d", &n, &q) != EOF) {
memset(sum, 0, sizeof(sum)); Build(1, n, 1);
while (q--) {
char ch[5];
int i, j;
scanf("%s %d %d", ch, &i, &j);
if (ch[0] == 'Q') {
printf("%d\n", Query(i, j, 1, n, 1));
} else {
update(i, j, 1, n, 1);
}
}
}
return 0;
}
HDU-I Hate It的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
- HDU 2586
http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...
随机推荐
- jQuery each用法及each解析json
$(function(){ $("button").click( function(){ var a1=""; var a2=""; var ...
- jQuery – 8.事件和事件参数
事件 (*)JQuery中的事件绑定:$("#btn").bind("click",function(){}),每次都这么调用太麻烦,所以jQuery可 ...
- PHP中array_merge和array相加的区别分析
今天处理一个这样的问题:如何获取字符键名相同值不同的两个数组值集合,用array_merge和数组相加都不可行,让我认真比较了下PHP中array_merge和array相加的区别 首先来看看键名是s ...
- html5 基本布局+新标签+新选择器 + 线性渐变
html5 基本布局+新标签 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- linux SecureCRT ssh key认证登陆
转自:http://blog.chinaunix.net/uid-20639775-id-3207171.html 通过SecureCRT创建key登录认证 一.生成公钥/密钥对 使用SecureCR ...
- 如何把Eclipse工程导入到Android Studio
1 在Eclipse中新建android项目androiddemo.里面只有一个MainActivity,主要是使用fastjson将一个Person对象转化成字符串. 2 在项目上点击右键-&g ...
- Linux学习笔记(15)shell基础之Bash基本功能
1 shell概述 shell是一个命令解释器,为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序.用户可以用shell启动.挂起.停止甚至是编写一些程序. shell是一个功能强大 ...
- LoadRunner参数化之数据生成方式
一般需要使用多条数据来完成实际事务的时候,需要参数化.而使用参数化可以方便实现很多实际事务,记得在哪里看到过,参数化是比C函数更高级的函数. 参数化的方法 先来个最常见的LR示例的登录脚本: Acti ...
- strcmp函数使用总结
Action() { /********************************* * Author:旺仔 * object:strcmp * date:2015-12-09 * fuc:我输 ...
- 使用J2SE API读取Properties文件的六种方法
1.使用java.util.Properties类的load()方法示例: InputStream in = lnew BufferedInputStream(new FileInputStream( ...