zoukankan      html  css  js  c++  java
  • poj2777 Count Color

    不开longlong见祖宗

    题目没说操作中的a,b大小要注意

    接着就是状压+线段树

    http://poj.org/problem?id=2777

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    typedef long long ll;
    const int M=1e5+5;
    ll tree[M<<2],lazy[M<<2];
    int n;
    void up(int root){
    	tree[root]=tree[root<<1]|tree[root<<1|1];
    }
    void pushdown(int root){
    	ll sign=lazy[root];
    	lazy[root<<1]=lazy[root<<1|1]=sign;
    	tree[root<<1]=tree[root<<1|1]=sign;
    	lazy[root]=0ll;
    }
    void build(int root,int l,int r){
    	if(l==r){
    		tree[root]=1ll;
    		return ;
    	}
    	int midd=(l+r)>>1;
    	build(root<<1,l,midd);
    	build(root<<1|1,midd+1,r);
    	up(root);
    }
    void update(int L,int R,int x,int root,int l,int r){
    	if(L<=l&&r<=R){
    		tree[root]=(1<<(x-1))*1ll;
    		lazy[root]=(1<<(x-1))*1ll;
    		return;
    	}
    	if(lazy[root])
    		pushdown(root);
    	int midd=(l+r)>>1;
    	if(L<=midd)
    		update(L,R,x,root<<1,l,midd);
    	if(R>midd)
    		update(L,R,x,root<<1|1,midd+1,r);
    	up(root);
    }
    ll query(int L,int R,int root,int l,int r){
    	if(L<=l&&r<=R){
    		return tree[root];
    	}
    	if(lazy[root])
    		pushdown(root);
    	ll ans=0;
    	int midd=(l+r)>>1;
    	if(L<=midd)
    		ans|=query(L,R,root<<1,l,midd);
    	if(R>midd)
    		ans|=query(L,R,root<<1|1,midd+1,r);
    	up(root);
    	return ans;
    }
    int solve(int l,int r){
    	ll x=query(l,r,1,1,n);
    	int t=0;
    	while(x){
    		if(x&1)
    			t++;
    		x>>=1;
    	}
    	return t;
    }
    char s[2];
    int main(){
    	n;
    	int m,p;
    	scanf("%d%d%d",&n,&m,&p);
    	build(1,1,n);
    	
    	while(p--){
    		scanf("%s",s);
    		if(s[0]=='C'){
    			int x,y,w;
    			if(x>y)
    				swap(x,y);
    			scanf("%d%d%d",&x,&y,&w);
    			update(x,y,w,1,1,n);
    		}
    		else{
    			int x,y;
    			scanf("%d%d",&x,&y);
    			if(x>y)
    				swap(x,y);
    			printf("%d
    ",solve(x,y));
    		}
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    vscode英文显示设置为中文语言
    vscode各插件使用-背景图-scss
    公众号关联小程序
    js点击遮罩空白区域关闭,点击遮罩内元素不关闭
    swiper使用-点击跳转指定页
    小程序内部引导关注公众号实现方法
    jq赋值input值为空
    sass中代码使用
    Sources”参数中指定了多次。“Sources”参数不支持重复项
    将已存在小程序项目添加云开发配置
  • 原文地址:https://www.cnblogs.com/starve/p/10821278.html
Copyright © 2011-2022 走看看