HDU 6183 Color it 线段树
题目链接: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+线段树因为写错了一句话,重现赛现场一直WA,我最后关头直接这样暴力过了。。。
#include <bits/stdc++.h>
using namespace std;
const int maxm = 3000010;
int tot, l[maxm], r[maxm], v[maxm], T[51];
void update(int &x,int L,int R,int pos,int val)
{
if(!x)
{
x = ++tot;
v[x] = val;
}
if(v[x]>val) v[x] = val;
if(L==R)return;
int mid=(L+R)>>1;
if(pos<=mid) update(l[x],L,mid,pos,val);
else update(r[x],mid+1,R,pos,val);
}
int flag;
int X;
int c, d; void query(int x, int L, int R)
{
if(flag||!x) return;
if(c<=L && R<=d)
{
if(v[x]<=X)flag=1;
return;
}
int mid=(L+R)>>1;
if(c<=mid) query(l[x],L,mid);
if(d>mid) query(r[x],mid+1,R);
}
int main()
{
for(int i=0; i<=50; i++)
{
T[i]=0;
}
while(1)
{
int op;
scanf("%d", &op);
if(op==3)return 0;
if(op==0)
{
for(int i=1; i<=tot; i++)l[i]=r[i]=0;
for(int i=0; i<=50; i++)T[i]=0;
tot=0;
}
if(op==1)
{
int x, y, c;
scanf("%d %d %d", &x,&y,&c);
update(T[c], 1, 1000000, y, x);
}
if(op==2)
{
scanf("%d %d %d", &X,&c,&d);
int ans=0;
for(int i=0; i<=50; i++)
{
flag=0;
query(T[i], 1, 1000000);
if(flag) ans++;
}
printf("%d\n",ans);
}
}
return 0;
}
HDU 6183 Color it 线段树的更多相关文章
- HDU - 6183 暴力,线段树动态开点,cdq分治
B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- Count Color poj2777 线段树
Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...
- HDU 6183 Color it(动态开点线段树)
题目原网址:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题目中文翻译: Time Limit: 20000/10000 MS (Java/Others ...
- hdu 6183 Color it (线段树 动态开点)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
- HDU 6183 Color it cdq分治 + 线段树 + 状态压缩
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Pro ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
随机推荐
- Django 2.0 学习(06):Django 视图(进阶)
概述 Django中的特方法,该方法代表了Django的Web页面,并且视图具有特定的模板.以博客应用为例进行说明,在博客应用中应该包含下面的视图: 博客主页:显示最近的一些记录: 详细页面:单个详细 ...
- Springboot @Transactional 事务不回滚
一.异常捕获的原因 这里Exception异常,他又分为运行时异常RuntimeException和非运行时异常 可查的异常(checked exceptions):Exception下除了Runti ...
- [Leetcode] maximun subarray 最大子数组
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- BZOJ1507 [NOI2003]Editor 【splay】
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MB Submit: 4129 Solved: 1660 [Submit][St ...
- 两年Java的面试经验
前言:从过年前就萌生出要跳槽的想法,到过年来公司从3月初提出离职到23号正式离职,上班的时间也出去面试过几家公司,后来总觉的在职找工作总是得请假,便决心离职后找工作.到4月10号找到了一家互联网公司成 ...
- UIViewContentMode的各种效果
UIViewContentMode的各种效果: 首先它是枚举类型的数据,表示为下所示: typedef enum { UIViewContentModeScaleToFill, ...
- Java日期时间实用工具类
Java日期时间实用工具类 1.Date (java.util.Date) Date(); 以当前时间构造一个Date对象 Date(long); 构造函数 ...
- [python]爬站点
#!/usr/bin/python 2 import urllib 3 import urllib2 4 import re 5 import os 6 7 dirs = ['js','img','p ...
- UVA11426
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page ...
- NYOJ 740 DP
“炫舞家“ST 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 ST是一个酷爱炫舞的玩家.TA很喜欢玩QQ炫舞,因此TA也爱屋及乌的喜欢玩跳舞机(Dance Danc ...