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 ...
随机推荐
- 解决CodeBlocks无法自动补全的问题
在Deepin下安装的CB,输入printf.scanf的时候不会自动补全,这样就很难受. 解决办法是在Setting -> Editor -> Syntax highlighting - ...
- 状压dp Gym - 100676G
http://codeforces.com/gym/100676 题目大意: 给你n个科目,m个关系,例如A->B,表示要学习B科目,一定要把A科目学习掉.同理,如果还有C->B,那么,B ...
- 字符串:KMP
KMP是字符串匹配的经典算法 也是众多字符串基础的重中之重 A. 题意:给T组数据,每组有长度为n和m的母串和模式串.判断模式串是否是母串的子串,如果是输出最先匹配完成的位置,否则输出-1. 做法:直 ...
- 将oh-my-zsh编程真正的my zsh
环境: Ubuntu 32位 oh-my-zsh安装: 1.安装zsh: sudo apt-get install zsh 2.将当前用户的shell环境修改为zsh: chsh -s /bin/z ...
- Centos7环境下消息队列之ActiveMQ实战
Activemq介绍 对于消息的传递有两种类型: 一种是点对点的,即一个生产者和一个消费者一一对应: 另一种是发布/订阅模式,即一个生产者产生消息并进行发送后,可以由多个消费者进行接收. JMS定义了 ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- JavaScript:自动生成博文目录导航
感谢 孤傲苍狼 分享了 自动生成博文目录的方法,本文仅作存档使用. 图 1:效果预览 CSS 样式 #TOCbar{ font-size:12px; text-align:left; position ...
- Price(洛谷P4109 [HEOI2015]定价)
题目 思路: 按照我的思路这一题应该是这样子的 剔除+判断 剔除 因为后面的0要越多越好,所以我们判断0出现的情况,当2个数之间的差大与10时,证明2个之间会存在一个0,所以这一位我们可以把它去掉,相 ...
- Redis数据类型之散列(hash)
1. 什么是散列 散列类似于一个字典,是一个<K, V>对的集合,不过这个key和value都只能是字符串类型的,不能嵌套,可以看做Java中的Map<String, String& ...
- Ajax请求数据与删除数据后刷新页面
1.ajax异步请求数据后填入模态框 请求数据的按钮(HTML) <a class="queryA" href="javascript:void(0)" ...