minimario

<Patel Segment Tree> TEMPLATE

Dec 12th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define mp make_pair
  6. #define pb push_back
  7. #define pii pair <int, int>
  8. #define vi vector<int>
  9.  
  10. #define read1(a) int a; scanf("%d", &a)
  11. #define read2(a, b) int a, b; scanf("%d %d", &a, &b)
  12. #define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)
  13.  
  14. #define FOR(i, a, b) for (int i=a; i<b; i++)
  15. #define F0R(i, a) for (int i=0; i<a; i++)
  16.  
  17. #define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
  18. #define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }
  19.  
  20. #define f first
  21. #define s second
  22.  
  23. const int MOD = 1000000007;
  24. const int MAX = 100005;
  25.  
  26. int arr[MAX];
  27. int lazy[4*MAX];
  28. int maxi[4*MAX];
  29.  
  30. void push(int node) {
  31. if (lazy[node]){
  32. lazy[2*node]=max(lazy[2*node],lazy[node]);
  33. lazy[2*node+1] = max(lazy[2*node+1], lazy[node]);
  34. maxi[node] = max(maxi[node], lazy[node]);
  35. lazy[node] = 0;
  36. }
  37. }
  38. void update (int start, int end, int i, int j, int node, int v){
  39. push(node);
  40. if (start>j||end<i)return;
  41. if(start>=i&&end<=j){
  42. lazy[node] = v; push(node); return;
  43. }
  44. update (start, (start+end)/2, i, j, 2*node, v);
  45. update ((start+end)/2+1, end, i, j, 2*node+1, v);
  46. maxi[node] = max(maxi[2*node], maxi[2*node+1]);
  47. }
  48. int query (int start, int end, int i, int j, int node){
  49. push(node); if (start>j||end<i) return 0; if (start>=i && end<=j) return maxi[node];
  50. int f = query (start, (start+end)/2, i, j, 2*node);
  51. int s = query ((start+end)/2+1, end, i, j, 2*node+1); return max(f, s);
  52. }
  53. int main(){
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment