• hdu 1754 单点更新


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

    5 6
    1 2 3 4 5
    Q 1 5
    U 3 6
    Q 3 4
    Q 4 5
    U 2 9
    Q 1 5

    5
    6
    5
    9

    代码再次优化

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 using namespace std;
     8 int n,m,t;
     9 #define lson l,m,rt<<1
    10 #define rson m+1,r,rt<<1|1
    11 #define root 1,n,1
    12 #define m ((l+r)>>1)
    13 const int maxn=205555;
    14 int cow[maxn];
    15 int maxx[maxn<<2],minn[maxn<<2];
    16 int mmax=-1,mmin=9999999;
    17 void pushup(int rt){
    18     maxx[rt]=max(maxx[rt<<1],maxx[rt<<1|1]);
    19 }
    20 void build(int l,int r,int rt){
    21     if(l==r){
    22         scanf("%d",&maxx[rt]);
    23         return;
    24     }
    25     build(lson);
    26     build(rson);
    27     pushup(rt);
    28 }
    29 void query(int L,int R,int l,int r,int rt) {
    30     if (L<=l&&r<=R){
    31         mmax=max(mmax,maxx[rt]);
    32         return;
    33     }
    34     int ret=0;
    35     if(L<=m)  query(L,R,lson);
    36     if(R>m)  query(L,R ,rson);
    37 }
    38 void update(int pos,int val,int l,int r,int rt)
    39 {
    40     if(l==r)    maxx[rt]=val;
    41     else
    42     {
    43         if(pos<=m)  update(pos,val,lson);
    44         else update(pos,val,rson);
    45         pushup(rt);
    46     }
    47 }
    48 int main()
    49 {
    50     int i,j,k;
    51     #ifndef ONLINE_JUDGE
    52     freopen("1.in","r",stdin);
    53     #endif
    54     int q;
    55     while(scanf("%d%d",&n,&q)!=EOF)
    56     {
    57         build(root);
    58         while(q--)
    59         {
    60             char s[10];
    61             scanf("%s",s);
    62             int a,b;
    63             if(s[0]=='Q')
    64             {
    65                 scanf("%d%d",&a,&b);
    66                 mmax=-99999;
    67                 query(a,b,root);
    68                 printf("%d
    ",mmax);
    69             }
    70             else
    71             {
    72                 scanf("%d%d",&a,&b);
    73                 update(a,b,root);
    74             }
    75         }
    76     }
    77     return 0;
    78 }
  • 相关阅读:
    Hive是什么
    Hive导入数据的四种方法
    grafana安装
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    linux下mysql安装报错及修改密码登录等等
    chown -R 用户名:组名 ./ 及 chown用法介绍
    Hadoop提交作业流程
    Java中常见的几种异常
    mysql索引需要了解的几个注意
    js数组依据下标删除元素
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4355162.html
Copyright © 2020-2023  润新知