# poj2777 Count Color

Description

Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem.

There is a very long board with length L centimeter, L is a positive integer, so we can evenly divide the board into L segments, and they are labeled by 1, 2, ... L from left to right, each is 1 centimeter long. Now we have to color the board - one segment with only one color. We can do following two operations on the board:

1. "C A B C" Color the board from segment A to segment B with color C.
2. "P A B" Output the number of different colors painted between segment A and segment B (including).

In our daily life, we have very few words to describe a color (red, green, blue, yellow…), so you may assume that the total number of different colors T is very small. To make it simple, we express the names of colors as color 1, color 2, ... color T. At the beginning, the board was painted in color 1. Now the rest of problem is left to your.

Input

First line of input contains L (1 <= L <= 100000), T (1 <= T <= 30) and O (1 <= O <= 100000). Here O denotes the number of operations. Following O lines, each contains "C A B C" or "P A B" (here A, B, C are integers, and A may be larger than B) as an operation defined previously.

Output

Ouput results of the output operation in order, each line contains a number.

with tree[p] do
begin
if (l=b) and (r=e) then
begin
color:=1 shl (c-1);
cover:=true;
exit;
end;
if cover then
begin
cover:=false;
tree[p*2].cover:=true;
tree[p*2].color:=color;
tree[p*2+1].cover:=true;
tree[p*2+1].color:=color;
end;
m:=(l+r) div 2;
if e<=m then ins(p*2,b,e,c) else
if b>m then ins(p*2+1,b,e,c) else
begin
ins(p*2,b,m,c);
ins(p*2+1,m+1,e,c);
end;
color:=tree[p*2].color or tree[p*2+1].color;
end;

• 本文已收录于以下专栏：

## poj2777--Count Color(线段树，二进制转化)

Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34950   A...
• u013015642
• 2014年08月04日 21:48
• 947

## poj2777Count Color（线段树）

Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40404   A...
• d_x_d
• 2015年12月20日 17:52
• 2079

## 【poj2777】Count Color

• zhaoyh2000
• 2017年02月27日 21:45
• 98

## POJ2777 Count Color

Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34022   ...
• eeeaaaaa
• 2014年06月22日 09:35
• 273

## poj2777:Count Color

• ZMOIYNLP
• 2015年02月15日 21:15
• 339

## poj2777 Count Color（成段更新）

http://poj.org/problem?id=2777 题意：给你一个长板，宽度为l，t种颜色，o项操作。操作共两种，更新一个区间内的颜色，求一个区间内的颜色数量，输出。 思路：...
• Flynn_curry
• 2016年05月09日 21:18
• 122

## poj2777——Count Color

• k1246195917
• 2010年10月27日 22:17
• 380

## Count Color[poj2777]

• hccz95
• 2011年03月26日 08:35
• 597

## POJ2777 Count Color（线段树）

• qq_21057881
• 2016年04月13日 21:55
• 142

## POJ2777 Count Color 线段树

• wuyanyi
• 2011年12月01日 23:17
• 2629

举报原因： 您举报文章：poj2777 Count Color 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)