• HDU


    #include <algorithm>
    #include <iostream>
    #include<sstream>
    #include<cstring>
    #include<string>
    #include<cstdio>
    #include<cctype>
    #include<vector>
    #include<deque>
    #include<map>
    #include<set>
    
    #define M 200000
    #define inf 0x3f3f3f3f
    typedef long long ll;
    
    using namespace std;
    
    struct Data
    {
        int max;
        int left, right;
    }tree[M*4];
    int n, m;
    int ans;
    int x, y;
    char ch;
    
    void built(int l,int r,int k) {
        tree[k].left = l, tree[k].right = r;
        if (l == r) {
            scanf("%d", &tree[k].max);
            return;
        }
        int mid = (l + r) / 2;
        built(l, mid,k*2);
        built(mid + 1, r, k * 2 + 1);
        tree[k].max = max(tree[k * 2].max, tree[k * 2 + 1].max);
    }
    
    void search(int k) {
        if (tree[k].left >= x && tree[k].right <= y) {
            ans = max(ans, tree[k].max);
            return;
        }
        int mid = (tree[k].left + tree[k].right) / 2;
        if (x <= mid) search(k * 2);
        if(y>mid) search(k * 2 + 1);
    }
    
    void change_inv(int k) {
        if (tree[k].left == tree[k].right) {
            tree[k].max = y;
            return;
        }
        int mid = (tree[k].left + tree[k].right) / 2;
        if (x <= mid) change_inv(k * 2);
        else change_inv(k * 2 + 1);
        tree[k].max = max(tree[k * 2].max, tree[k * 2 + 1].max);
    }
    
    int main() {
        while (scanf("%d%d",&n,&m)!=EOF){
            built(1, n, 1);
            while (m--){
                cin >> ch;
                scanf("%d%d", &x, &y);
                if(ch=='Q'){
                    ans = 0;
                    search(1);
                    printf("%d
    ", ans);
                }
                else {
                    change_inv(1);
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    类和迭代器
    使用委托调用函数
    自定义类和集合
    带函数的参数返回函数的最大值
    使用程序调试输出窗口
    自定义类
    类和结构
    全局参数
    带参数的函数返回数组之和
    IS运算符
  • 原文地址:https://www.cnblogs.com/caibingxu/p/10777073.html
Copyright © 2020-2023  润新知