Count Color poj2777 线段树】的更多相关文章

Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为刷颜色可以看作是区间修改,使用lazy标记区间的颜色种类,下传标记后,当前节点的lazy标记就标记为0,然后使用vis数组来标记颜色(颜色种类很少).剩下的基本就是线段树的模板了. 代码实现 #include<cstdio> #include<cstring> #include<…
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40949   Accepted: 12366 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here…
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40510 Accepted: 12215 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. The…
题目链接:http://poj.org/problem?id=2777 给你一个长为L想线段,向上面染色,颜色不超过30种,一共有O次操作,操作有两种: C a b c 在[a,b]上染上c颜色 P a b 查询[a,b]上所有颜色数. 思路:线段树维护每个线段上颜色种类,用位来存颜色.好题. /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛…
Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42940   Accepted: 13011 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.…
传送门: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…
题目大意:要求完成以下两个操作:1.将一个区间刷上一种颜色2.询问一段区间上有多少种颜色 思路:这两个操作线段树都可以很迅速的完成,具体做法是:线段树上每个节点存这个线段上的颜色数量,由于颜色数很少,因此可以用二进制存颜色,如果二进制的第N位是1,则该区间存在颜色N,因此一个节点等于其两个子节点颜色的或.最后一个问题就是修改操作是对区间修改,因此需要用lazy_tag的思想(虽然这里不完全是),不然一个一个插节点会TLE #include<cstdio> #include<string.…
以下是题目大意: 有水平方向上很多块板子拼成的墙,一开始每一块都被涂成了颜色1,有C和P两个操作,代表的意思是:C X Y Z —— 从X到Y将板子涂成颜色ZP X Y    —— 查询X到Y的板子共有多少种颜色 //有2块板子 两2颜色 4个询问 C P C P 自己AC后上网查阅了许多别人的题解,看很多人用的什么“状态压缩”.“位运算”等等方法.感觉自己不会的知识还有很多.我用的方法是类似于hash的思想,每次将颜色查询时标记,由于这题的数据范围很小,不需要用离散化处理,所以比较好写.下面附…
题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释,  参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/201402/277917.html #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; + ; ]; struct n…
题目链接:http://poj.org/problem?id=2777 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…
又毁三观了.......虽然题目数据有坑:区间[a,b]可能会有a>b的情况,但是我一开始没有考虑它也能过. 此外莫名其妙的TLE #include <iostream> #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <…
题目链接 http://poj.org/problem?id=2777 题意:题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的颜色有几种. 这题区间更新很简单但是查询会发现挺麻烦的,主要是不知道怎么判断一个区间到底有几个不同的数. 由于这道题的T比较小才30,1<<30不超过int型于是可以考虑用状态来表示,1表示color1,10表示color2,100表示color3,以此类推. 然后区间更新时注意父节点的变化…
title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,,, 做了几道染色的问题,,好像渐渐的熟悉的染色问题的大概的解体思路,,,不再像刚开始做的时候那样一脸懵逼,,,只能去翻博客去看别人的思路,,,好歹这次没有看别人博客自己写出来,,,(除了一些细节没考虑到wa的一发,,,,逃 分析与思路 题面 大概的意思就是给一个区间1~n,,,然后最多有30种颜色,…
Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32217   Accepted: 9681 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.…
题目传送门:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45259   Accepted: 13703 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of…
题目传送门 题目大意: 有多次操作.操作0是清空二维平面的点,操作1是往二维平面(x,y)上放一个颜色为c的点,操作2是查询一个贴着y轴的矩形内有几种颜色的点,操作3退出程序. 思路: 由于查询的矩形是贴着y轴的,所以以y轴为线段树节点,建立52颗线段树,然后每个节点都保存这个纵坐标下x的最小值,然后查询. 这样的线段树显然是开不下的,所以我们考虑线段树动态开点,但是发现有50颗,如果按照50*n*logn的查询,还是会TLE,这里需要一个减枝,就是如果一部分区间内已经有一个颜色了,就直接退出所…
Count Color Time Limit: 1000MS Memory Limit: 65536K 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 cen…
潇爷昨天刚刚讲完...感觉得还可以...对着模板打了个模板...还是不喜欢用指针.... 1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec Memory Limit: 162 MB Submit: 10559 Solved: 4258 [Submit][Status][Discuss] Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结…
//Accepted 4768 KB 391 ms //线段树,延时标记的应用 //对于每一段,用一个int表示被着色的情况,change标记该段的颜色是否发生整体的改变,即这一段 //用没用被全部涂成令一种颜色 #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <cmath> #include <algorithm>…
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以对于区间(L, R)我们只要让左端点+1即可按照正常的线段树操作来做. #include<bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 using namespace std; +…
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染色后共有多少不同的色段.注意假如相邻两个线段同色,那么算作一条线段. 线段树区间更新,不需要pushUP操作,因为查询和非叶节点无关.找长线段的时候首先定位最靠左那根,然后判后面是否与前面的线段颜色相等.注意有可能出现两条线段中间没有染色的情况,这时候查询返回一个无关值,这时候重置p即可. #inc…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不会覆盖) 2 x y1 y2 : 在(0, y1)与(x, y2)所围成的矩形里有多少种颜色 3 : 程序结束 解法: 颜色最多51种.我们就建51棵线段树. 每个线段树按y轴建树,每个结点的值是在范围内的最小的x值,这题最关键的就是看到是x轴是查1-x 队友的CDQ+线段树因为写错了一句话,重现赛…
Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42828   Accepted: 12973 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.…
题意: 一个1e6*1e6的棋盘,有两个操作:给(x,y)加上颜色c,或查找(1,y1)到(x,y2)内的颜色种类数量,最多有50种颜色 思路: 建立50颗线段树,对每个颜色的线段树,维护每个y坐标上x的最小值 但是这样会爆内存,于是动态开点即可 动态开点之后T了一发,就改了下查询的函数,只要有满足在矩形的该颜色,就全线return,果然快了好多 代码: #include<iostream> #include<cstdio> #include<algorithm> #i…
Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can s…
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Description Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different…
Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Description Painting some colored segments on a line, some previously painted segments may be covered by some the subseque…
题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at last. Input The firs…
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at last. InputThe first line of each data set contains exactly o…
Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can s…