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 ...
随机推荐
- 响应式布局(rem布局),使用JS动态设置fontsize
var cw = document.documentElement.clientWidth; if (cw > 1920) { cw = 1920; } document.getElements ...
- hdu 2962 Trucking (最短路径)
Trucking Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- [SP8372-TSUM]Triple Sums
题面在这里 description 某\(B\)姓\(OJ\)权限题 给出\(n\)个正整数\(a[i]\),求\(i<j<k\)且\(S=a[i]+a[j]+a[k]\)的三元组\((i ...
- 自学Python快速入门
1 helloworld#基本语法print("hello") #换行print('1221312\12312312\2312312321312\21312312') ##表示注释 ...
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
最近在做播放器的时候遇到一个问题,在屏幕方向改变之后需要切换播放器全屏/非全屏的时候,在重写了onConfigurationChanged方法并在manifest.xml配置文件中添加 android ...
- 【枚举】 最大子矩阵(I)
题注:最大子矩形问题的解决办法最初由中国国家集训队王知昆前辈整理并发表为论文,在此说明并感谢. Definition 给你一个大矩形,里面有一些障碍点,求一个面积最大的矩形,满足该矩形在大矩形内部且该 ...
- printf函数用法小记
By francis_hao Aug 26,2017 C语言中printf函数是一个比较常用的函数,但是常用并不代表完全了解,本文翻译了printf的man手册,介绍了其全部功能(不包括ma ...
- [codeforces/gym/101350/L]维护“凸包”
题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...
- [mysql][【优化集合】mysql数据库优化集合
三个层面: 1.系统层面 2.mysql配置参数 3.sql语句优化 =========================================================== 一.系统层 ...
- bzoj 2654 tree 二分+kruskal
tree Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 2739 Solved: 1126[Submit][Status][Discuss] Des ...