Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

来晒代码

Posted by gnaggnoyil at 2010-01-22 17:08:25 on Problem 2777
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define maxn 100005
#define maxl 100005
#define maxc 31
#define maxlongint ((1<<31)-1)
struct treenode{
  int l,r,lch,rch,col;
}tree[maxn+maxn+maxn];
int n,m,t,s,tot=0,u,v,w;
int buildtree(int a,int b){
  int now=++tot;
  tree[now].l=a,tree[now].r=b,tree[now].col=1;
  if(a+1<b){
    tree[now].lch=tot+1,buildtree(a,((a+b)>>1));
    tree[now].rch=tot+1,buildtree(((a+b)>>1),b);
  }
  return 0;
}
int modify(int t,int a,int b,int c){
  if((b<=tree[t].l)||(a>=tree[t].r))
    return 0;
  if((a<=tree[t].l)&&(b>=tree[t].r))
    return tree[t].col=c,0;
  if(tree[t].col==c)
    return 0;
  if(((tree[t].col)&(tree[t].col-1))==0)
    tree[tree[t].lch].col=tree[tree[t].rch].col=tree[t].col;
  if(a<=tree[tree[t].lch].r)
    modify(tree[t].lch,a,b,c);
  if(b>=tree[tree[t].rch].l)
    modify(tree[t].rch,a,b,c);
  return tree[t].col=(tree[tree[t].lch].col)|(tree[tree[t].rch].col),0;
}
int query(int t,int a,int b){
  if((b<=tree[t].l)||(a>=tree[t].r))
    return 0;
  if(((a<=tree[t].l)&&(b>=tree[t].r))||(((tree[t].col)&(tree[t].col-1))==0))
    return tree[t].col;
  int ans=0;
  if(a<=tree[tree[t].lch].r)
    ans=query(tree[t].lch,a,b);
  if(b>=tree[tree[t].rch].l)
    ans=(ans)|(query(tree[t].rch,a,b));
  return ans;
}
int main(){
  scanf("%d%d%d\n",&n,&t,&m);
  buildtree(0,n);
  for(char ch;m>0;m--){
    scanf("%c ",&ch);
    if(ch=='C'){
      scanf("%d%d%d\n",&u,&v,&w);
      if(u>v)
        u=u^v,v=u^v,u=u^v;
      modify(1,u-1,v,(1<<(w-1)));
    }
    if(ch=='P'){
      scanf("%d%d\n",&u,&v);
      w=query(1,u-1,v);
      for(s=0;w>0;w/=2)
        s+=(w&1);
      printf("%d\n",s);
    }
  }
  return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator