HDU 6183 Color it
线段树。
假设只有一种颜色,因为每次询问有一个$x$一定是$1$,那么我可以想办法找出每一个$y$最小的$x$是多少,如果最小的都不符合,那么一定不符合,因为更新变成了单点更新,询问是区间询问最小值,搞个线段树即可。有$51$种颜色,可以搞$51$个线段树。
#include <bits/stdc++.h>
using namespace std; const int maxn = 6000000 + 10;
int op;
int root[60];
struct Node {
int val;
int L;
int R;
}s[maxn];
int num; int add() {
num ++;
s[num].val = 2000000;
s[num].L = -1;
s[num].R = -1;
return num;
} void update(int rt, int pos, int val, int l, int r) {
if(l == r) {
s[rt].val = min(s[rt].val, val);
return ;
}
int mid = (l + r) / 2;
if(pos <= mid) {
if(s[rt].L == -1) {
s[rt].L = add();
}
update(s[rt].L, pos, val, l, mid);
} else {
if(s[rt].R == -1) {
s[rt].R = add();
}
update(s[rt].R, pos, val, mid + 1, r);
}
int left = 2000000;
int right = 2000000;
if(s[rt].L != -1) {
left = s[s[rt].L].val;
}
if(s[rt].R != -1) {
right = s[s[rt].R].val;
}
s[rt].val = min(left, right);
} int query(int rt, int L, int R, int l, int r) {
if(L <= l && r <= R) {
return s[rt].val;
}
int mid = (l + r) / 2;
int left = 2000000;
int right = 2000000;
if(L <= mid && s[rt].L != -1) {
left = query(s[rt].L, L, R, l, mid);
}
if(R > mid && s[rt].R != -1) {
right = query(s[rt].R, L, R, mid + 1, r);
}
return min(left, right);
} int main() {
// freopen("D://in.txt", "r", stdin);
while(~scanf("%d", &op)) {
if(op == 0) {
for(int i = 0; i <= 50; i ++) {
root[i] = add();
}
} else if(op == 1) {
int x, y, c;
scanf("%d%d%d", &x, &y, &c);
update(root[c], y, x, 1, 1000000);
} else if(op == 2) {
int x, y1, y2;
scanf("%d%d%d", &x, &y1, &y2);
int ans = 0;
for(int i = 0; i <= 50; i ++) {
if(query(root[i], y1, y2, 1, 1000000) <= x) {
ans ++;
}
}
printf("%d\n", ans);
} else {
break;
}
}
return 0;
}
HDU 6183 Color it的更多相关文章
- HDU 6183 Color it 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...
- 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
Problem Description Do you like painting? Little D doesn't like painting, especially messy color pai ...
- HDU 6183 Color it cdq分治 + 线段树 + 状态压缩
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Pro ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU - 6183:Color it (线段树&动态开点||CDQ分治)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
随机推荐
- tap事件的原理详解
点击事件延迟问题所在: 在移动端中,由于两次触摸是放大操作,,所以当你点击一次的时候,浏览器会等待300ms,看用户是否会进行第二次点击,如果没有的话,才会执行点击事件 为什么要解决: 随着h5游戏, ...
- 你知道吗?Java开发的10位牛人
James Gosling 1983年,Gosling获得了加州大学的计算机科学学士学位.1990年,他获得了卡内基梅隆大学的计算机科学博士学位,师从Bob Sproull.在攻读博士期间,他自己开发 ...
- Spring boot初始
1 创建pom.xml parent:org.springframework.boot 包含启动的依赖 添加依赖,如 spring-boot-starter-web mvn dependency:t ...
- 【CodeForces】913 E. Logical Expression
[题目]E. Logical Expression [题意]令x=11110000(2),y=11001100(2),z=10101010(2),n次询问,每次要求用[与][或][非][括号]构成含至 ...
- 20155117王震宇 2016-2017-2 《Java程序设计》第十周学习总结
教材学习内容总结 Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd) 第22章 网络 {{屏幕快照 2017-04-30 下午8.38.06.pn ...
- 【洛谷 P2900】 [USACO08MAR]土地征用Land Acquisition(斜率优化,单调栈)
题目链接 双倍经验 设\(H\)表示长,\(W\)表示宽. 若\(H_i<H_j\)且\(W_i<W_j\),显然\(i\)对答案没有贡献. 于是把所有点按\(H\)排序,然后依次加入一个 ...
- XML-RPC笔记
1.什么是XML-RPC RPC(Remote Procedure Call)就是相当于提供了一种"远程接口"来供外部系统调用,常用于不同平台.不同架构的系统之间互相调用. XML ...
- Axure RP 授权码
Axure RP 8.1.0.3372Licensee:KoshyKey:wTADPqxn3KChzJxLmUr5jTTitCgsfRkftQQ1yIG9HmK83MYSm7GPxLREGn+Ii6x ...
- Coursera在线学习---第四节.过拟合问题
一.解决过拟合问题方法 1)减少特征数量 --人为筛选 --靠模型筛选 2)正则化(Regularization) 原理:可以降低参数Θ的数量级,使一些Θ值变得非常之小.这样的目的既能保证足够的特征变 ...
- SQLite3 C/C++ 开发接口简介(API函数)
from : http://www.sqlite.com.cn/MySqlite/5/251.Html 1.0 总览 SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的 ...