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;
    }
    

      

  • 相关阅读:
    [译]Node.js Interview Questions and Answers (2017 Edition)
    XUnit
    Inline Route Constraints in ASP.NET Core MVC
    [译]Object.getPrototypeOf
    [译]IIS 8.0应用初始化
    C++的那些事:你真的了解引用吗
    C++的那些事:表达式与语句
    C++的那些事:数据与类型
    神经网络:卷积神经网络
    图像分析:投影曲线的波峰查找
  • 原文地址:https://www.cnblogs.com/starve/p/10821278.html
Copyright © 2011-2022 走看看