AC了,但过不了hdu
  • 板块P1531 I Hate It
  • 楼主intemd
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/11/12 22:27
  • 上次更新2023/11/4 00:45:55
查看原帖
AC了,但过不了hdu
232007
intemd楼主2021/11/12 22:27

本人萌新,对着板子改的。理论上原题是 http://acm.hdu.edu.cn/showproblem.php?pid=1754

但过不了。 怎么会事呢

#include<bits/stdc++.h>

//#define LOCAL
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0int))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'

#define print(x) cout<<(x)<<'\n'
#define print_v(x) for (int iii = 0; iii < (x).size() - 1; ++iii) {cout << (x)[iii] << ' ';}cout << (x)[(x).size() - 1]<< '\n'
using namespace std;
#define mp make_pair
#define int long long

const int inf = 0x3f3f3f3f;
const int MAXN = 200000 + 5;
int n, A[MAXN];
int mod;
struct node {
    int l, r, max_tag, m_max;
} s[MAXN * 4];


inline void push_down(int pos) {

}

inline void push_up(int pos) {
    s[pos].m_max = max(s[pos * 2].m_max, s[pos * 2 + 1].m_max);
}

void build_tree(int pos, int l, int r) {
    s[pos].l = l;
    s[pos].r = r;
    s[pos].max_tag = 0;

    if (l == r) {
        s[pos].m_max = A[l];
        return;
    }

    int mid = (l + r) / 2;
    build_tree(pos * 2, l, mid);
    build_tree(pos * 2 + 1, mid + 1, r);
    push_up(pos);
}


void update_max(int pos, int index, int k) {
    if (s[pos].l == s[pos].r) {
        s[pos].m_max = max(k, s[pos].m_max);
        return;
    }

    push_down(pos);
    int mid = (s[pos].l + s[pos].r) / 2;
    if (index <= mid) update_max(pos * 2, index, k);
    else update_max(pos * 2 + 1, index, k);
    push_up(pos);
}

int query(int pos, int x, int y) {
    if (x <= s[pos].l && s[pos].r <= y) {
        return s[pos].m_max;
    }

    push_down(pos);
    int res = 0;
    int mid = (s[pos].l + s[pos].r) / 2;
    if (x <= mid) res = max(res, query(pos * 2, x, y));
    if (y > mid) res = max(res, query(pos * 2 + 1, x, y));
    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("output.txt", "w", stdout);
    freopen("input.txt", "r", stdin);
#endif
    int m, x, y, k;
    char t;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    build_tree(1, 1, n);
    while (m--) {
        cin >> t >> x >> y;
        if (t == 'Q') {
            print(query(1, x, y));
        } else {
            update_max(1, x, y);
        }
    }
}
2021/11/12 22:27
加载中...