Esempio n. 1
0
 inline void insert(int loc, int value) {
     rotateTo(loc, 0);
     rotateTo(loc + 1, root);
     newNode(dealTree, value);
     fa[dealTree] = child[root][1];
     pushUp(child[root][1]);
     pushUp(root);
 }
Esempio n. 2
0
 inline void add(int left, int right, int cnt_value) {
     rotateTo(left - 1, 0);
     rotateTo(right + 1, root);
     value[dealTree] += cnt_value; 
     add_lazy[dealTree] += cnt_value;
     min_number[dealTree] += cnt_value;
     pushUp(child[root][1]);
     pushUp(root);
 }
Esempio n. 3
0
 inline void init(int n) {
     fa[0] = tree_size[0] = child[0][0] = child[0][1] = 0;
     root = 0;
     add_lazy[0] = reverse_lazy[0] = 0;
     value[0] = min_number[0] = INF;
     top_1 = 0;
     top_2 = 0;
     newNode(root, INF);
     newNode(child[root][1], INF);
     fa[child[root][1]] = root;
     makeTree(dealTree, 1, n, input, child[root][1]);
     pushUp(child[root][1]);
     pushUp(root);
 }
Esempio n. 4
0
 inline void splay(int x, int goal) {
     pushDown(x);
     while (fa[x] != goal) {
         if (fa[fa[x]] == goal) {
             rotate(x, x == child[fa[x]][0]);
         }
         else {
             int y = fa[x];
             int z = fa[y];
             int f = child[z][0] == y;
             if (child[y][f] == x) {
                 rotate(x, !f);
                 rotate(x, f);
             }
             else {
                 rotate(y, f);
                 rotate(x, f);
             }
         }
     }
     pushUp(x);
     if (goal == 0) {
         root = x;
     }
 }
Esempio n. 5
0
 inline void rot(int x) {
     int f = fa[x], ff = fa[f];
     int p = d(x), pp = d(f);
     if(isRoot(f)) fa[x] = ff;
     else setc(ff, x, pp);
     setc(f, c[x][p^1], p), setc(x, f, p^1);
     pushUp(f);
 }
Esempio n. 6
0
void MaxHeap::insert(Song s){
    ++ length;
    s.lastPlayed = currentTime;
    int key = (1000 * s.likeability);
    *(songs + length) = s;
    hashmap.insert(s, length);
    pushUp(length, key);
}
Esempio n. 7
0
 inline void access(int x) {
     for(int y = 0; x; y = x, x = fa[x]) {
         splay(x);
         if(c[x][1]) m[x][lc[c[x][1]]].insert(maxl[c[x][1]]);
         if(y) m[x][lc[y]].erase(m[x][lc[y]].find(maxl[y]));
         setc(x, y, 1), pushUp(x);
     }
 }
Esempio n. 8
0
 inline void access(int x) {
     for(int y = 0; x; y = x, x = fa[x]) {
         splay(x);
         s[x][lc[c[x][1]]] += maxl[c[x][1]];
         s[x][lc[y]] -= maxl[y];
         setc(x, y, 1), pushUp(x);
     }
 }
Esempio n. 9
0
inline void build(int l, int r) {
	delta[CID] = FibMatrix(true);
	if(l >= r) {
		sum[CID] = U * power(T, a[l]);
	} else {
		build(LSON); build(RSON);
		pushUp(l, r);
	}
}
Esempio n. 10
0
void build(int l,int r,int rt)
{
	sum[rt]=1;
	col[rt]=0;
	if(l==r)return;
	int m=(l+r)>>1;
	build(l,m,rt<<1);
	build(m+1,r,rt<<1|1);
	pushUp(rt);
}
Esempio n. 11
0
void MaxHeap::pushUp(int pos, int key){
    if(pos != 1){
	int parentPos = floor(pos / 2);
	int keyParent = (songs + parentPos)->getKey(&currentTime);
	if(keyParent < key){
	    swap(pos, parentPos);
	    pushUp(parentPos, key);
	}
    }
}
Esempio n. 12
0
 inline void splay(int x) {
     while(!isRoot(x)) {
         if(!isRoot(fa[x])) {
             if(d(x) == d(fa[x])) rot(fa[x]);
             else rot(x);
         }
         rot(x);
     }
     pushUp(x);
 }
