线段树。

假设只有一种颜色,因为每次询问有一个$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的更多相关文章

  1. HDU 6183 Color it 线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...

  2. HDU 6183 Color it(动态开点线段树)

    题目原网址:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题目中文翻译: Time Limit: 20000/10000 MS (Java/Others ...

  3. hdu 6183 Color it (线段树 动态开点)

    Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...

  4. 【刷题】HDU 6183 Color it

    Problem Description Do you like painting? Little D doesn't like painting, especially messy color pai ...

  5. HDU 6183 Color it cdq分治 + 线段树 + 状态压缩

    Color it Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Pro ...

  6. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  9. HDU - 6183:Color it (线段树&动态开点||CDQ分治)

    Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...

随机推荐

  1. CF821 E. Okabe and El Psy Kongroo 矩阵快速幂

    LINK 题意:给出$n$条平行于x轴的线段,终点$k$坐标$(k <= 10^{18})$,现在可以在线段之间进行移动,但不能超出两条线段的y坐标所夹范围,问到达终点有几种方案. 思路:刚开始 ...

  2. 【LibreOJ】#6257. 「CodePlus 2017 12 月赛」可做题2

    [题意]数列满足an=an-1+an-2,n>=3.现在a1=i,a2=[l,r],要求满足ak%p=m的整数a2有多少个.10^18. [算法]数论(扩欧)+矩阵快速幂 [题解]定义fib(i ...

  3. Java并发编程学习路线

    一年前由于工作需要从微软技术栈入坑Java,并陆陆续续做了一个Java后台项目,目前在搞Scala+Java混合的后台开发,一直觉得并发编程是所有后台工程师的基本功,所以也学习了小一年Java的并发工 ...

  4. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  5. ubuntu16.04中启动anaconda图形化界面

    $ source ~/anaconda3/bin/activate root $ anaconda-navigator

  6. 目标检测-基于Pytorch实现Yolov3(1)- 搭建模型

    原文地址:https://www.cnblogs.com/jacklu/p/9853599.html 本人前段时间在T厂做了目标检测的项目,对一些目标检测框架也有了一定理解.其中Yolov3速度非常快 ...

  7. Machine Learning系列--深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件

    在求取有约束条件的优化问题时,拉格朗日乘子法(Lagrange Multiplier) 和KKT条件是非常重要的两个求取方法,对于等式约束的优化问题,可以应用拉格朗日乘子法去求取最优值:如果含有不等式 ...

  8. ACM ICPC Kharagpur Regional 2017

    ACM ICPC Kharagpur Regional 2017 A - Science Fair 题目描述:给定一个有\(n\)个点,\(m\)条无向边的图,其中某两个点记为\(S, T\),另外标 ...

  9. $FFT$(快速傅里叶变换)

    - 概念引入 - 点值表示 对于一个$n - 1$次多项式$A(x)$,可以通过确定$n$个点与值(即$x$和$y$)来表示这唯一的$A(x)$ - 复数 对于一元二次方程 $$x^2 + 1 = 0 ...

  10. linux nginx php-fpm被攻击

    1.nginx错误日志:报错 2018/05/30 16:30:55 [error] 8765#0: *1485 connect() to unix:/tmp/php-70-cgi.sock fail ...