生活随笔
收集整理的這篇文章主要介紹了
hdu1754
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- #include?<stdio.h>??
- #include?<conio.h>??
- #include?<string.h>??
- ??
- #define?max(x1,?y1)?((x1)?>?(y1)???(x1)?:?(y1))??
- #define?min(x1,?y1)?((x1)?<?(y1)???(x1)?:?(y1))??
- ??
- #define?MAXSIZE?200002??
- ??
- typedef?struct?{??
- ????int?max?;??
- ????int?left,?right?;??
- }?NODE?;??
- ??
- int?????n,?m?;??
- int?????num?[MAXSIZE]?;??
- NODE????tree[MAXSIZE?*?20]?;??
- ??
- ??
- int?build?(int?root,?int?left,?int?right)??
- {??
- ????int?mid?;??
- ??
- ??????
- ????tree[root].left?????=?left?;??
- ????tree[root].right????=?right?;??
- ??
- ??????
- ????if?(left?==?right)??
- ????{??
- ????????return?tree[root].max?=?num[left]?;??
- ????}??
- ????mid?=?(left?+?right)?/?2?;??
- ??
- ??????
- ????int?a,?b?;??
- ????a?=?build?(2?*?root,?left,?mid)?;??
- ????b?=?build?(2?*?root?+?1,?mid?+?1,?right)?;??
- ??
- ????return?tree[root].max?=?max?(a,?b)?;??
- }??
- ??
- ??
- int?find?(int?root,?int?left,?int?right)??
- {??
- ????int?mid?;??
- ??????
- ????if?(tree[root].left?>?right?||?tree[root].right?<?left)??
- ????????return?0?;??
- ??????
- ????if?(left?<=?tree[root].left?&&?tree[root].right?<=?right)??
- ????????return?tree[root].max?;??
- ??
- ??????
- ??
- ????int?a,?b?;????
- ????a?=?find?(2?*?root,?left,?right)?;??
- ????b?=?find?(2?*?root?+?1,?left,?right)?;??
- ??
- ????return?max?(a,?b)?;??
- }??
- ??
- ??
- int?update?(int?root,?int?pos,?int?val)??
- {??
- ??????
- ????if?(pos?<?tree[root].left?||?tree[root].right?<?pos)??
- ????????return?tree[root].max?;??
- ??
- ??????
- ????if?(tree[root].left?==?pos?&&?tree[root].right?==?pos)??
- ????????return?tree[root].max?=?val?;??
- ??
- ??????
- ??
- ????int?a,?b?;????
- ????a?=?update?(2?*?root,?pos,?val)?;??
- ????b?=?update?(2?*?root?+?1,?pos,?val)?;??
- ??
- ????tree[root].max?=?max?(a,?b)?;??
- ??
- ????return?tree[root].max?;??
- }??
- ??
- int?main?()??
- {??
- ????char?c?;??
- ????int?i?;??
- ????int?x,?y?;??
- ????while?(scanf?("%d%d",?&n,?&m)?!=?EOF)??
- ????{??
- ????????for?(i?=?1?;?i?<=?n?;?++i)??
- ????????????scanf?("%d",?&num[i])?;??
- ????????build?(1,?1,?n)?;??
- ??
- ????????for?(i?=?1?;?i?<=?m?;?++i)??
- ????????{??
- ????????????getchar?()?;??
- ????????????scanf?("%c%d%d",?&c,?&x,?&y)?;??
- ????????????if?(c?==?'Q')??
- ????????????{??
- ????????????????printf?("%d\n",?find?(1,?x,?y))?;??
- ????????????}??
- ????????????else??
- ????????????{??
- ????????????????num[x]?=?y?;??
- ????????????????update?(1,?x,?y)?;??
- ????????????}??
- ????????}??
- ????}??
- ????return?0?;??
- } ?
總結
以上是生活随笔為你收集整理的hdu1754的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。