I Hate ItTime Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
SubmitStatusPracticeHDU 1754
Description
Input
N M ( 0
February 20, 2013 Data Structure Data Structure
I Hate ItTime Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
SubmitStatusPracticeHDU 1754
Description
Input
N M ( 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <cstdio> #include <cstring> #include <cstdio> #include <string> #include <iostream> #include <cmath> using namespace std; char com[100]; int a[200010]; int n; struct Node{ int l, r, v; }tree[800050]; void Build(int pos, int l, int r){ tree[pos].l = l; tree[pos].r = r; if(l == r){ tree[pos].v = a[tree[pos].l]; return ; } int mid = (l + r) / 2; Build(pos * 2, l, mid); Build(pos * 2 + 1, mid + 1, r); tree[pos].v = max(tree[pos * 2].v, tree[pos * 2 + 1].v); } void Update(int pos, int idx, int val){ if(tree[pos].l == tree[pos].r){ tree[pos].v = val; return ; } int mid = (tree[pos].l + tree[pos].r) / 2; if(idx <= mid) Update(pos * 2, idx, val); else Update(pos * 2 + 1, idx, val); tree[pos].v = max(tree[pos * 2].v, tree[pos * 2 + 1].v); } int Query(int pos, int l, int r){ if(l <= tree[pos].l && tree[pos].r <= r){ return tree[pos].v; } int ret = 0, mid = (tree[pos].l + tree[pos].r) / 2; if(l <= mid){ ret =max(ret, Query(pos * 2, l, r)); } if(r > mid){ ret =max( ret, Query(pos * 2 + 1, l, r)); } return ret; } int main(){ int t, m; int x, y, i, j, k; int cnt = 0; while(~scanf("%d %d",&n ,&m)){ cnt ++; for(i = 1; i <= n; i++){ scanf("%d", &a[i]); } Build(1, 1, n); for(i = 0; i < m; i++){ scanf ("%s", com); if(com[0] == 'Q'){ //cout << com[0]; scanf("%d%d", &x, &y); printf("%d\n", Query(1, x, y)); } else if(com[0] == 'U'){ //cout << com[0]; scanf("%d%d", &x, &y); Update(1, x, y); } } } return 0; } |
code
more code
~~~~