Advertisement
Rimifawfaw

GSS1

Feb 24th, 2020
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include<bits/stdc++.h>//rimi
  2. using namespace std;
  3. #define max 100005
  4. #define ll long long
  5. int ar[max];
  6. vector<ll >tree(max*4);
  7. ll x = 0;
  8.  
  9.  
  10. void update(ll node,ll b,ll e,ll x,ll y)
  11. {
  12. if(b>e||x<b||x>e)
  13. {
  14. return;
  15. }
  16. else if(b==e && e==x )
  17. {
  18. tree[node] = y;
  19. ar[x]=y;
  20. return;
  21. }
  22. else{
  23. ll left = node*2;
  24. ll right = (node*2)+1;
  25. ll mid = (b+e)/2;
  26. update(left ,b,mid, x,y);
  27. update(right,mid+1,e,x,y);
  28. if(tree[left]>=tree[right])tree[node] = tree[left];
  29. else tree[node] = tree[right];
  30. return ;
  31. }
  32.  
  33. }
  34. ll mm =0;
  35. ll m=0;
  36.  
  37. ll query(ll node,ll b,ll e,ll x,ll y)
  38. {
  39. if(b>e||e<x||y<b)
  40. {
  41. return -INT_MAX;
  42. }
  43. else if(x==y)
  44. {
  45. return ar[x];
  46. }
  47. else if(b>=x && e<=y)
  48. {
  49. return tree[node];
  50. cout<<"tree "<<tree[node]<<endl;
  51. }
  52. else{
  53. ll left = node*2;
  54. ll right = (node*2)+1;
  55. ll mid = (b+e)/2;
  56. ll a = query(left,b,mid,x,y);
  57. ll c = query(right,mid+1,e,x,y);
  58. //cout<<"a c "<<a<<" "<<c<<endl;
  59. if(a>c)return a;
  60. else return c;
  61. }
  62.  
  63. }
  64.  
  65. int main()
  66. {
  67.  
  68. ios_base::sync_with_stdio(false);
  69. cin.tie(NULL);
  70.  
  71. ll x,y,z,a,b,c,t,i,j,n,k,h,e,w,p,q,l,o,d;
  72. string s1,s,s2,str;
  73. //tree.resize(4*n);
  74. map<char, ll>ma;
  75. cin>>n;
  76. for(i=1;i<=n;i++)
  77. {
  78. cin>>ar[i];
  79. update(1,1,n,i,ar[i]);
  80. }
  81. // input(1,1,n);
  82. cin>>t;
  83. for(i=1;i<=t;i++)
  84. {
  85. cin>>p>>q;
  86. mm=m=-INT_MAX;
  87. cout<<query(1,1,n,p,q)<<endl;
  88.  
  89. }
  90.  
  91.  
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement