fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. //Build tree for minimum
  6. void build_tree(ll int *a, ll int s,ll int e, ll int *tree, ll int index)
  7. {
  8. if(s==e)
  9. {
  10. tree[index] = a[s];
  11. return;
  12. }
  13. ll int mid = (s+e)/2;
  14. build_tree(a,s,mid,tree,2*index);
  15. build_tree(a,mid+1,e,tree,2*index+1);
  16. tree[index] = min(tree[2*index],tree[2*index+1]);
  17. return;
  18. }
  19. //Query for find min element
  20. int query(ll int *tree,ll int ss,ll int se,ll int qs,ll int qe ,ll int index)
  21. {
  22. //complete overlap
  23. if(ss>=qs and se<=qe)
  24. {
  25. return tree[index];
  26. }
  27. //No Overlap
  28. if(qe<ss || qs>se)
  29. return INT_MAX;
  30.  
  31. //partial overlap
  32. ll int mid = (ss + se)/2;
  33. ll int left = query(tree,ss,mid,qs,qe,2*index);
  34. ll int right = query(tree,mid+1,se,qs,qe,2*index+1);
  35. return min(left,right);
  36. }
  37. //point update
  38. void point_update(ll int *tree, ll int ss,ll int se, ll int i,ll int inc,ll int index)
  39. {
  40. if(i>se || i<ss)
  41. return;
  42. if(ss == se)
  43. {
  44. tree[index] = inc;
  45. return;
  46. }
  47. ll int mid = (ss + se)/2;
  48. point_update(tree,ss,mid,i,inc,2*index);
  49. point_update(tree,mid+1,se,i,inc,2*index+1);
  50. tree[index] = min(tree[2*index],tree[2*index+1]);
  51. return;
  52. }
  53.  
  54. void solve()
  55. {
  56. int n,q;
  57. cin>>n>>q;
  58.  
  59. ll a[n];
  60. for(int i=0;i<n;i++)
  61. cin>>a[i];
  62. ll tree[4*n+1]={0};
  63. build_tree(a,0,n-1,tree,1);
  64.  
  65.  
  66. while(q--)
  67. {
  68. ll num,l,r;
  69. cin>>num>>l>>r;
  70. if(num==1)
  71. {
  72. point_update(tree,0,n-1,l,r,1);
  73.  
  74. }
  75. else
  76. cout<<query(tree,0,n-1,l,r-1,1)<<endl;
  77.  
  78. }
  79.  
  80. }
  81. int main()
  82. {
  83. ios_base::sync_with_stdio(false);
  84. cin.tie(NULL);
  85. ll int t=1;
  86. // cin>>t;
  87. while(t--)
  88. {
  89. solve();
  90. }
  91.  
  92. return 0;
  93. }
  94.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:62:10: error: variable-sized object may not be initialized
        ll tree[4*n+1]={0};
                ^~~~~
1 error generated.
stdout
Standard output is empty