Advertisement
nicuvlad76

Untitled

Dec 17th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <vector>
  5. #define N 100000
  6. #define oo 2000000000
  7. using namespace std;
  8. ifstream fin("aemi.in");
  9. ofstream fout("aemi.out");
  10. int aint[4*N], n, Q;
  11. inline void Update(int p, int x)
  12. {
  13. int tata;
  14. aint[p]=x;
  15. while(p>=1)
  16. {
  17. tata=p/2;
  18. aint[tata]=min(aint[2*tata], aint[2*tata+1]);
  19. p=tata;
  20. }
  21. }
  22.  
  23. inline int Query(int k,int st, int dr, int x, int y)
  24. {
  25. if(st==x && dr==y) return aint[k];
  26. int mij=(st+dr)/2;
  27. if(mij<x) return Query(2*k+1, mij+1, dr, x,y);
  28. else if(mij>=y)
  29. return Query(2*k,st, mij, x, y);
  30. else
  31. return min(Query(2*k,st, mij, x, mij),Query(2*k+1, mij+1, dr, mij+1,y) );
  32.  
  33. }
  34.  
  35. int main()
  36. {
  37.  
  38. int k, p,i, op, x, y;
  39. fin>>k;
  40. n=1;
  41. while(n<k) n*=2;
  42. p=n;
  43. for(i=1;i<=k;i++)
  44. {
  45. fin>>x;
  46. aint[p++]=x;
  47. }
  48. for( ; p<=2*n-1;p++)
  49. aint[p]=oo;
  50. for(i=n-1;i>=1;i--)
  51. aint[i]=min(aint[2*i], aint[2*i+1]);
  52.  
  53. fin>>Q;
  54. while(Q--)
  55. {
  56. fin>>op>>x>>y;
  57. if(op==2)Update(n-1+x,y);
  58. else fout<<Query(1,1,n,x,y)<<"\n";
  59. }
  60. return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement