fork download
  1. //Range query for minimum, point update
  2.  
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. #define INF 2e9
  8. #define NMAX 100010
  9. #define TMAX ((1<<18)+10) //size should be 2**(ceil(log2(N)) +1)
  10.  
  11. int A[NMAX];
  12.  
  13. int tree[TMAX];
  14. int lookup[NMAX];
  15.  
  16. int N;
  17.  
  18. inline int left(int x){ return x*2+1; }
  19. inline int right(int x) { return x*2+2; }
  20. inline int parent(int x){ return (x+1)/2-1; }
  21.  
  22. void init(int node, int s, int e){
  23.  
  24. if(s == e){
  25. tree[node] = A[s];
  26. lookup[s] = node; //lookup for bottom up update
  27. return;
  28. }
  29.  
  30. int l,r,m;
  31. l = left(node), r = right(node) ,m = (s+e)/2;
  32.  
  33. init(l,s,m);
  34. init(r,m+1,e);
  35.  
  36. tree[node] = min(tree[l],tree[r]);
  37. }
  38.  
  39. int query(int node, int s, int e, int i, int j){
  40.  
  41. if(s > j || e < i) return INF;
  42. if(s >= i && e <= j) return tree[node];
  43.  
  44. int l,r,m;
  45. l = left(node), r = right(node), m = (s+e)/2;
  46.  
  47. return min(query(l,s,m,i,j),query(r,m+1,e,i,j));
  48. }
  49.  
  50.  
  51.  
  52. void update(int i, int val){
  53. A[i] = val;
  54.  
  55. int x = lookup[i];
  56. tree[x] = val;
  57.  
  58. while(x){
  59. x = parent(x);
  60. tree[x] = min(tree[left(x)],tree[right(x)]);
  61. }
  62. }
  63.  
  64.  
  65. //calling query and init
  66.  
  67. void init(){
  68. init(0,0,N-1);
  69. }
  70.  
  71. int query(int i, int j){
  72. return query(0,0,N-1,i,j);
  73. }
  74.  
  75.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty