标签:opened desc \n return printf 输出 包含 family 流行
I Hate It
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 100523 Accepted Submission(s): 37845
分析:此题为经典线段树模板题, 标志性的更新和查询操作, 如果无数条更新和查询操作时, 想到线段树, 很可能就是一道与此题类似的线段树题欧。。
ac代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 6 const int N=200000+50; 7 struct tree{ 8 int l, r, maxn; 9 }; 10 tree t[N*3]; 11 int ans; 12 13 void build(int m, int l, int r) 14 { 15 t[m].l = l; 16 t[m].r = r; 17 if(l==r) 18 { 19 scanf("%d", &t[m].maxn); 20 return; 21 } 22 int mid = (l + r) >> 1; 23 build(m<<1, l, mid); 24 build(m<<1|1, mid+1, r); 25 t[m].maxn = max(t[m<<1].maxn, t[m<<1|1].maxn); 26 } 27 void U(int m, int a, int b) 28 { 29 if(t[m].l == t[m].r && t[m].l == a) 30 { 31 t[m].maxn = b; 32 return; 33 } 34 int mid = (t[m].l + t[m].r) >> 1; 35 if(a <= mid) 36 U(m<<1, a, b); 37 else 38 U(m<<1|1, a, b); 39 t[m].maxn = max(t[m<<1].maxn, t[m<<1|1].maxn); 40 } 41 void Q(int m, int l, int r) 42 { 43 if(t[m].l == l && t[m].r == r) 44 { 45 ans = max(ans, t[m].maxn); 46 return; 47 } 48 int mid = (t[m].l + t[m].r) >> 1; 49 if(r <= mid) 50 Q(m<<1, l, r); 51 else if(l >= mid + 1) 52 Q(m<<1|1, l, r); 53 else 54 { 55 Q(m<<1, l, mid); 56 Q(m<<1|1, mid+1, r); 57 } 58 } 59 int main() 60 { 61 int n, m; 62 while(scanf("%d%d", &n, &m)!=EOF) 63 { 64 build(1, 1, n); 65 for(int i=0;i<m;i++) 66 { 67 getchar(); 68 char c; 69 int a, b; 70 scanf("%c", &c); 71 scanf("%d%d", &a, &b); 72 if(c == ‘Q‘) 73 { 74 ans = 0; 75 Q(1, a, b); 76 printf("%d\n", ans); 77 } 78 else 79 U(1, a, b); 80 } 81 } 82 return 0; 83 }
标签:opened desc \n return printf 输出 包含 family 流行
原文地址:https://www.cnblogs.com/sqdtss/p/9437786.html