Esempio n. 13
0
 inline void makeTree(int &x, int left, int right, int *arr, int father) {
     if (left > right) {
         return ;
     }
     int mid = (left + right) >> 1;
     newNode(x, arr[mid]);
     makeTree(child[x][0], left, mid - 1, arr, x);
     makeTree(child[x][1], mid + 1, right, arr, x);
     fa[x] = father;
     pushUp(x);
 }
Esempio n. 14
0
inline void update(int l, int r, int ul, int ur, const FibMatrix& m) {
	if(l > ur || r < ul) { return;}
	if(l >= ul && r <= ur) {
		delta[CID] *= m;
		sum[CID] *= m;
	} else {
		update(LSON, ul, ur, m);
		update(RSON, ul, ur, m);
		pushUp(l, r);
	}
}
Esempio n. 15
0
	void update_tree(int L, int R, int fn, int id){
		if (L == R){
			multiset<int>::reverse_iterator ptr=D[V[L]].rbegin();
			tree[id].mxL = tree[id].mxR = tree[id].mx = *ptr;
			ptr++;
			tree[id].mx = max(-INF,tree[id].mx+(*ptr));
			return ;
		}
		int M=(L+R)/2;
		if (fn <= M) update_tree(L,M,fn,id*2+1);
		else update_tree(M+1,R,fn,id*2+2);
		pushUp(L,R,id);
	}
Esempio n. 16
0
 inline void deleteTree(int x) {
     int cnt_father = fa[x];
     int front = 0;
     int rear = 1;
     que[front] = x;
     while (front < rear) {
         mem_sta[top_2++] = que[front];
         if (child[que[front]][0]) {
             que[rear++] = child[que[front]][0];
         }
         if (child[que[front]][1]) {
             que[rear++] = child[que[front]][1];
         }
         front++;            
     }
     child[cnt_father][x == child[cnt_father][0]] = 0;
     while (cnt_father != root) {
         pushUp(cnt_father);
         cnt_father = fa[cnt_father];
     }
     pushUp(root);
 }
Esempio n. 17
0
void update(int L,int R,int c,int l,int r,int rt)
{
	if(L<=l&&R>=r)
	{
		col[rt]=c;
		sum[rt]=(r-l+1)*c;
		return;
	}
	pushDown(rt, r-l+1);
	int m=(l+r)>>1;
	if(L<=m)update(L,R,c,l,m,rt<<1);
	if(R>m)update(L,R,c,m+1,r,rt<<1|1);
	pushUp(rt);
}
Esempio n. 18
0
 inline void rotate(int x, int c) {
     int y = fa[x];
     pushDown(y);
     pushDown(x);
     child[y][!c] = child[x][c];
     fa[child[x][c]] = y;
     fa[x] = fa[y];
     if (fa[x]) {
         child[fa[x]][child[fa[y]][1] == y] = x;
     }
     child[x][c] = y;
     fa[y] = x;
     pushUp(y);
 }
Esempio n. 19
0
 void update(int u, int l, int r, int b, int e, int v) {
     if(b <= l && e >= r) {
         node[u] = lazy[u] = v;
         return;
     }
     pushDown(u);
     int m = l + (r - l) / 2;
     if(b <= m) {
         update(lson(u), l, m, b, e, v);
     }
     if(e > m) {
         update(rson(u), m + 1, r, b, e, v);
     }
     pushUp(u);
 }
Esempio n. 20
0
File: 3468.cpp Progetto: cwchym/ACM
void update(__int64 uL,__int64 uR,__int64 c,__int64 rt)
{
	if(N[rt].l>=uL&&uR>=N[rt].r)
	{
		N[rt].addMark+=c;
		N[rt].sum+=(__int64)c*(N[rt].r-N[rt].l+1);
		return;
	}

	pushDown(rt);
	__int64 mid=(N[rt].l+N[rt].r)>>1;
	if(uL<=mid)update(uL,uR,c,rt<<1);
	if(uR>mid)update(uL,uR,c,rt<<1|1);
	pushUp(rt);
}
Esempio n. 21
0
void MaxHeap::like(std::string title){
    Song tmp = Song();
    tmp.title = title;
    int pos = hashmap.getValue(tmp);    
    if(pos == -1){
	// std::cout << title << " is not in your playlist" << std::endl;
	return;
    }
    if((songs + pos)->likeability >= 0){
	(songs + pos)->likeability ++;
    }else{
	(songs + pos)->likeability = 1;
    }
    int key = (songs + pos)->getKey(&currentTime);
    pushUp(pos, key);
}
Esempio n. 22
0
File: 3468.cpp Progetto: cwchym/ACM
void build(__int64 a,__int64 l,__int64 r)
{
	N[a].addMark=0;
	N[a].l=l;
	N[a].r=r;
	if(l==r)
	{
		scanf("%I64d",&(N[a].sum));
		return;
	}

	__int64 mid=(l+r)/2;
	build(a<<1,l,mid);
	build(a<<1|1,mid+1,r);
	pushUp(a);
}
Esempio n. 23
0
void build(int order, int left, int right) {
    int mid = (left + right) >> 1;
    segment[order].left = left;
    segment[order].right = right;
    if (left == right) {
        if (stones[left]) {
            segment[order].black_length = segment[order].left_black = segment[order].right_black = 1;
            segment[order].white_length = segment[order].left_white = segment[order].right_white = 0;
        }
        else {
            segment[order].black_length = segment[order].left_black = segment[order].right_black = 0;
            segment[order].white_length = segment[order].left_white = segment[order].right_white = 1;            
        }
        return ;
    }
    build(order * 2, left, mid);
    build(order * 2 + 1, mid + 1, right);
    pushUp(order);
}
Esempio n. 24
0
void update(int order, int left, int right) {
    int mid = (segment[order].left + segment[order].right) >> 1;
    if (segment[order].left >= left && segment[order].right <= right) {
        swapBlackWhite(order);
        segment[order].lazy ^= 1;
        return ;
    }
    pushDown(order);
    if (right <= mid) {
        update(order * 2, left, right);
    }
    else if (left > mid) {
        update(order * 2 + 1, left, right);
    }
    else {
        update(order * 2, left, mid);
        update(order * 2 + 1, mid + 1, right);
    }
    pushUp(order);
}
Esempio n. 25
0
//增加下一个地图的步骤
void addNxtStep(struct sokomap *header,struct sokomap **currentTail,struct sokomap *current,struct mappos * boxPos,int boxCount)
{
	
	//计算人所在的列表
	if(current->pos==NULL)
	{
		current->pos = personCanWalkPoint(current);
	}
	getBoxList(current,boxPos);
	//进行循环判断箱子可以移动的方向
	for(int i=0;i < boxCount;i++)
	{
		int x = boxPos[i].x;
		int y = boxPos[i].y;
		//向上推的操作
		if(isCanPushUp(current,x,y))
		{	
			if(isInMappos(current->pos,boxPos[i].x,boxPos[i].y+1))
			{
				struct sokomap * tmpMap = copyMap(current);
				tmpMap ->parent = current;
				pushUp(tmpMap,x,y);
				//判断地图是否已经棍了,没棍的话就加入到尾步
				if(isMapDead(tmpMap,x,y+1,UP))
				{
					freeMap(tmpMap);
				}else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除
				{
					freeMap(tmpMap);
				}else
				{
					(*currentTail)->next = tmpMap;
					*currentTail = tmpMap;
				}
			}
		}
		//向下推的操作
		if(isCanPushDown(current,boxPos[i].x,boxPos[i].y))
		{
			if(isInMappos(current->pos,boxPos[i].x,boxPos[i].y - 1))
			{
				struct sokomap * tmpMap = copyMap(current);
				tmpMap ->parent = current;
				pushDown(tmpMap,x,y);
				//判断地图是否已经棍了,没棍的话加入到尾部
				if(isMapDead(tmpMap,x,y-1,DOWN))
				{
					freeMap(tmpMap);
				}else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除
				{
					freeMap(tmpMap);
				}else
				{
					(*currentTail)->next = tmpMap;
					*currentTail = tmpMap;
				}
			}
		}
		//向左推的操作
		if(isCanPushLeft(current,boxPos[i].x,boxPos[i].y))
		{
			if(isInMappos(current->pos,boxPos[i].x + 1,boxPos[i].y))
			{
				struct sokomap * tmpMap = copyMap(current);
				tmpMap ->parent = current;
				pushLeft(tmpMap,x,y);
				//判断地图是否已经棍了,没棍的话加入到尾部
				if(isMapDead(tmpMap,x - 1,y,LEFT))
				{
					freeMap(tmpMap);
				}else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除
				{
					freeMap(tmpMap);
				}else
				{
					(*currentTail)->next = tmpMap;
					*currentTail = tmpMap;
				}
			}
		}
		//向右推的操作
		if(isCanPushRight(current,boxPos[i].x,boxPos[i].y))
		{
			if(isInMappos(current->pos,boxPos[i].x - 1,boxPos[i].y))
			{
				struct sokomap * tmpMap = copyMap(current);
				tmpMap ->parent = current;
				pushRight(tmpMap,x,y);
				//判断地图是否已经棍了,没棍的话加入到尾部
				if(isMapDead(tmpMap,x + 1,y,RIGHT))
				{
					freeMap(tmpMap);
				}else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除
				{
					freeMap(tmpMap);
				}else
				{
					(*currentTail)->next = tmpMap;
					*currentTail = tmpMap;
				}
			}
		}
	}
}
Esempio n. 26
0
void cs6300::locRegAlloc(std::pair<std::shared_ptr<cs6300::BasicBlock>,
                                   std::shared_ptr<cs6300::BasicBlock>> b)
{
  int count = 0;

  for (auto&& v : allBlocks(b))
    v->initSets();

  // propogate block meta
  bool change;
  do
  {
    change = false;
    for (auto&& v : allBlocks(b))
    {
      if (pushUp(v, v->jumpTo)) change = true;

      if (pushUp(v, v->branchTo)) change = true;
    }
  } while (change);

  std::map<int, RegColorNode*> nodes;
  for (auto&& cur : allBlocks(b))
  {
    auto t = regDeps(cur);
    auto s = std::set<std::set<int>>(t.begin(), t.end());
    for (auto& v : s)
    {
      for (int reg : v)
      {
        for (int nreg : v)
        {
          if (!nodes.count(nreg)) nodes[nreg] = new RegColorNode{-1};
          nodes[reg]->nodes.insert(nodes[nreg]);
        }
      }
    }
  }

  std::map<int, int> regRemap;
  // color nodes
  for (auto& p : nodes)
  {
    if (p.second->color != -1)
    {
      continue; // already colored
    }

    for (int i = START_REGISTER;; i++)
    {
      if (!p.second->cant.count(i))
      {
        p.second->color = i;
        regRemap[p.first] = i;
        // remapping p.first to i
        for (auto& n : p.second->nodes)
        {
          n->cant.insert(i);
        }
        break;
      }
      if (i == END_REGISTER)
      {
        std::cerr << "Too many colors tried" << std::endl;
        break;
      }
    }
  }

  for (auto&& v : allBlocks(b))
  {
    v->remap(regRemap);
  }
}
Esempio n. 27
0
 inline void splay(int x) {
     while(!isRoot(x)) 
         rot(x);
     pushUp(x);
 }