博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Count Color
阅读量:7112 次
发布时间:2019-06-28

本文共 2320 字,大约阅读时间需要 7 分钟。

Count Color
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 43773   Accepted: 13249

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.

Sample Input

2 2 4C 1 1 2P 1 2C 2 2 2P 1 2

Sample Output

21

Source

,dodo
#include
#include
#include
#define N 100005#define lson i*2,l,m#define rson i*2+1,m+1,rusing namespace std;bool visit[31];int color[N*4];int cur;void build(int i,int l,int r){ color[i]=1; if(l==r) return; int m=(l+r)/2; build(lson); build(rson);}void pushdown(int i){ if(color[i]>0) color[i*2]=color[i*2+1]=color[i];}void pushup(int i){ if(color[i*2]==-1||color[i*2+1]==-1) color[i]=-1; else if(color[i*2]==color[i*2+1]) color[i]=color[i*2]; else color[i]=-1;}void update(int ql,int qr,int val,int i,int l,int r){ //cout<<"l="<
<<" r="<
<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6017429.html

你可能感兴趣的文章
CS-231N-斯坦福李飞飞机器视觉课(Cydiachen版笔记+感悟)
查看>>
推荐一个有趣的Chrome扩展程序-查看任意网站的开发技术栈
查看>>
聊聊storm TridentWindowManager的pendingTriggers
查看>>
React 解决fetch跨域请求时session失效
查看>>
翻译_只需20行代码创造JavaScript模板引擎(二)
查看>>
Blockchain和Tangle哪一个是未来?
查看>>
apicloud拉起小程序并传递参数
查看>>
虚拟机Centos6.8安装MYSQL5.7,本地Navicat连接
查看>>
简单聊聊DOM
查看>>
【JavaScript】JavaScript Array 对象(数组)
查看>>
github 上有趣又实用的前端项目(持续更新,欢迎补充)
查看>>
opencv python 直方图均衡化
查看>>
HotFrameLearning 热门框架学习(前言)
查看>>
git团队开发流程
查看>>
【Under-the-hood-ReactJS-Part6】React源码解读
查看>>
深入理解css之vertical-align
查看>>
Laravel事件
查看>>
matlab绘制peano(皮亚诺)曲线和koch(科赫曲线,雪花曲线)分形曲线
查看>>
使用pipenv代替virtualenv管理python包
查看>>
Docker零基础入门指南(四):Docker容器使用
查看>>