Beispiel #1
0
void
visit()
{

    int pop_up();
    LISTPTR Pnode;

    push_down(&Pstack, v1);
    val[v1] = IN_STACK;

    while ((v1 = pop_up(&Pstack)) != 0)
    {
	Pnode = garray[v1]->first;
	garray[v1]->set = numcomps;
	while (Pnode)
	{
	    v2 = Pnode->t_vertex;
	    if (garray[v2]->status == LABEL && val[v2] == UNVISITED)
	    {
		if (earray[Pnode->edge]->intree)
		{
		    push_down(&Pstack, v2);
		    val[v2] = IN_STACK;
		}
	    }
	    Pnode = Pnode->next;
	}
    }

} /* end of visit */
Beispiel #2
0
//旋转,0为左旋,1为右旋
void Rotate(int x,int kind)
{
  int y = pre[x];
  push_down(y);
  push_down(x);
  ch[y][!kind] = ch[x][kind];
  pre[ch[x][kind]] = y;
  if(pre[y])
    ch[pre[y]][ch[pre[y]][1]==y] = x;
  pre[x] = pre[y];
  ch[x][kind] = y;
  pre[y] = x;
  push_up(y);
}
	inline void RotateTo(int k,int goal) {//把第k位的数转到goal下边
		int x = root;
		push_down(x);
		while(sz[ ch[x][0] ] != k) {
			if(k < sz[ ch[x][0] ]) {
				x = ch[x][0];
			} else {
				k -= (sz[ ch[x][0] ] + 1);
				x = ch[x][1];
			}
			push_down(x);
		}
		Splay(x,goal);
	}
 inline void Splay(int x, int goal)
 {
     push_down(x);
     while (pre[x] != goal)
     {
         if (pre[pre[x]] == goal)
         {
             Rotate(x , ch[pre[x]][0] == x);
         }
         else
         {
             int y = pre[x] , z = pre[y];
             int f = (ch[z][0] == y);
             if (ch[y][f] == x)
             {
                 Rotate(x , !f) , Rotate(x , f);
             }
             else
             {
                 Rotate(y , f) , Rotate(x , f);
             }
         }
     }
     push_up(x);
     if (goal == 0) root = x;
 }
Beispiel #5
0
	void _m(int t, int l, int r, int ll, int rr) {
		if (ll > rr) return ;
		if (ll == rr) {
			sum[t] = laz[t] = 0;
			return ;
		}
		if (sum[t] == 0) return;
		
		if (l == ll && r == rr) {
			sum[t] = 0;
			laz[t] = 1;
		}
		
		push_down(t);
		
		int mi = (ll+rr) / 2;
		if (r <= mi) {
			_m(lc(t), l, r, ll, mi);
		} else if (l > mi) {
			_m(rc(t), l, r, mi+1, rr);
		} else {
			_m(lc(t), l, mi, ll, mi);
			_m(rc(t), mi+1, r, mi+1, rr);
		}
		
		update(t);
	}
Beispiel #6
0
void InOrder(int r)
{
  if(!r)return;
  push_down(r);
  InOrder(ch[r][0]);
  printf("%d ",key[r]);
  InOrder(ch[r][1]);
}
Beispiel #7
0
int Get_kth(int r,int k)
{
  push_down(r);
  int t = size[ch[r][0]] + 1;
  if(t == k)return r;
  if(t > k)return Get_kth(ch[r][0],k);
  else return Get_kth(ch[r][1],k-t);
}
Beispiel #8
0
LL query(int p, int l, int r, int rt)
{
    if (l==r) return sum[rt];
    push_down(rt);
    int mid = (l + r) >> 1;
    if (mid >= p) return query(p, l, mid, rt<<1);
    return query(p, mid+1, r, rt<<1|1);
}
int64 query(int left, int right, int root) {
  if (left <= tree[root].left and tree[root].right <= right) {
    return tree[root].sum;
  } else if (left > tree[root].right or right < tree[root].left) {
    return 0L;
  }
  push_down(root);
  return query(left, right, root*2) + query(left, right, root*2+1);
}
Beispiel #10
0
lli sumar(tree **t,lli l,lli r){
  if((*t)->d <= l || r<=(*t)->i) return 0;
  if(l <= (*t)->i && (*t)->d <=r){
    return realC(*t);
  }
  makeSons(t);
  push_down(t);
  return (sumar(&((*t)->l),l,r) + sumar(&((*t)->r),l,r))%MOD;
}
Beispiel #11
0
void	push_a2(t_box *box)
{
	push_down(box->a, box->size);
	A[0] = B[0];
	push_up(box->b, box->size);
	box->size_a++;
	box->size_b--;
	box->nb_op++;
}
Beispiel #12
0
void	push_b2(t_box *box)
{
	push_down(box->b, box->size);
	B[0] = A[0];
	push_up(box->a, box->size);
	box->size_a--;
	box->size_b++;
	box->nb_op++;
}
Beispiel #13
0
/*
 * Helper function to push element down a heap.
 */
void push_down(double heap[], unsigned int n,  unsigned int i)
{
	unsigned int smallesti = smallest(heap,n,i);
	if( smallesti != i ){
		double temp = heap[smallesti];
		heap[smallesti] = heap[i];
		heap[i] = temp;
		push_down(heap, n, smallesti);
	}
}
Beispiel #14
0
/*
 * Helper function to extract min element and rebalance tree
 */
double pull_min(double heap[], unsigned int n, unsigned int last)
{
	double min = heap[0];
	heap[0] = heap[last];
	heap[last] = 0;
	
	push_down(heap, n, 0); 
	
	return min;
}
Beispiel #15
0
TEST(state, capsule_carries_its_own_watchers)
{
  auto sig = std::shared_ptr<detail::state_up_down_signal<int>>{};
  auto s = testing::spy();
  {
    auto st = make_state(42);
    sig = detail::access::signal(st);
    watch(st, s);
    sig->push_down(12);
    sig->send_down();
    sig->notify();
    EXPECT_EQ(1, s.count());
  }
  sig->push_down(7);
  sig->send_down();
  sig->notify();
  EXPECT_EQ(1, s.count());
  EXPECT_TRUE(sig->observers().empty());
}
phys_t buddy_allocate(unsigned int lvl) {
    unsigned int k = lvl;
    while(k < MAX_SIZE && heads[k].next == NULL) {
        ++k;
    }
    while(k > lvl) {
        push_down(k);
        --k;
    }
    return extract_mem(lvl);
}
Beispiel #17
0
static void do_it(void)
{
	struct X z[8];
	int i;
	for (i = 0; i < ARRAY_SIZE(z); i++)
		z[i] = N(i);


	Z(7).d[0] = &Z(2);
		Z(2).d[0] = &Z(4);
			Z(4).d[0] = NULL;
			Z(4).d[1] = NULL;
		Z(2).d[1] = &Z(5);
			Z(5).d[0] = NULL;
			Z(5).d[1] = NULL;
	Z(7).d[1] = &Z(1);
		Z(1).d[0] = &Z(6);
			Z(6).d[0] = NULL;
			Z(6).d[1] = NULL;
		Z(1).d[1] = &Z(3);
			Z(3).d[0] = NULL;
			Z(3).d[1] = NULL;

	struct binary_heap b = {
		.top = &Z(7),
		.sz = 7,
		.ord = X_ord
	};

	push_down(&b);

	ok_eq(b.top, &Z(1));
	ok_eq(Z(1).d[0], &Z(2));
		ok_eq(Z(2).d[0], &Z(4));
			ok_eq(Z(4).d[0], NULL);
			ok_eq(Z(4).d[1], NULL);
		ok_eq(Z(2).d[1], &Z(5));
			ok_eq(Z(5).d[0], NULL);
			ok_eq(Z(5).d[1], NULL);
	ok_eq(Z(1).d[1], &Z(3));
		ok_eq(Z(3).d[0], &Z(6));
			ok_eq(Z(6).d[0], NULL);
			ok_eq(Z(6).d[1], NULL);
		ok_eq(Z(3).d[1], &Z(7));
			ok_eq(Z(7).d[0], NULL);
			ok_eq(Z(7).d[1], NULL);
}

int main(void)
{
	plan_tests(1 + 2 + 4 + 8);
	do_it();
	return exit_status();
}
Beispiel #18
0
	int ask_min(int i, int l, int r) {
		if ( node[i].l > r || node[i].r < l )
			return inf;
		if ( l <= node[i].l && node[i].r <= r )
			return node[i].min_val;
		push_down(i);
		int res = inf;
		res = min(res, ask_min(i * 2, l, r));
		res = min(res, ask_min(i * 2 + 1, l, r));
		update(i);
		return res;
	}
Beispiel #19
0
void update(int L, int R, int l, int r, int rt)
{
    if (L <= l && R >= r)
    {
        sum[rt]++;
        return;
    }
    push_down(rt);
    int mid = (l + r) >> 1;
    if (L <= mid) update(L, R, l, mid, rt<<1);
    if (R > mid) update(L, R, mid+1, r, rt<<1|1);
}
Beispiel #20
0
void			push_a(t_box *box)
{
	push_down(box->a, box->size);
	A[0] = B[0];
	push_up(box->b, box->size);
	box->size_a++;
	box->size_b--;
	if (box->b_color == 1)
		PURPLE;
	ft_putstr("pa\n");
	box->nb_op++;
}
Beispiel #21
0
void			push_b(t_box *box)
{
	push_down(box->b, box->size);
	B[0] = A[0];
	push_up(box->a, box->size);
	box->size_a--;
	box->size_b++;
	if (box->b_color == 1)
		RED;
	ft_putstr("pb\n");
	box->nb_op++;
}
Beispiel #22
0
	void cover(int i, int l, int r, int val) {
		if ( node[i].l > r || node[i].r < l )
			return;
		if ( l <= node[i].l && node[i].r <= r ) {
			mark(i, val);
			return;
		}
		push_down(i);
		cover(i * 2, l, r, val);
		cover(i * 2 + 1, l, r, val);
		update(i);
	}
