Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
  2.  
  3. #include<bits/stdc++.h>
  4. #define MAX 100005
  5. #define inf 0x7fffffff
  6.  
  7. using namespace std;
  8.  
  9. int tree_min[5*MAX],A[MAX],x,y,mid;
  10.  
  11. void build(int node,int start,int end)
  12. {
  13. if(start==end){
  14. tree_min[node]=A[start];
  15. }
  16. else{
  17. mid=(start+end)/2;
  18. build(2*node,start,mid);
  19. build(2*node+1,mid+1,end);
  20. tree_min[node]=min(tree_min[2*node],tree_min[2*node+1]);
  21. }
  22. }
  23.  
  24. void update(int node,int start,int end,int idx,int val)
  25. {
  26. if(start==end){
  27. A[idx]=val;
  28. tree_min[node]=val;
  29. }
  30. else{
  31. mid=(start+end)/2;
  32.  
  33. if(start<=idx && idx<=mid){
  34. update(2*node,start,mid,idx,val);
  35. }
  36. else{
  37. update(2*node+1,mid+1,end,idx,val);
  38. }
  39.  
  40. tree_min[node]=min(tree_min[2*node],tree_min[2*node+1]);
  41. }
  42. }
  43.  
  44. int query(int node,int start,int end,int l,int r)
  45. {
  46. if(r<start || l>end){
  47. return 100005;
  48. }
  49.  
  50. if(l<=start && r>=end){
  51. return tree_min[node];
  52. }
  53.  
  54. mid=(start+end)/2;
  55. int p1=query(2*node,start,mid,l,r);
  56. int p2=query(2*node+1,mid+1,end,l,r);
  57.  
  58. return min(p1,p2);
  59. }
  60. int main()
  61. {
  62. freopen("input.txt","r",stdin);
  63. freopen("output.txt","w",stdout);
  64. int q,i,n,tree_min;
  65. char com;
  66. cin>>n>>q;
  67.  
  68. for(i=1;i<=n;i++){
  69. cin>>A[i];
  70. }
  71. // A[0]=inf;
  72.  
  73.  
  74. build(1,1,n);
  75.  
  76. while(q--){
  77. cin>>com>>x>>y;
  78. if(com=='q'){
  79. cout<<query(1,1,n,x,y)<<endl;
  80. }
  81. else{
  82. update(1,1,n,x,y);
  83. }
  84. }
  85.  
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement