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 ...
随机推荐
- vue 父子组件相互传递数据
例子一 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta ...
- linux shell学习二
参考:http://www.cnblogs.com/waitig/p/5531463.html Shell注释 Shell中的注释以“#”号开头,所有以“#”号开头的代码都会被解释器所忽略. 比如下面 ...
- 洛谷 P2345 奶牛集会
https://www.luogu.org/problem/show?pid=2345 题目描述 约翰的N 头奶牛每年都会参加“哞哞大会”.哞哞大会是奶牛界的盛事.集会上的活动很 多,比如堆干草,跨栅 ...
- .net core 集成 autofac.
1. Install Install-Package Autofac Install-Package Autofac.Extensions.DependencyInjection 2.Startup ...
- GridControl详解(六)样式设置
表格样式:全局设置 例子: 例子: 列样式:只作用于当前的列 通用样式:外观设定 注意:样式设定都是相同的,Appearance前缀.
- bootstrap-select,selectpicker 用法详细:通过官方文档翻译
用过selectpicker的都说好~但是网上中文的教程又找不到比较完整的用法,于是去官网看了下 顺便弄过来翻译一下: 选项可以通过数据属性或JavaScript传递.对于数据属性,附加选项名称dat ...
- Spring Boot中使用Spring Security进行安全控制
我们在编写Web应用时,经常需要对页面做一些安全控制,比如:对于没有访问权限的用户需要转到登录表单页面.要实现访问控制的方法多种多样,可以通过Aop.拦截器实现,也可以通过框架实现(如:Apache ...
- 【译】第二篇 SQL Server代理作业步骤和子系统
本篇文章是SQL Server代理系列的第二篇,详细内容请参考原文. SQL Server代理作业由一系列的一个或多个作业步骤组成.一个作业步骤分配给一个特定的作业子系统(确定作业步骤去完成的工作). ...
- python 实现字符串转整型
def str2Int(s): l=list(s) if len(l)<=0: return 0 flag=0 sum=0 dict_num={':9} dict_tag={'+':1,'-': ...
- 有关mysql的innodb_flush_log_at_trx_commit参数【转】
一.参数解释 0:log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下在事务提交的时候,不会主动触发写入磁盘的操作. 1:每次事务 ...