void rotate(int x, int k) { pushdown(x); pushdown(c[x][k]); int y = c[x][k]; c[x][k] = c[y][k ^ 1]; c[y][k ^ 1] = x; if (f[x] != -1) c[f[x]][c[f[x]][1] == x] = y; f[y] = f[x]; f[x] = y; f[c[x][k]] = x; std::swap(p[x], p[y]); update(x); update(y); }
/* * 23Sep2006, Maiko, A beacon function of sorts, transmit a * pactor FEC message to let users know of our presence. */ void dxp_FEC (int dev, int pactor) { char tmp[AXBUF], *data, *mycallp; struct mbuf *bp; log (-1, "dxp_FEC - send beacon"); /* * Select P-MODE FEC transmit */ bp = pushdown (NULLBUF, 4); data = bp->data; *data++ = 0x80; *data++ = 0x1c; *data++ = 0x80; *data++ = 0x00; asy_send (dev, bp); j2pause (1000); /* give it time */ /* * Create beacon content, then request normal disconnect */ mycallp = pax25 (tmp, Bbscall); bp = pushdown (NULLBUF, 3 * strlen (mycallp) + 4); data = bp->data; data += sprintf (data, "%s %s %s", mycallp, mycallp, mycallp); *data++ = 0x80; *data++ = 0x07; asy_send (dev, bp); #ifdef DONT_COMPILE j2pause (5000); /* give it time */ /* * Make sure we're back in P-Mode standby */ bp = pushdown (NULLBUF, 2); data = bp->data; *data++ = 0x80; *data++ = 0x83; asy_send (dev, bp); #endif }
//对排序的函数实现 void sort(int n,int A[]) { int i; for(i=n/2;i>=1;i--) { pushdown(i,n,A); } for(i=n;i>=2;i--) { swap(&A[1],&A[i]); pushdown(1,i-1,A); } }
void add(int p,int l,int r,int gl,int gr,int v) { if(gl==l && gr==r) { if(h[v]>val[p]) val[p]=v; if(l!=r) pushdown(p); return; } pushdown(p); int mid=(l+r)/2; if(gr<=mid) add(p*2,l,mid,gl,gr,v); else if(gl>mid) add(p*2+1,mid+1,r,gl,gr,v); else add(p*2,l,mid,gl,mid,v),add(p*2+1,mid+1,r,mid+1,gr,v); }
/* Decrement the IP TTL field in each packet on the send queue. If * a TTL goes to zero, discard the packet. */ void ttldec( struct iface *ifp ){ struct mbuf *bp,*bpprev,*bpnext; struct qhdr qhdr; struct ip ip; bpprev = NULL; for(bp = ifp->outq; bp != NULL;bpprev = bp,bp = bpnext){ bpnext = bp->anext; pullup(&bp,&qhdr,sizeof(qhdr)); ntohip(&ip,&bp); if(--ip.ttl == 0){ /* Drop packet */ icmp_output(&ip,bp,ICMP_TIME_EXCEED,0,NULL); if(bpprev == NULL) /* First on queue */ ifp->outq = bpnext; else bpprev->anext = bpnext; free_p(&bp); bp = bpprev; continue; } /* Put IP and queue headers back, restore to queue */ htonip(&ip,&bp,0); pushdown(&bp,&qhdr,sizeof(qhdr)); if(bpprev == NULL) /* First on queue */ ifp->outq = bp; else bpprev->anext = bp; bp->anext = bpnext; } }
int removeMin(struct Heap *heap) { int mn = heap->A[1]; heap->A[1] = heap->A[heap->n]; (heap->n)--; pushdown(heap, 1); return mn; }
int query(int rt, int l, int r, int pos) { if (l == r) return node[rt].degree; int mid = (l + r) >> 1; pushdown(rt, l, r); if (pos <= mid) return query(lson, pos); else return query(rson, pos); }
int query(int x,int y) { pushdown(); if(x>=r || y<l) return 0; if(l>=x && r-1<=y) return sum; return (pl->query(x,y)+pr->query(x,y))%MOD; }
void bvh_done<SVBVHTree>(SVBVHTree *obj) { rtbuild_done(obj->builder, &obj->rayobj.control); //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE); BLI_memarena_use_malloc(arena1); MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE); BLI_memarena_use_malloc(arena2); BLI_memarena_use_align(arena2, 16); //Build and optimize the tree if(0) { VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder); if(RE_rayobjectcontrol_test_break(&obj->rayobj.control)) { BLI_memarena_free(arena1); BLI_memarena_free(arena2); return; } reorganize(root); remove_useless(root, &root); bvh_refit(root); pushup(root); pushdown(root); pushup_simd<VBVHNode,4>(root); obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root); } else { //Finds the optimal packing of this tree using a given cost model //TODO this uses quite a lot of memory, find ways to reduce memory usage during building OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder); if(RE_rayobjectcontrol_test_break(&obj->rayobj.control)) { BLI_memarena_free(arena1); BLI_memarena_free(arena2); return; } VBVH_optimalPackSIMD<OVBVHNode,PackCost>(PackCost()).transform(root); obj->root = Reorganize_SVBVH<OVBVHNode>(arena2).transform(root); } //Free data BLI_memarena_free(arena1); obj->node_arena = arena2; obj->cost = 1.0; rtbuild_free( obj->builder ); obj->builder = NULL; }
//单点查询 int query(int i, int x) { if (tree[i].l == x && tree[i].r == x) return tree[i].sum; pushdown(i); if (x <= tree[L(i)].r) return query(L(i), x); else return query(R(i), x); }
void splay(int x, int s = -1) { pushdown(x); while (f[x] != s) { if (f[f[x]] != s) rotate(f[f[x]], (c[f[f[x]]][1] == f[x]) ^ rev[f[f[x]]]); rotate(f[x], (c[f[x]][1] == x) ^ rev[f[x]]); } update(x); }
long long query(int n, int l, int r, int x, int y) { if (r < x || l > y) return -INF; if (x <= l && r <= y) return tree[n]; pushdown(n); long long left = query(n << 1, l, l + r >> 1, x, y); long long right = query(n << 1 ^ 1, (l + r >> 1) + 1, r, x, y); return std::max(left, right); }
void Node::Splay(Node *goal = null) { pushdown(); for (; f != goal;) { f->f->pushdown(); f->pushdown(); pushdown(); if (f->f == goal) { rotate(); } else if ((f->f->ch[0] == f) ^ (f->ch[0] == this)) { rotate(); rotate(); } else { f->rotate(); rotate(); } } }
int query(int i, int left, int right) { if (tree[i].l == left && tree[i].r == right) return tree[i].sum; pushdown(i); if (right <= tree[L(i)].r) return query(L(i), left, right); if (left >= tree[R(i)].l) return query(R(i), left, right); return query(L(i), left, tree[L(i)].r) + query(R(i), tree[R(i)].l, right); }
int query(int i, int left, int right) { if (left == tree[i].l && right == tree[i].r) return tree[i].max; pushdown(i); if (right <= tree[L(i)].r) return query(L(i), left, right); if (left >= tree[R(i)].l) return query(R(i), left, right); return max(query(L(i), left, tree[L(i)]), query(R(i), tree[R(i)].l, right)); }
void access(int x) { int y = 0; while (x != -1) { splay(x); pushdown(x); f[c[x][1]] = -1; p[c[x][1]] = x; c[x][1] = y; f[y] = x; p[y] = -1; update(x); x = p[y = x]; } }
int query(int p,int l,int r,int gp) { if(l==r && l==gp) return val[p]; pushdown(p); int mid=(l+r)/2; if(gp<=mid) return query(p*2,l,mid,gp); else return query(p*2+1,mid+1,r,gp); }
/* Convert a host-format AX.25 header into a mbuf ready for transmission */ void htonax25( struct ax25 *hdr, struct mbuf **bpp ){ register uint8 *cp; register uint16 i; if(hdr == (struct ax25 *)NULL || hdr->ndigis > MAXDIGIS || bpp == NULL) return; /* Allocate space for return buffer */ i = AXALEN * (2 + hdr->ndigis); pushdown(bpp,NULL,i); /* Now convert */ cp = (*bpp)->data; /* cp -> dest field */ /* Generate destination field */ memcpy(cp,hdr->dest,AXALEN); if(hdr->cmdrsp == LAPB_COMMAND) cp[ALEN] |= C; /* Command frame sets C bit in dest */ else cp[ALEN] &= ~C; cp[ALEN] &= ~E; /* Dest E-bit is always off */ cp += AXALEN; /* cp -> source field */ /* Generate source field */ memcpy(cp,hdr->source,AXALEN); if(hdr->cmdrsp == LAPB_RESPONSE) cp[ALEN] |= C; else cp[ALEN] &= ~C; /* Set E bit on source address if no digis */ if(hdr->ndigis == 0){ cp[ALEN] |= E; return; } cp += AXALEN; /* cp -> first digi field */ /* All but last digi get copied with E bit off */ for(i=0; i < hdr->ndigis; i++){ memcpy(cp,hdr->digis[i],AXALEN); if(i < hdr->ndigis - 1) cp[ALEN] &= ~E; else cp[ALEN] |= E; /* Last digipeater has E bit set */ if(i < hdr->nextdigi) cp[ALEN] |= REPEATED; else cp[ALEN] &= ~REPEATED; cp += AXALEN; /* cp -> next digi field */ } }
LL query(int l,int r,lrrt) { if(l <= L && r >= R) return tree[rt].sum; imid; pushdown(mid,L,R,rt); LL ans = 0; if(mid >= l) ans += query(l,r,lson); if(mid < r) ans += query(l,r,rson); return ans; }
long long find(int n, int l, int r, int fl, int fr) { if (fl <= l && r <= fr) return Tr[n]; pushdown(n, l, r); long long ans = 0; if (fl <= lm) ans += find(lson, l, lm, fl, fr); if (fr >= rm) ans += find(rson, rm, r, fl, fr); return ans; }
void inc (int l, int r, int t) { for (l += M - 1, r += M + 1, pushdown (l), pushdown (r); l ^ r ^ 1; l >>= 1, r >>= 1) { if (~l & 1) { //if ((tag[l ^ 1] += t) > tagmax[l ^ 1]) tagmax[l ^ 1] = tag[l ^ 1]; if ((curmax[l ^ 1] += t) > pasmax[l ^ 1]) pasmax[l ^ 1] = curmax[l ^ 1]; for (int i = (l ^ 1) >> 1; i; i >>= 1) if ((curmax[i] += t) > pasmax[i]) pasmax[i] = curmax[i]; } if ( r & 1) { //if ((tag[r ^ 1] += t) > tagmax[r ^ 1]) tagmax[r ^ 1] = tag[r ^ 1]; if ((curmax[r ^ 1] += t) > pasmax[r ^ 1]) pasmax[r ^ 1] = curmax[r ^ 1]; for (int i = (r ^ 1) >> 1; i; i >>= 1) if ((curmax[i] += t) > pasmax[i]) pasmax[i] = curmax[i]; } } }
void modify(int n, int l, int r, int x, int y, int d) { if (r < x || l > y) return; if (x <= l && r <= y) { makedelta(n, d); return; } pushdown(n); modify(n << 1, l, l + r >> 1, x, y, d); modify(n << 1 ^ 1, (l + r >> 1) + 1, r, x, y, d); tree[n] = std::max(tree[n << 1], tree[n << 1 ^ 1]); }
int query(int id,int ll,int rr) { int l=no[id].l,r=no[id].r,mid=(l+r)>>1; if(l>=ll&&r<=rr) return no[id].s; pushdown(id,l,r); int ret=0; if(mid>=ll&&l<=rr) ret+=query(L(id),ll,rr); if(mid<rr&&r>=ll) ret+=query(R(id),ll,rr); return mid; }
void set_update(int o,int L,int R){ int lc=o*2,rc=o*2+1; if(y1<=L && y2>=R){ setv[o]=v; }else{ pushdown(o); int M=L+(R-L)/2; if(y1<=M) set_update(lc,L,M);else maintain(lc,L,M); if(y2>M) set_update(rc,M+1,R);else maintain(rc,M+1,R); } maintain(o,L,R); }
int query(int i,int l,int r) { if(l==r) { int rt=IDX(l,r); return tree[rt]; } int mid=l+r>>1; pushdown(l,r); if(i<=mid) return query(i,l,mid); return query(i,mid+1,r); }
/* Send raw data packet on KISS TNC */ int kiss_raw( struct iface *iface, struct mbuf **bpp ){ /* Put type field for KISS TNC on front */ pushdown(bpp,NULL,1); (*bpp)->data[0] = PARAM_DATA; /* slip_raw also increments sndrawcnt */ slip_raw(iface,bpp); return 0; }
void cover(int &rt, int l, int r, int x, int y) { if (r < x || l > y) return; alloc(rt); if (x <= l && r <= y) { makesame(rt, l, r); return; } pushdown(rt, l, r); cover(t[rt].l, l, l + r >> 1, x, y); cover(t[rt].r, (l + r >> 1) + 1, r, x, y); t[rt].d = t[t[rt].l].d + t[t[rt].r].d; }
int query(int L,int R, father) { if(l >= L && r <= R) return r-l+1 - sum[rt]; calm; pushdown(l,r,rt); int ans = 0; if(m >= L) ans += query(L,R,lson); if(m+1 <= R) ans += query(L,R,rson); return ans; }
void update(int l,int r,int num,lrrt) { if(l <= L && R <= r) { tree[rt].sum += (R-L+1) * num; tree[rt].lazy += num; return; } imid; pushdown(mid,L,R,rt); if(mid >= l) update(l,r,num,lson); if(mid < r) update(l,r,num,rson); pushup(rt); }
long long findsum(int pl,int pr,int x) { if(pl>=ll&&pr<=rr)return(sum[x]); else { int m=(pl+pr)/2;long long ans=0; if(lazy[x]!=0)pushdown(pl,pr,x); if(ll<=m)ans+=findsum(pl,m,2*x); if(rr>=m+1)ans+=findsum(m+1,pr,2*x+1); return ans; } }