测试代码全输出0
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+1;
int n;
//int t, n, l, f[N];
//struct Peop {
// int h, id;
// friend bool operator <(Peop a, Peop b) {
// return a.h == b.h ? a.id > b.id : a.h < b.h;
// }
//}a[N];
struct SegTree {
#define lson p<<1, l, mid
#define rson p<<1|1, mid+1, r
int val[N<<2];
void push_up(int p) {
val[p] = max(val[p<<1], val[p<<1|1]);
}
void build(int p, int l, int r) {
val[p] = 0;
if (l == r) return ;
int mid = l+r>>1;
build(lson);
build(rson);
push_up(p);
}
void update(int p, int l, int r, int upos, int v) {
if (l == r) {val[upos] = v; return ;}
int mid = l+r>>1;
if (upos <= mid) update(lson, upos, v);
if (upos > mid) update(rson, upos, v);
push_up(p);
}
int query(int p, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return val[p];
int mid = l+r>>1, res = 0;
if (ql <= mid) res = max(res, query(lson, ql, qr));
if (qr > mid) res = max(res, query(rson, ql, qr));
return res;
}
}seg;
//void init() {
// seg.build(1, 0, n);
// memset(f, 0, sizeof f);
//}
//
void out() {
for (int i = 1; i <= n; ++i)
cout << seg.query(1, 0, n, i, i)<<" ";
cout << endl;
}
signed main() {
n= 10;
seg.build(1, 0, n);
out();
seg.update(1, 0, n, 4, 4);
out();
// cin >> t;
// for (int cas = 1; cas <= t; ++cas) {
// cin >> n >> l, init();
// for (int i = 1; i <= n; ++i)
// cin >> a[i].h, a[i].id = i;
// sort(a+1, a+n+1);
// for (int i = 1; i <= n; ++i) {
// int h = a[i].h, id = a[i].id;
// f[id] = seg.query(1, 0, n, max(id-l, 0LL), id-1)+h*h;
// seg.update(1, 0, n, i, f[id]-h);
// }
// printf("Case #%d: %lld\n", cas, f[n]);
// }
return 0;
}