예제 #1
0
void init()
{
    pad=0;
    for(int i=0;i<(1<<n);i++)
    {
        if(!((i<<1)&i) && !((i>>1)&i))
        {
            s[pad]=i;
            for(int j=i;j>0;j-=lowbit(j)) sum[pad]++;
            pad++;
        }
    }
}
int sum(int end)
{
    int sum=0;
    if(0 == end)
    {
        return 0;
    }
    while(end > 0)
    {
        sum+=in[end];
        end-=lowbit(end);
    }
    return sum;
}
int main()
{
	int i,j,p;
	int m;
	int sum;
	int ans;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		sum=n-1;
		for(i=1;i<=n;i++) 
		{
			scanf("%s %d",s[i],&a[i]);
			flag[i]=lowbit(i);
			flg[i]=1;
		}
		for(i=0;prime[i+1]<=n;i++);
		p=prime[i];
		ans=prime1[i];
		update(m,-1);
		flg[m]=0;
		i=m-1;
		while(--p)
		{
			j=a[m];
			if(j>0) j=((i+j)%sum+sum)%sum;
			else j=((i+j)%sum+sum)%sum+1;
			if(j==0) j=sum;
			m=f(j);
			update(m,-1);
			flg[m]=0;
			i=j-1;
			sum--;
		}
		printf("%s %d\n",s[m],ans);
	}
	return 0;
}
예제 #4
0
void add(int c[MAXN], int x, int d)
{
//	if(x>n||x<1) return;
	for(int t=x;t<=MAXN;t+=lowbit(t))
		c[t]+=d;
}
예제 #5
0
void update(int x, int y, int v) {
    for (v -= a[x][y], a[x++][y++] += v, z = y; x <= n; x += lowbit(x))
        for (y = z; y <= m; b[x - 1][y - 1] += v, y += lowbit(y));
}
 void update(int sta){
     for(int i = sta; i <= bnd; i += lowbit(i)){
         ++ cur_arr[i];
     }
 }
예제 #7
0
	inline int add(int x,dtype t){ 
		if (t == 0) return 0;
		for (;x <= siz;x += lowbit(x)) 
		   C[x] += t;
	}
예제 #8
0
void
PsPaintWindow(
  WindowPtr pWin,
  RegionPtr pRegion,
  int       what)
{
  int       status;
  WindowPtr pRoot;

#define FUNCTION        0
#define FOREGROUND      1
#define TILE            2
#define FILLSTYLE       3
#define ABSX            4
#define ABSY            5
#define CLIPMASK        6
#define SUBWINDOW       7
#define COUNT_BITS      8

  pointer              gcval[7];
  pointer              newValues [COUNT_BITS];

  BITS32               gcmask, index, mask;
  RegionRec            prgnWin;
  DDXPointRec          oldCorner;
  BoxRec               box;
  WindowPtr            pBgWin;
  GCPtr                pGC;
  register int         i;
  register BoxPtr      pbox;
  register ScreenPtr   pScreen = pWin->drawable.pScreen;
  register xRectangle *prect;
  int                  numRects;

  gcmask = 0;

  /*
   * We don't want to paint a window that has no place to put the
   * PS output.
   */
  if( PsGetContextFromWindow(pWin)==(XpContextPtr)NULL ) return;

  if( what==PW_BACKGROUND )
  {
    switch(pWin->backgroundState)
    {
      case None: return;
      case ParentRelative:
        (*pWin->parent->drawable.pScreen->PaintWindowBackground)
          (pWin->parent, pRegion, what);
        return;
      case BackgroundPixel:
        newValues[FOREGROUND] = (pointer)pWin->background.pixel;
        newValues[FILLSTYLE] = (pointer)FillSolid;
        gcmask |= GCForeground | GCFillStyle;
        break;
      case BackgroundPixmap:
        newValues[TILE] = (pointer)pWin->background.pixmap;
        newValues[FILLSTYLE] = (pointer)FillTiled;
        gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
        break;
    }
  }
  else
  {
    if( pWin->borderIsPixel )
    {
      newValues[FOREGROUND] = (pointer)pWin->border.pixel;
      newValues[FILLSTYLE] = (pointer)FillSolid;
      gcmask |= GCForeground | GCFillStyle;
    }
    else
    {
      newValues[TILE] = (pointer)pWin->border.pixmap;
      newValues[FILLSTYLE] = (pointer)FillTiled;
      gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
    }
  }

  prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(pRegion) *
                                         sizeof(xRectangle));
  if( !prect ) return;

  newValues[FUNCTION] = (pointer)GXcopy;
  gcmask |= GCFunction | GCClipMask;

  i = pScreen->myNum;
  pRoot = WindowTable[i];

  pBgWin = pWin;
  if (what == PW_BORDER)
  {
    while( pBgWin->backgroundState==ParentRelative ) pBgWin = pBgWin->parent;
  }

  pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
  if( !pGC )
  {
    DEALLOCATE_LOCAL(prect);
    return;
  }
  /*
   * mash the clip list so we can paint the border by
   * mangling the window in place, pretending it
   * spans the entire screen
   */
  if( what==PW_BORDER )
  {
    prgnWin = pWin->clipList;
    oldCorner.x = pWin->drawable.x;
    oldCorner.y = pWin->drawable.y;
    pWin->drawable.x = pWin->drawable.y = 0;
    box.x1 = 0;
    box.y1 = 0;
    box.x2 = pScreen->width;
    box.y2 = pScreen->height;
    REGION_INIT(pScreen, &pWin->clipList, &box, 1);
    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
    newValues[ABSX] = (pointer)(long)pBgWin->drawable.x;
    newValues[ABSY] = (pointer)(long)pBgWin->drawable.y;
  }
  else
  {
    newValues[ABSX] = (pointer)0;
    newValues[ABSY] = (pointer)0;
  }