Beispiel #23
0
//Splay调整,将r结点调整到goal下面
void Splay(int r,int goal)
{
  push_down(r);
  while(pre[r] != goal)
  {
    if(pre[pre[r]] == goal)
    {
      push_down(pre[r]);
      push_down(r);
      Rotate(r,ch[pre[r]][0] == r);
    }
    else
    {
      push_down(pre[pre[r]]);
      push_down(pre[r]);
      push_down(r);
      int y = pre[r];
      int kind = ch[pre[y]][0]==y;
      if(ch[y][kind] == r)
      {
        Rotate(r,!kind);
        Rotate(r,kind);
      }
      else
      {
        Rotate(y,kind);
        Rotate(r,kind);
      }
    }
  }
  push_up(r);
  if(goal == 0) root = r;
}
void add(int left, int right, int64 c, int root) {
  if (left <= tree[root].left and tree[root].right <= right) {
    tree[root].sum += c * (tree[root].right - tree[root].left + 1);
    tree[root].mark += c;
    return;
  } else if (left > tree[root].right or right < tree[root].left) {
    return;
  }
  push_down(root);
  add(left, right, c, root*2);
  add(left, right, c, root*2+1);
  tree[root].sum = tree[root*2].sum + tree[root*2+1].sum;
}
Beispiel #25
0
void Change(int x,int l,int r,int v)
{
	if(l<=t[x].l&&r>=t[x].r&&(t[x].max[0]<=v||t[x].min[0]>v))
	{
		if(t[x].max[0]<=v) Inv(x);
		return;
	}
	if(t[x].tag) push_down(x);
	int mid=t[x].l+t[x].r>>1;
	if(l<=mid) Change(t[x].ls,l,r,v);
	if(r>mid)  Change(t[x].rs,l,r,v);
	push_up(x);
}
Beispiel #26
0
void update(int v, int L, int R, int l, int r, int rt)
{
	if (L <= l && R >= r)
	{
		sum[rt] = v * (r - l + 1);
		flag[rt] = v;
		return;
	}
	int mid = (l + r) >> 1;
	push_down(rt);
	if (L <= mid) update(v, L, R, l, mid, rt<<1);
	if (R > mid) update(v, L, R, mid + 1, r, rt<<1|1);
	push_up(rt);
}
Beispiel #27
0
// Prereq : *t is initialized
void operar(tree **t,lli l,lli r,lli a,lli b){
  if((*t)->d <= l || r<=(*t)->i) return;
  if(l <= (*t)->i && (*t)->d <=r){
    addDiffs(t,a,b);
    return;
  }
  makeSons(t);
  push_down(t);
  operar(&((*t)->l),l,r,a,b);
  operar(&((*t)->r),l,r,a,b);
  (*t)->sa = (realA((*t)->l) + realA((*t)->r))%MOD;
  (*t)->sb = (realB((*t)->l) + realB((*t)->r))%MOD;
  (*t)->sc = (realC((*t)->l) + realC((*t)->r))%MOD;
}
Beispiel #28
0
Node *insert_main(int newkey, Node *root){
  int x;	
  Node *xr;
  Node *pnt;
  int pushup;
  pushup = push_down(newkey,root,&x,&xr);
  if (pushup) {
    pnt = (Node *)malloc(sizeof(Node)); 
    pnt->count = 1;
    pnt->key[1] = x;
    pnt->branch[0] = root;
    pnt->branch[1] = xr;
    return pnt;
  }
  return root;
}
	void update(Node *proot, int start, int end, int value)
	{
		if (start > proot->r || end < proot->l)
			return;
		start = max(start, proot->l);
		end = min(end, proot->r);
		if (start == proot->l && end == proot->r)
		{
			//do something
			return;
		}
		push_down(proot);
		update(proot->pleft, start, end, value);
		update(proot->pright, start, end, value);
		pull_up(proot);
	}
Beispiel #30
0
void BinaryHeap::heapsort()
{
	int n = size;
	int tmp;
	int count=0;
	while(size>1)
	{
		tmp = A[1];
		A[1]=A[size-1];
		A[size-1]=tmp;
		size--;
		count+=push_down(1);
	}
	size = n;
	std::cout<<"The count for heapsort is: "<<count<<'\n';
}