POJ 2777 Count Color (线段树)
来源:互联网 发布:淘宝发布宝贝图片变形 编辑:程序博客网 时间:2024/06/05 23:59
题目点我点我点我
题目大意:给一个固定长度为L的画板
有两个操作:
C A B C:区间AB内涂上颜色C。
P A B:查询区间AB内颜色种类数。
解题思路:线段树,用位操作记录颜色种类。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <bitset>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)#define pb push_back#define mp make_pairconst int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define LL long long#define ULL unsigned long long#define MS0(X) memset((X), 0, sizeof((X)))#define SelfType intSelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}#define Sd(X) int (X); scanf("%d", &X)#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())#define all(a) a.begin(), a.end()typedef pair<int, int> pii;typedef pair<long long, long long> pll;typedef vector<int> vi;typedef vector<long long> vll;inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")const int N = 1e5 + 5;struct node{ int col; int sum;}seg[N*4];void build(){ seg[1].sum = seg[1].col = 1;}void pushdown(int x,int l,int r){ seg[x<<1].col = seg[x<<1|1].col = seg[x].col; seg[x<<1].sum = seg[x<<1|1].sum = 1<<(seg[x].col-1); seg[x].col = -1;}void pushuup(int x,int l,int r){ seg[x].sum = seg[x<<1].sum | seg[x<<1|1].sum;}void update(int x,int l,int r,int L,int R,int c){ if(L<=l && r<=R) { seg[x].sum = 1<<(c-1); seg[x].col = c; return; } if(seg[x].col!=-1)pushdown(x,l,r); int mid = (l+r) >> 1; if(L<=mid) update(x<<1,l,mid,L,R,c); if(R>mid) update(x<<1|1,mid+1,r,L,R,c); pushuup(x,l,r);}int query(int x,int l,int r,int L,int R){ if(L<=l && r<=R) { return seg[x].sum; } if(seg[x].col!=-1)pushdown(x,l,r); int mid = (l+r) >> 1; int res = 0; if(L<=mid) res |= query(x<<1,l,mid,L,R); if(R>mid) res |= query(x<<1|1,mid+1,r,L,R); return res;}char s[5];int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);ios::sync_with_stdio(0);cin.tie(0);int L,T,O; scanf("%d%d%d",&L,&T,&O); build(); while(O--) { int a,b,c; scanf("%s%d%d",s,&a,&b); if(a>b)swap(a,b); if(s[0]=='C') { scanf("%d",&c); update(1,1,L,a,b,c); } else { int temp = query(1,1,L,a,b); int ans = 0; while(temp) { if(temp&1)ans++; temp >>= 1; } printf("%d\n",ans); } }return 0;}
0 0
- poj 2777 -- Count Color ( 线段树 )
- poj - 2777 - Count Color(线段树)
- POJ 2777 Count Color(线段树)
- poj 2777 Count Color(线段树)
- POJ 2777--Count Color(线段树)
- POJ 2777 Count Color(线段树)
- POJ 2777 Count Color(线段树 )
- POJ 2777 Count Color(线段树)
- POJ 2777 Count Color (线段树)
- [POJ 2777]Count Color(线段树)
- POJ 2777 Count Color(线段树)
- POJ 2777-Count Color-(线段树)
- POJ 2777 Count Color 线段树
- POJ 2777 Count Color 线段树
- POJ 2777 Count Color(线段树#1)
- POJ 2777 Count Color (线段树)
- POJ 2777 Count Color 线段树
- POJ 2777 Count Color 线段树
- Android Studio 将引用第三方jar包的android工程打包成jar包
- 2、从键盘上输入两个整数,由用户回答它们的和,差,积,商和取余运算结果,并统计出正确答案的个数。
- servlet中的监听器
- Codeforces Round #228 (Div. 2) A - Fox and Number Game(水题)
- 解方程(按位或)
- POJ 2777 Count Color (线段树)
- Linux TCP网络编程
- Codeforces Round #228 (Div. 2) B Fox and Cross(DFS)
- WaitForMultipleObjects用法详解,一看就懂
- Java线程:线程的调度-守护线程
- Codeforces Round #228 (Div. 2) C Fox and Box Accumulation(贪心)
- 辰辰的成长记录
- MyBatis学习总结[5]-动态 SQL
- Java中ArrayList和LinkedList区别