/*
 * XXX Backing store is turned off for the PS driver

  if( pWin->backStorage )
    (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
 */

  mask = gcmask;
  gcmask = 0;
  i = 0;
  while( mask )
  {
    index = lowbit (mask);
    mask &= ~index;
    switch(index)
    {
      case GCFunction:
        if( (pointer)(long)pGC->alu!=newValues[FUNCTION] )
        {
          gcmask |= index;
          gcval[i++] = newValues[FUNCTION];
        }
        break;
      case GCTileStipXOrigin:
        if( (pointer)(long)pGC->patOrg.x!=newValues[ABSX] )
        {
          gcmask |= index;
          gcval[i++] = newValues[ABSX];
        }
        break;
      case GCTileStipYOrigin:
        if( (pointer)(long)pGC->patOrg.y!=newValues[ABSY] )
        {
          gcmask |= index;
          gcval[i++] = newValues[ABSY];
        }
        break;
      case GCClipMask:
        if( (pointer)pGC->clientClipType!=(pointer)CT_NONE )
        {
          gcmask |= index;
          gcval[i++] = (pointer)CT_NONE;
        }
        break;
      case GCSubwindowMode:
        if( (pointer)pGC->subWindowMode!=newValues[SUBWINDOW] )
        {
          gcmask |= index;
          gcval[i++] = newValues[SUBWINDOW];
        }
        break;
      case GCTile:
        if( pGC->tileIsPixel || (pointer)pGC->tile.pixmap!=newValues[TILE] )
        {
          gcmask |= index;
          gcval[i++] = newValues[TILE];
        }
        break;
      case GCFillStyle:
        if( (pointer)pGC->fillStyle!=newValues[FILLSTYLE] )
        {
          gcmask |= index;
          gcval[i++] = newValues[FILLSTYLE];
        }
        break;
      case GCForeground:
        if( (pointer)pGC->fgPixel!=newValues[FOREGROUND] )
        {
          gcmask |= index;
          gcval[i++] = newValues[FOREGROUND];
        }
        break;
    }
  }

  if( gcmask ) DoChangeGC(pGC, gcmask, (XID *)gcval, 1);

  if( pWin->drawable.serialNumber!=pGC->serialNumber )
    ValidateGC((DrawablePtr)pWin, pGC);

  numRects = REGION_NUM_RECTS(pRegion);
  pbox = REGION_RECTS(pRegion);
  for( i=numRects ; --i >= 0 ; pbox++,prect++ )
  {
    prect->x = pbox->x1 - pWin->drawable.x;
    prect->y = pbox->y1 - pWin->drawable.y;
    prect->width = pbox->x2 - pbox->x1;
    prect->height = pbox->y2 - pbox->y1;
  }
  prect -= numRects;
  (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect);
  DEALLOCATE_LOCAL(prect);

