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

发个code

Posted by ACAccepted at 2019-09-29 09:09:04 on Problem 2777
#include <cstdio>
#include <bitset>
#include <iostream>
using namespace std;

template<typename T>
inline T read()
{
	T x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

const int MAXN=100005;
int n,m,t,ans;

namespace stree
{
	int color[MAXN<<2];
	bitset<MAXN<<2> coverd;
	
	inline void push_up(int k)
	{
		color[k]=color[k<<1]|color[k<<1|1];
	}
	
	inline void push_down(int k)
	{
		color[k<<1]=color[k];color[k<<1|1]=color[k];
		coverd.reset(k);coverd.set(k<<1);coverd.set(k<<1|1);
	}
	
	inline void edit_tree(int k,int l,int r,int _l,int _r,int d)
	{
		if (color[k]==d) return ;
		if (_l<=l&&_r>=r) {color[k]=d;coverd.set(k);return ;}
		if (coverd[k]) push_down(k);
		int mid=l+r>>1;
		if (_l<=mid) edit_tree(k<<1,l,mid,_l,_r,d);
		if (_r>mid) edit_tree(k<<1|1,mid+1,r,_l,_r,d);
		push_up(k);
	}
	
	inline void query(int k,int l,int r,int _l,int _r)
	{
		if (_l<=l&&_r>=r) {ans|=color[k];return ;}
		if (coverd[k]) {ans|=color[k];return ;}
		int mid=l+r>>1;
		if (_l<=mid) query(k<<1,l,mid,_l,_r);
		if (_r>mid) query(k<<1|1,mid+1,r,_l,_r);
	}
}

inline int count(int &x)
{
	int w=0;
	for (;x;x-=(x&-x)) w++;
	return w;
}

int main()
{
	char op;
	int a,b,c;
	while (~scanf("%d%d%d",&n,&t,&m))
	{
		stree::edit_tree(1,1,n,1,n,1);
		while (m--)
		{
			cin>>op;
			if (op=='C')
			{
				a=read<int>();b=read<int>();c=read<int>();
				stree::edit_tree(1,1,n,a,b,1<<c-1);
			}
			else 
			{
				a=read<int>();b=read<int>();
				stree::query(1,1,n,a,b);
				printf("%d\n",count(ans));
			}
		}
	}
	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