From dd559df202137899df4a2a4e7d56197837078e45 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 11 Aug 2016 10:55:50 +0800 Subject: [PATCH] Create 1077.cpp Almost exactly the same as 1070 !! Only N is different. --- hihoCoder/1077.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 hihoCoder/1077.cpp diff --git a/hihoCoder/1077.cpp b/hihoCoder/1077.cpp new file mode 100644 index 0000000..6e83e74 --- /dev/null +++ b/hihoCoder/1077.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#define INF 0x3f3f3f3f +using namespace std; +const int maxn = 1000010; +struct node +{ + int lt,rt,v; +}; +node tree[maxn<<2]; + +/** ========== Conditional =========== */ +using ValueType = int; + +inline ValueType algo_delegate(ValueType a,ValueType b) +{ + return min(a,b); +} +/****************************************/ + +void build(int lt,int rt,int v) +{ + tree[v].lt = lt; + tree[v].rt = rt; + if(lt == rt) + { + scanf("%d",&tree[v].v); + return; + } + int mid = (lt + rt)>>1; + build(lt,mid,v<<1); + build(mid+1,rt,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +void update(int p,int val,int v) +{ + if(tree[v].lt == tree[v].rt) + { + tree[v].v = val; + return; + } + if(p <= tree[v<<1].rt) update(p,val,v<<1); + if(p >= tree[v<<1|1].lt) update(p,val,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +int query(int lt,int rt,int v) +{ + if(tree[v].lt >= lt && tree[v].rt <= rt) + return tree[v].v; + int a = INF,b = INF; + if(lt <= tree[v<<1].rt) a = query(lt,rt,v<<1); + if(rt >= tree[v<<1|1].lt) b = query(lt,rt,v<<1|1); + return algo_delegate(a,b); +} + +int main() +{ + int n,m,op,u,v; + while(~scanf("%d",&n)) + { + build(1,n,1); + scanf("%d",&m); + while(m--) + { + scanf("%d %d %d",&op,&u,&v); + if(op) update(u,v,1); + else printf("%d\n",query(u,v,1)); + } + } + return 0; +}