/*
 * XXX Backing store is turned off for the PS driver

  if( pWin->backStorage )
    (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing);
 */

  if( what==PW_BORDER )
  {
    REGION_UNINIT(pScreen, &pWin->clipList);
    pWin->clipList = prgnWin;
    pWin->drawable.x = oldCorner.x;
    pWin->drawable.y = oldCorner.y;
    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  }
  FreeScratchGC(pGC);
}
예제 #9
0
파일: gc.c 프로젝트: Magister/x11rdp_xorg71
_X_EXPORT int
CopyGC(register GC *pgcSrc, register GC *pgcDst, register BITS32 mask)
{
    register BITS32	index2;
    BITS32		maskQ;
    int 		error = 0;

    if (pgcSrc == pgcDst)
	return Success;
    pgcDst->serialNumber |= GC_CHANGE_SERIAL_BIT;
    pgcDst->stateChanges |= mask;
    maskQ = mask;
    while (mask)
    {
	index2 = (BITS32) lowbit (mask);
	mask &= ~index2;
	switch (index2)
	{
	    case GCFunction:
		pgcDst->alu = pgcSrc->alu;
		break;
	    case GCPlaneMask:
		pgcDst->planemask = pgcSrc->planemask;
		break;
	    case GCForeground:
		pgcDst->fgPixel = pgcSrc->fgPixel;
		break;
	    case GCBackground:
		pgcDst->bgPixel = pgcSrc->bgPixel;
		break;
	    case GCLineWidth:
		pgcDst->lineWidth = pgcSrc->lineWidth;
		break;
	    case GCLineStyle:
		pgcDst->lineStyle = pgcSrc->lineStyle;
		break;
	    case GCCapStyle:
		pgcDst->capStyle = pgcSrc->capStyle;
		break;
	    case GCJoinStyle:
		pgcDst->joinStyle = pgcSrc->joinStyle;
		break;
	    case GCFillStyle:
		pgcDst->fillStyle = pgcSrc->fillStyle;
		break;
	    case GCFillRule:
		pgcDst->fillRule = pgcSrc->fillRule;
		break;
	    case GCTile:
		{
		    if (EqualPixUnion(pgcDst->tileIsPixel,
				      pgcDst->tile,
				      pgcSrc->tileIsPixel,
				      pgcSrc->tile))
		    {
			break;
		    }
		    if (!pgcDst->tileIsPixel)
			(* pgcDst->pScreen->DestroyPixmap)(pgcDst->tile.pixmap);
		    pgcDst->tileIsPixel = pgcSrc->tileIsPixel;
		    pgcDst->tile = pgcSrc->tile;
		    if (!pgcDst->tileIsPixel)
		       pgcDst->tile.pixmap->refcnt++;
		    break;
		}
	    case GCStipple:
		{
		    if (pgcDst->stipple == pgcSrc->stipple)
			break;
		    if (pgcDst->stipple)
			(* pgcDst->pScreen->DestroyPixmap)(pgcDst->stipple);
		    pgcDst->stipple = pgcSrc->stipple;
		    if (pgcDst->stipple)
			pgcDst->stipple->refcnt ++;
		    break;
		}
	    case GCTileStipXOrigin:
		pgcDst->patOrg.x = pgcSrc->patOrg.x;
		break;
	    case GCTileStipYOrigin:
		pgcDst->patOrg.y = pgcSrc->patOrg.y;
		break;
	    case GCFont:
		if (pgcDst->font == pgcSrc->font)
		    break;
		if (pgcDst->font)
		    CloseFont(pgcDst->font, (Font)0);
		if ((pgcDst->font = pgcSrc->font) != NullFont)
		    (pgcDst->font)->refcnt++;
		break;
	    case GCSubwindowMode:
		pgcDst->subWindowMode = pgcSrc->subWindowMode;
		break;
	    case GCGraphicsExposures:
		pgcDst->graphicsExposures = pgcSrc->graphicsExposures;
		break;
	    case GCClipXOrigin:
		pgcDst->clipOrg.x = pgcSrc->clipOrg.x;
		break;
	    case GCClipYOrigin:
		pgcDst->clipOrg.y = pgcSrc->clipOrg.y;
		break;
	    case GCClipMask:
		(* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
		break;
	    case GCDashOffset:
		pgcDst->dashOffset = pgcSrc->dashOffset;
		break;
	    case GCDashList:
		if (pgcSrc->dash == DefaultDash)
		{
		    if (pgcDst->dash != DefaultDash)
		    {
			xfree(pgcDst->dash);
			pgcDst->numInDashList = pgcSrc->numInDashList;
			pgcDst->dash = pgcSrc->dash;
		    }
		}
		else
		{
		    unsigned char *dash;
		    unsigned int i;

		    dash = (unsigned char *)xalloc(pgcSrc->numInDashList *
						   sizeof(unsigned char));
		    if (dash)
		    {
			if (pgcDst->dash != DefaultDash)
			    xfree(pgcDst->dash);
			pgcDst->numInDashList = pgcSrc->numInDashList;
			pgcDst->dash = dash;
			for (i=0; i<pgcSrc->numInDashList; i++)
			    dash[i] = pgcSrc->dash[i];
		    }
		    else
			error = BadAlloc;
		}
		break;
	    case GCArcMode:
		pgcDst->arcMode = pgcSrc->arcMode;
		break;
	    default:
		clientErrorValue = maskQ;
		error = BadValue;
		break;
	}
    }
    if (pgcDst->fillStyle == FillTiled && pgcDst->tileIsPixel)
    {
	if (!CreateDefaultTile (pgcDst))
	{
	    pgcDst->fillStyle = FillSolid;
	    error = BadAlloc;
	}
    }
    (*pgcDst->funcs->CopyGC) (pgcSrc, maskQ, pgcDst);
    return error;
}
예제 #10
0
파일: test-233.c 프로젝트: ice1000/OI-codes
// binary-indexed array
void add(int i, int v) {
    if (i <= n) a[i] += v, add(i + lowbit(i), v);
}
예제 #11
0
void update(int x, int d) {
	while (x <= MAX_NUMBER) {
		tree_array[x] += d;
		x += lowbit(x);
	}
}
예제 #12
0
 void update(int i,elem_t v) {
     for (v-=a[i],a[i++]+=v; i<=n; c[i-1]+=v,i+=lowbit(i));
 }
예제 #13
0
 elem_t query(int i) {
     for (ret=0; i; ret+=c[i-1],i^=lowbit(i));
     return ret;
 }
예제 #14
0
int getsum(int n)
{
    int ans=0;
    for (;n;n-=lowbit(n)) ans+=t[n];
    return ans;
}
예제 #15
0
void add(int i,int v)
{
    for (;i<=m;i+=lowbit(i)) t[i]+=v;
}
 int sumup(vector<int> &arr, int sta){
     int res = 0;
     for(int i = sta; i > 0; i -= lowbit(i))
         res += arr[i];
     return res;
 }
예제 #17
0
// 求和 O(logN)
int64 sum(int64 c[], int n, int i) {
	int64 s = 0;
	for (; i > 0; i -= lowbit(i)) s += c[i];
	return s;
}
예제 #18
0
파일: test-233.c 프로젝트: ice1000/OI-codes
int sum(int i) {
    return i ? a[i] + sum(i - lowbit(i)) : 0;
}
예제 #19
0
/* swap in correct PaintWindow* routine.  If we can use a fast output
routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
of it in devPrivates[cfbWindowPrivateIndex].ptr.
*/
Bool
cfbChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
{
    unsigned long index;
    cfbPrivWin *pPrivWin;
    int width;
    WindowPtr	pBgWin;

    pPrivWin = cfbGetWindowPrivate(pWin);

    /*
     * When background state changes from ParentRelative and
     * we had previously rotated the fast border pixmap to match
     * the parent relative origin, rerotate to match window
     */
    if (mask & (CWBackPixmap | CWBackPixel) &&
	pWin->backgroundState != ParentRelative &&
	pPrivWin->fastBorder &&
	(pPrivWin->oldRotate.x != pWin->drawable.x ||
	 pPrivWin->oldRotate.y != pWin->drawable.y))
    {
	cfbXRotatePixmap(pPrivWin->pRotatedBorder,
		      pWin->drawable.x - pPrivWin->oldRotate.x);
	cfbYRotatePixmap(pPrivWin->pRotatedBorder,
		      pWin->drawable.y - pPrivWin->oldRotate.y);
	pPrivWin->oldRotate.x = pWin->drawable.x;
	pPrivWin->oldRotate.y = pWin->drawable.y;
    }
    while(mask)
    {
	index = lowbit (mask);
	mask &= ~index;
	switch(index)
	{
	case CWBackPixmap:
	    if (pWin->backgroundState == None)
	    {
		pPrivWin->fastBackground = FALSE;
	    }
	    else if (pWin->backgroundState == ParentRelative)
	    {
		pPrivWin->fastBackground = FALSE;
		/* Rotate border to match parent origin */
		if (pPrivWin->pRotatedBorder) {
		    for (pBgWin = pWin->parent;
			 pBgWin->backgroundState == ParentRelative;
			 pBgWin = pBgWin->parent);
		    cfbXRotatePixmap(pPrivWin->pRotatedBorder,
				  pBgWin->drawable.x - pPrivWin->oldRotate.x);
		    cfbYRotatePixmap(pPrivWin->pRotatedBorder,
				  pBgWin->drawable.y - pPrivWin->oldRotate.y);
		    pPrivWin->oldRotate.x = pBgWin->drawable.x;
		    pPrivWin->oldRotate.y = pBgWin->drawable.y;
		}
	    }
	    else if (((width = (pWin->background.pixmap->drawable.width * PSZ))
		      <= PGSZ) && !(width & (width - 1)))
	    {
		cfbCopyRotatePixmap(pWin->background.pixmap,
				    &pPrivWin->pRotatedBackground,
				    pWin->drawable.x,
				    pWin->drawable.y);
		if (pPrivWin->pRotatedBackground)
		{
		    pPrivWin->fastBackground = TRUE;
		    pPrivWin->oldRotate.x = pWin->drawable.x;
		    pPrivWin->oldRotate.y = pWin->drawable.y;
		}
		else
		{
		    pPrivWin->fastBackground = FALSE;
		}
	    }
	    else
	    {
		pPrivWin->fastBackground = FALSE;
	    }
	    break;

	case CWBackPixel:
	    pPrivWin->fastBackground = FALSE;
	    break;

	case CWBorderPixmap:
	    if (((width = (pWin->border.pixmap->drawable.width * PSZ)) <= PGSZ) &&
		!(width & (width - 1)))
	    {
		for (pBgWin = pWin;
		     pBgWin->backgroundState == ParentRelative;
		     pBgWin = pBgWin->parent);
		cfbCopyRotatePixmap(pWin->border.pixmap,
				    &pPrivWin->pRotatedBorder,
				    pBgWin->drawable.x,
				    pBgWin->drawable.y);
		if (pPrivWin->pRotatedBorder)
		{
		    pPrivWin->fastBorder = TRUE;
		    pPrivWin->oldRotate.x = pBgWin->drawable.x;
		    pPrivWin->oldRotate.y = pBgWin->drawable.y;
		}
		else
		{
		    pPrivWin->fastBorder = FALSE;
		}
	    }
	    else
	    {
		pPrivWin->fastBorder = FALSE;
	    }
	    break;
	 case CWBorderPixel:
	    pPrivWin->fastBorder = FALSE;
	    break;
	}
    }
    return (TRUE);
}
void update(int x,int y,int v)
{
    for (int i=x; i<=N; i+=lowbit(i))
        for (int j=y; j<=N; j+=lowbit(j))
            c[i][j]+=v;
}
예제 #21
0
파일: gc.c 프로젝트: jon-turney/xorg-server
int
ChangeGC(ClientPtr client, GC * pGC, BITS32 mask, ChangeGCValPtr pUnion)
{
    BITS32 index2;
    int error = 0;
    PixmapPtr pPixmap;
    BITS32 maskQ;

    assert(pUnion);
    pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;

    maskQ = mask;               /* save these for when we walk the GCque */
    while (mask && !error) {
        index2 = (BITS32) lowbit(mask);
        mask &= ~index2;
        pGC->stateChanges |= index2;
        switch (index2) {
        case GCFunction:
        {
            CARD8 newalu;
            NEXTVAL(CARD8, newalu);

            if (newalu <= GXset)
                pGC->alu = newalu;
            else {
                if (client)
                    client->errorValue = newalu;
                error = BadValue;
            }
            break;
        }
        case GCPlaneMask:
            NEXTVAL(unsigned long, pGC->planemask);

            break;
        case GCForeground:
            NEXTVAL(unsigned long, pGC->fgPixel);

            /*
             * this is for CreateGC
             */
            if (!pGC->tileIsPixel && !pGC->tile.pixmap) {
                pGC->tileIsPixel = TRUE;
                pGC->tile.pixel = pGC->fgPixel;
            }
            break;
        case GCBackground:
            NEXTVAL(unsigned long, pGC->bgPixel);

            break;
        case GCLineWidth:      /* ??? line width is a CARD16 */
            NEXTVAL(CARD16, pGC->lineWidth);

            break;
        case GCLineStyle:
        {
            unsigned int newlinestyle;
            NEXTVAL(unsigned int, newlinestyle);

            if (newlinestyle <= LineDoubleDash)
                pGC->lineStyle = newlinestyle;
            else {
                if (client)
                    client->errorValue = newlinestyle;
                error = BadValue;
            }
            break;
        }
        case GCCapStyle:
        {
            unsigned int newcapstyle;
            NEXTVAL(unsigned int, newcapstyle);

            if (newcapstyle <= CapProjecting)
                pGC->capStyle = newcapstyle;
            else {
                if (client)
                    client->errorValue = newcapstyle;
                error = BadValue;
            }
            break;
        }
        case GCJoinStyle:
        {
            unsigned int newjoinstyle;
            NEXTVAL(unsigned int, newjoinstyle);

            if (newjoinstyle <= JoinBevel)
                pGC->joinStyle = newjoinstyle;
            else {
                if (client)
                    client->errorValue = newjoinstyle;
                error = BadValue;
            }
            break;
        }
        case GCFillStyle:
        {
            unsigned int newfillstyle;
            NEXTVAL(unsigned int, newfillstyle);

            if (newfillstyle <= FillOpaqueStippled)
                pGC->fillStyle = newfillstyle;
            else {
                if (client)
                    client->errorValue = newfillstyle;
                error = BadValue;
            }
            break;
        }
        case GCFillRule:
        {
            unsigned int newfillrule;
            NEXTVAL(unsigned int, newfillrule);

            if (newfillrule <= WindingRule)
                pGC->fillRule = newfillrule;
            else {
                if (client)
                    client->errorValue = newfillrule;
                error = BadValue;
            }
            break;
        }
        case GCTile:
            NEXT_PTR(PixmapPtr, pPixmap);

            if ((pPixmap->drawable.depth != pGC->depth) ||
                (pPixmap->drawable.pScreen != pGC->pScreen)) {
                error = BadMatch;
            }
            else {
                pPixmap->refcnt++;
                if (!pGC->tileIsPixel)
                    (*pGC->pScreen->DestroyPixmap) (pGC->tile.pixmap);
                pGC->tileIsPixel = FALSE;
                pGC->tile.pixmap = pPixmap;
            }
            break;
        case GCStipple:
            NEXT_PTR(PixmapPtr, pPixmap);

            if (pPixmap && ((pPixmap->drawable.depth != 1) ||
                            (pPixmap->drawable.pScreen != pGC->pScreen)))
            {
                error = BadMatch;
            }
            else {
                if (pPixmap)
                    pPixmap->refcnt++;
                if (pGC->stipple)
                    (*pGC->pScreen->DestroyPixmap) (pGC->stipple);
                pGC->stipple = pPixmap;
            }
            break;
        case GCTileStipXOrigin:
            NEXTVAL(INT16, pGC->patOrg.x);

            break;
        case GCTileStipYOrigin:
            NEXTVAL(INT16, pGC->patOrg.y);

            break;
        case GCFont:
        {
            FontPtr pFont;
            NEXT_PTR(FontPtr, pFont);

            pFont->refcnt++;
            if (pGC->font)
                CloseFont(pGC->font, (Font) 0);
            pGC->font = pFont;
            break;
        }
        case GCSubwindowMode:
        {
            unsigned int newclipmode;
            NEXTVAL(unsigned int, newclipmode);

            if (newclipmode <= IncludeInferiors)
                pGC->subWindowMode = newclipmode;
            else {
                if (client)
                    client->errorValue = newclipmode;
                error = BadValue;
            }
            break;
        }
        case GCGraphicsExposures:
        {
            unsigned int newge;
            NEXTVAL(unsigned int, newge);

            if (newge <= xTrue)
                pGC->graphicsExposures = newge;
            else {
                if (client)
                    client->errorValue = newge;
                error = BadValue;
            }
            break;
        }
        case GCClipXOrigin:
            NEXTVAL(INT16, pGC->clipOrg.x);

            break;
        case GCClipYOrigin:
            NEXTVAL(INT16, pGC->clipOrg.y);

            break;
        case GCClipMask:
            NEXT_PTR(PixmapPtr, pPixmap);

            if (pPixmap) {
                if ((pPixmap->drawable.depth != 1) ||
                    (pPixmap->drawable.pScreen != pGC->pScreen)) {
                    error = BadMatch;
                    break;
                }
                pPixmap->refcnt++;
            }
            (*pGC->funcs->ChangeClip) (pGC, pPixmap ? CT_PIXMAP : CT_NONE,
                                       (void *) pPixmap, 0);
            break;
        case GCDashOffset:
            NEXTVAL(INT16, pGC->dashOffset);

            break;
        case GCDashList:
        {
            CARD8 newdash;
            NEXTVAL(CARD8, newdash);

            if (newdash == 4) {
                if (pGC->dash != DefaultDash) {
                    free(pGC->dash);
                    pGC->numInDashList = 2;
                    pGC->dash = DefaultDash;
                }
            }
            else if (newdash != 0) {
                unsigned char *dash;

                dash = malloc(2 * sizeof(unsigned char));
                if (dash) {
                    if (pGC->dash != DefaultDash)
                        free(pGC->dash);
                    pGC->numInDashList = 2;
                    pGC->dash = dash;
                    dash[0] = newdash;
                    dash[1] = newdash;
                }
                else
                    error = BadAlloc;
            }
            else {
                if (client)
                    client->errorValue = newdash;
                error = BadValue;
            }
            break;
        }
        case GCArcMode:
        {
            unsigned int newarcmode;
            NEXTVAL(unsigned int, newarcmode);

            if (newarcmode <= ArcPieSlice)
                pGC->arcMode = newarcmode;
            else {
                if (client)
                    client->errorValue = newarcmode;
                error = BadValue;
            }
            break;
        }
        default:
            if (client)
                client->errorValue = maskQ;
            error = BadValue;
            break;
        }
    }                           /* end while mask && !error */

    if (pGC->fillStyle == FillTiled && pGC->tileIsPixel) {
        if (!CreateDefaultTile(pGC)) {
            pGC->fillStyle = FillSolid;
            error = BadAlloc;
        }
    }
    (*pGC->funcs->ChangeGC) (pGC, maskQ);
    return error;
}
예제 #22
0
파일: G.cpp 프로젝트: leonyan18/MyCode
int main()
{
    int n, m, l;
    while (scanf("%d%d%d", &n, &m, &l) == 3) {
        std::vector<std::vector<int>> graph(n);
        for (int i = 0, a, b; i < m; ++ i) {
            scanf("%d%d", &a, &b);
            a --, b --;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
        if (l == 1) {
            puts("1");
            continue;
        }
        l --;
        std::vector<std::vector<Info>> dp(1 << l, std::vector<Info>(n, Info { m + 1, 0 })),
            merged(n, std::vector<Info>(1 << l, Info { m + 1, 0 }));
        int root = l;
        for (int i = 0; i < l; ++ i) {
            dp[1 << i][i] = { 0, 1 };
        }
        for (int msk = 0; msk < 1 << l; ++ msk) {
            for (int u = 0; u < n; ++ u) {
                auto& ref = merged.at(u);
                for (int subset = msk; subset > 0; subset = subset - 1 & msk) {
                    if (lowbit(subset) == lowbit(msk)) {
                        update(ref.at(msk), add(dp.at(subset).at(u), ref.at(msk ^ subset)));
                    }
                }
            }
            for (int u = 0; u < n; ++ u) {
                for (int v : graph[u]) {
                    update(dp.at(msk).at(v), add(merged.at(u).at(msk), ONE));
                }
            }
            auto& ref = dp.at(msk);
            PQ<std::pair<int, int>> pq;
            for (int u = 0; u < n; ++ u) {
                pq.emplace(ref.at(u).first, u);
            }
            while (!pq.empty()) {
                auto top = pq.top();
                pq.pop();
                int u = top.second;
                if (top.first == ref.at(u).first) {
                    for (int v : graph.at(u)) {
                        Info todo = add(ref.at(u), ONE);
                        if (todo.first < ref.at(v).first) {
                            pq.emplace(todo.first, v);
                        }
                        update(ref.at(v), todo);
                    }
                }
            }
            for (int u = 0; u < n; ++ u) {
                update(merged.at(u).at(msk), dp.at(msk).at(u));
// fprintf(stderr, "%s %d %d %d\n", std::bitset<3>(msk).to_string().c_str(), u, dp.at(msk).at(u).first, dp.at(msk).at(u).second);
            }
        }
        printf("%d\n", merged.at(root).at((1 << l) - 1).second);
    }
}
예제 #23
0
파일: gc.c 프로젝트: Magister/x11rdp_xorg71
_X_EXPORT int
dixChangeGC(ClientPtr client, register GC *pGC, register BITS32 mask, CARD32 *pC32, ChangeGCValPtr pUnion)
{
    register BITS32 	index2;
    register int 	error = 0;
    PixmapPtr 		pPixmap;
    BITS32		maskQ;

    assert( (pC32 && !pUnion) || (!pC32 && pUnion) );
    pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;

    maskQ = mask;	/* save these for when we walk the GCque */
    while (mask && !error) 
    {
	index2 = (BITS32) lowbit (mask);
	mask &= ~index2;
	pGC->stateChanges |= index2;
	switch (index2)
	{
	    case GCFunction:
	    {
		CARD8 newalu;
		NEXTVAL(CARD8, newalu);
		if (newalu <= GXset)
		    pGC->alu = newalu;
		else
		{
		    clientErrorValue = newalu;
		    error = BadValue;
		}
		break;
	    }
	    case GCPlaneMask:
		NEXTVAL(unsigned long, pGC->planemask);
		break;
	    case GCForeground:
		NEXTVAL(unsigned long, pGC->fgPixel);
		/*
		 * this is for CreateGC
		 */
		if (!pGC->tileIsPixel && !pGC->tile.pixmap)
		{
		    pGC->tileIsPixel = TRUE;
		    pGC->tile.pixel = pGC->fgPixel;
		}
		break;
	    case GCBackground:
		NEXTVAL(unsigned long, pGC->bgPixel);
		break;
	    case GCLineWidth:		/* ??? line width is a CARD16 */
		 NEXTVAL(CARD16, pGC->lineWidth);
		break;
	    case GCLineStyle:
	    {
		unsigned int newlinestyle;
		NEXTVAL(unsigned int, newlinestyle);
		if (newlinestyle <= LineDoubleDash)
		    pGC->lineStyle = newlinestyle;
		else
		{
		    clientErrorValue = newlinestyle;
		    error = BadValue;
		}
		break;
	    }
	    case GCCapStyle:
	    {
		unsigned int newcapstyle;
		NEXTVAL(unsigned int, newcapstyle);
		if (newcapstyle <= CapProjecting)
		    pGC->capStyle = newcapstyle;
		else
		{
		    clientErrorValue = newcapstyle;
		    error = BadValue;
		}
		break;
	    }
	    case GCJoinStyle:
	    {
		unsigned int newjoinstyle;
		NEXTVAL(unsigned int, newjoinstyle);
		if (newjoinstyle <= JoinBevel)
		    pGC->joinStyle = newjoinstyle;
		else
		{
		    clientErrorValue = newjoinstyle;
		    error = BadValue;
		}
		break;
	    }
	    case GCFillStyle:
	    {
		unsigned int newfillstyle;
		NEXTVAL(unsigned int, newfillstyle);
		if (newfillstyle <= FillOpaqueStippled)
		    pGC->fillStyle = newfillstyle;
		else
		{
		    clientErrorValue = newfillstyle;
		    error = BadValue;
		}
		break;
	    }
	    case GCFillRule:
	    {
		unsigned int newfillrule;
		NEXTVAL(unsigned int, newfillrule);
		if (newfillrule <= WindingRule)
		    pGC->fillRule = newfillrule;
		else
		{
		    clientErrorValue = newfillrule;
		    error = BadValue;
		}
		break;
	    }
	    case GCTile:
	    {
		XID newpix = 0;
		if (pUnion)
		{
		    NEXT_PTR(PixmapPtr, pPixmap);
		}
		else
		{
		    NEXTVAL(XID, newpix);
		    pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
					newpix, RT_PIXMAP, SecurityReadAccess);
		}
		if (pPixmap)
		{
		    if ((pPixmap->drawable.depth != pGC->depth) ||
			(pPixmap->drawable.pScreen != pGC->pScreen))
		    {
			error = BadMatch;
		    }
		    else
		    {
			pPixmap->refcnt++;
			if (!pGC->tileIsPixel)
			    (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap);
			pGC->tileIsPixel = FALSE;
			pGC->tile.pixmap = pPixmap;
		    }
		}
		else
		{
		    clientErrorValue = newpix;
		    error = BadPixmap;
		}
		break;
	    }
	    case GCStipple:
	    {
		XID newstipple = 0;
		if (pUnion)
		{
		    NEXT_PTR(PixmapPtr, pPixmap);
		}
		else
		{
		    NEXTVAL(XID, newstipple)
		    pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
				newstipple, RT_PIXMAP, SecurityReadAccess);
		}
		if (pPixmap)
		{
		    if ((pPixmap->drawable.depth != 1) ||
			(pPixmap->drawable.pScreen != pGC->pScreen))
		    {
			error = BadMatch;
		    }
		    else
		    {
			pPixmap->refcnt++;
			if (pGC->stipple)
			    (* pGC->pScreen->DestroyPixmap)(pGC->stipple);
			pGC->stipple = pPixmap;
		    }
		}
		else
		{
		    clientErrorValue = newstipple;
		    error = BadPixmap;
		}
		break;
	    }
	    case GCTileStipXOrigin:
		NEXTVAL(INT16, pGC->patOrg.x);
		break;
	    case GCTileStipYOrigin:
		NEXTVAL(INT16, pGC->patOrg.y);
		break;
	    case GCFont:
    	    {
		FontPtr	pFont;
		XID newfont = 0;
		if (pUnion)
		{
		    NEXT_PTR(FontPtr, pFont);
		}
		else
		{
		    NEXTVAL(XID, newfont)
		    pFont = (FontPtr)SecurityLookupIDByType(client, newfont,
						RT_FONT, SecurityReadAccess);
		}
		if (pFont)
		{
		    pFont->refcnt++;
		    if (pGC->font)
    		        CloseFont(pGC->font, (Font)0);
		    pGC->font = pFont;
		 }
		else
		{
		    clientErrorValue = newfont;
		    error = BadFont;
		}
		break;
	    }
	    case GCSubwindowMode:
	    {
		unsigned int newclipmode;
		NEXTVAL(unsigned int, newclipmode);
		if (newclipmode <= IncludeInferiors)
		    pGC->subWindowMode = newclipmode;
		else
		{
		    clientErrorValue = newclipmode;
		    error = BadValue;
		}
		break;
	    }
	    case GCGraphicsExposures:
    	    {
		unsigned int newge;
		NEXTVAL(unsigned int, newge);
		if (newge <= xTrue)
		    pGC->graphicsExposures = newge;
		else
		{
		    clientErrorValue = newge;
		    error = BadValue;
		}
		break;
	    }
	    case GCClipXOrigin:
		NEXTVAL(INT16, pGC->clipOrg.x);
		break;
	    case GCClipYOrigin:
		NEXTVAL(INT16, pGC->clipOrg.y);
		break;
	    case GCClipMask:
	    {
		Pixmap pid = 0;
		int    clipType = 0;

		if (pUnion)
		{
		    NEXT_PTR(PixmapPtr, pPixmap);
		}
		else
		{
		    NEXTVAL(Pixmap, pid)
		    if (pid == None)
		    {
			clipType = CT_NONE;
			pPixmap = NullPixmap;
		    }
		    else
		        pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
					pid, RT_PIXMAP, SecurityReadAccess);
		}

		if (pPixmap)
		{
		    if ((pPixmap->drawable.depth != 1) ||
			(pPixmap->drawable.pScreen != pGC->pScreen))
		    {
			error = BadMatch;
		    }
		    else
		    {
			clipType = CT_PIXMAP;
			pPixmap->refcnt++;
		    }
		}
		else if (!pUnion && (pid != None))
		{
		    clientErrorValue = pid;
		    error = BadPixmap;
		}
		if(error == Success)
		{
		    (*pGC->funcs->ChangeClip)(pGC, clipType,
					      (pointer)pPixmap, 0);
		}
		break;
	    }
	    case GCDashOffset:
		NEXTVAL(INT16, pGC->dashOffset);
		break;
	    case GCDashList:
	    {
		CARD8 newdash;
		NEXTVAL(CARD8, newdash);
		if (newdash == 4)
		{
		    if (pGC->dash != DefaultDash)
		    {
			xfree(pGC->dash);
			pGC->numInDashList = 2;
			pGC->dash = DefaultDash;
		    }
		}
		else if (newdash != 0)
 		{
		    unsigned char *dash;

		    dash = (unsigned char *)xalloc(2 * sizeof(unsigned char));
		    if (dash)
		    {
			if (pGC->dash != DefaultDash)
			    xfree(pGC->dash);
			pGC->numInDashList = 2;
			pGC->dash = dash;
			dash[0] = newdash;
			dash[1] = newdash;
		    }
		    else
			error = BadAlloc;
		}
 		else
		{
		   clientErrorValue = newdash;
		   error = BadValue;
		}
		break;
	    }
	    case GCArcMode:
	    {
		unsigned int newarcmode;
		NEXTVAL(unsigned int, newarcmode);
		if (newarcmode <= ArcPieSlice)
		    pGC->arcMode = newarcmode;
		else
		{
		    clientErrorValue = newarcmode;
		    error = BadValue;
		}
		break;
	    }
	    default:
		clientErrorValue = maskQ;
		error = BadValue;
		break;
	}
    } /* end while mask && !error */

    if (pGC->fillStyle == FillTiled && pGC->tileIsPixel)
    {
	if (!CreateDefaultTile (pGC))
	{
	    pGC->fillStyle = FillSolid;
	    error = BadAlloc;
	}
    }
    (*pGC->funcs->ChangeGC)(pGC, maskQ);
    return error;
}
예제 #24
0
void add (int p, int x, int y){
    for (; x <= mx; x += lowbit(x)) c[p][x] += y;
}
예제 #25
0
void add(int x,int value)
{
    int i;
    for (i=x;i<=MaxN;i+=lowbit(i)) tree[i]+=value;
}
예제 #26
0
// 修改, O(logN)
void add(int64 c[], int n, int i, int64 v) {
	for (; i <= n; i += lowbit(i)) c[i] += v;
}
예제 #27
0
 void add(int x, int val) {  
     while (x <= n) {  
         sum_array[x] += val;  
         x += lowbit(x);  
     }  
 }  
예제 #28
0
int sum(int x)
{
    int i,res=0;
    for (i=x;i;i-=lowbit(i)) res+=tree[i];
    return res;
}
예제 #29
0
int query (int p, int x){
    int ret = 0;
    for (; x; x -= lowbit(x)) ret += c[p][x];
    return ret;
}
예제 #30
0
파일: 2.cpp 프로젝트: Fengdalu/ICPC
 void push(int x, int w) {
     while(x < N) {
         _[x] += w;
         x += lowbit(x);
     }
 }