HDU6183 Color it (线段树动态开点)
题意:
一个1e6*1e6的棋盘,有两个操作:给(x,y)加上颜色c,或查找(1,y1)到(x,y2)内的颜色种类数量,最多有50种颜色
思路:
建立50颗线段树,对每个颜色的线段树,维护每个y坐标上x的最小值
但是这样会爆内存,于是动态开点即可
动态开点之后T了一发,就改了下查询的函数,只要有满足在矩形的该颜色,就全线return,果然快了好多
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int lc[maxn<<];
int rc[maxn<<];
int minv[maxn<<];
int tot;
int root[];
int build(){
tot++;
lc[tot]=rc[tot]=;
minv[tot]=mod;
return tot;
} void update(int p, int v, int l, int r, int &root){
if(!root){
root = build();
}
if(minv[root] > v) minv[root] = v;
if(l==r)return;
int mid = (l+r)/;
if(p <= mid)update(p,v,l,mid,lc[root]);
if(p > mid)update(p,v,mid+,r,rc[root]);
}
int flg;
int X;
void query(int ql, int qr, int l, int r, int root){
if(!root||flg)return;
if(ql <= l && r <= qr){
if(minv[root]<=X)flg=;
return;
}
int mid = (l+r)/;
if(ql <= mid)query(ql, qr, l, mid, lc[root]);
if(mid < qr) query(ql, qr, mid+,r,rc[root]);
return;
}
int main(){
tot = ;
int op; while(scanf("%d", &op)){
if(op==)return ;
if(op==){
tot = ;
mem(root,);
}
else if(op == ){
int x, y, c;
scanf("%d %d %d", &x, &y, &c);
if(!root[c]){
root[c] = build();
}
update(y, x, , , root[c]);
}
else{
int ans = ;
int x,y1,y2;
scanf("%d %d %d", &x, &y1, &y2);
X=x;
for(int i = ; i <= ; i++){
flg = ;
query(y1,y2,,,root[i]);
//printf("-- %d %d\n",i,tmp);
if(flg)ans++;
}
printf("%d\n",ans);
}
}
return ;
}
HDU6183 Color it (线段树动态开点)的更多相关文章
- hdu6183 Color it 线段树动态开点+查询减枝
题目传送门 题目大意: 有多次操作.操作0是清空二维平面的点,操作1是往二维平面(x,y)上放一个颜色为c的点,操作2是查询一个贴着y轴的矩形内有几种颜色的点,操作3退出程序. 思路: 由于查询的矩形 ...
- HDU - 6183 暴力,线段树动态开点,cdq分治
B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...
- BZOJ_4636_蒟蒻的数列_线段树+动态开点
BZOJ_4636_蒟蒻的数列_线段树+动态开点 Description 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将 ...
- P3939 数颜色 线段树动态开点
P3939 数颜色 线段树动态开点 luogu P3939 水.直接对每种颜色开个权值线段树即可,注意动态开点. #include <cstdio> #include <algori ...
- 洛谷P3313 [SDOI2014]旅行 题解 树链剖分+线段树动态开点
题目链接:https://www.luogu.org/problem/P3313 这道题目就是树链剖分+线段树动态开点. 然后做这道题目之前我们先来看一道不考虑树链剖分之后完全相同的线段树动态开点的题 ...
- codedecision P1113 同颜色询问 题解 线段树动态开点
题目描述:https://www.cnblogs.com/problems/p/11789930.html 题目链接:http://codedecision.com/problem/1113 这道题目 ...
- 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分治)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
- 2019.03.09 bzoj4999: This Problem Is Too Simple!(树链剖分+线段树动态开点)
传送门 题意:给一颗树,每个节点有个初始值,要求支持将i节点的值改为x或询问i节点到j节点的路径上有多少个值为x的节点. 思路: 考虑对每种颜色动态开点,然后用树剖+线段树维护就完了. 代码: #in ...
随机推荐
- WPF 给Button按钮加小图标图片Image
前言:当WPF项目后台完成到一定程度的时候,就可以对XAML前端进行美化啦,个人认为XAML前端还是挺有意思的. 下面举一个Button加过小图标后的例子: 是不是比生硬的文字看来更人性化了呢? 不多 ...
- 每日一问2:堆(heap)和栈(stack)的区别
因为这里没有明确指出堆是指数据结构还是存储方式,所以两个尝试都回答一下. 一.堆和栈作为数据结构 1.堆(heap),也叫做优先队列(priority queue),队列中允许的操作是先进先出(FIF ...
- C# 微信h5支付
相关文档 https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_20&index=1 需要准备 公众号ID.商户号.商家私钥 1.登 ...
- Java 第一次课堂测验
周一下午进行了开学来java第一次课堂测验,在课堂上我只完成了其中一部分,现代码修改如下: 先定义 ScoreInformation 类记录学生信息: /** * 信1805-1 * 胡一鸣 * 20 ...
- cannot mount volume over existing file, file exists /var/lib/docker/overlay2/.../merged/usr/share/zoneinfo/UTC 解决
问题产生原因: linux系统docker-compose.yml文件 放到 mac本启动发现启动报错 cannot mount volume over existing file, file exi ...
- C++中全排列函数next_permutation 用法
今天蓝桥杯刷题时发现一道字符串排序问题,突然想起next_permutation()函数和prev_permutation()函数. 就想写下next_permutation()的用法 next_pe ...
- 常见基本数据结构——树,二叉树,二叉查找树,AVL树
常见数据结构——树 处理大量的数据时,链表的线性时间太慢了,不宜使用.在树的数据结构中,其大部分的运行时间平均为O(logN).并且通过对树结构的修改,我们能够保证它的最坏情形下上述的时间界. 树的定 ...
- mysql索引创建和使用细节(二)
上篇粗略记录当mysql字段类型是string,传入int类型参数后失效当问题. 现在测试下mysql字段是int类型,传参string类型会发生什么. 题外话,最近膝盖手术后还在家养伤中,只怪自己以 ...
- 弹性碰撞 poj 3684
Simon is doing a physics experiment with N identical balls with the same radius of R centimeters. Be ...
- 洛谷p1137 模拟退火
题目链接:https://www.luogu.org/problem/P1337 以x为原点,将力分解成横纵方向的力,每次退火时单独对答案的横纵坐标进行判断是否更新答案 #include<ios ...