HDU 6183 Color it cdq分治 + 线段树 + 状态压缩
Color it
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
0 : clear all the points.
1 x y c : add a point which color is c at point (x,y).
2 x y1 y2 : count how many different colors in the square (1,y1) and (x,y2). That is to say, if there is a point (a,b) colored c, that 1≤a≤x and y1≤b≤y2, then the color c should be counted.
3 : exit.
Each line contains a operation. It may be '0', '1 x y c' ( 1≤x,y≤106,0≤c≤50 ), '2 x y1 y2' (1≤x,y1,y2≤106 ) or '3'.
x,y,c,y1,y2 are all integers.
Assume the last operation is 3 and it appears only once.
There are at most 150000 continuous operations of operation 1 and operation 2.
There are at most 10 operation 0.
0
1 1 1
2 1 1
1 1 2
2 1 1
1 2 2
2 1 1
1 2 1
2 2 1
2 10
2 10
3
1
2
2
3
3
1
1
1
1
1
1
1
#include <bits/stdc++.h> inline int read(){int x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}return x*f;}
using namespace std;
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
const int N = 1e6 + ; namespace IO {
const int MX = 4e7; //1e7占用内存11000kb
char buf[MX]; int c, sz;
void begin() {
c = ;
sz = fread(buf, , MX, stdin);
}
inline bool read(int &t) {
while(c < sz && buf[c] != '-' && (buf[c] < '' || buf[c] > '')) c++;
if(c >= sz) return false;
bool flag = ; if(buf[c] == '-') flag = , c++;
for(t = ; c < sz && '' <= buf[c] && buf[c] <= ''; c++) t = t * + buf[c] - '';
if(flag) t = -t;
return true;
}
} struct ss{
int op,x,y,z,id;
long long ans;
ss(int op = ,int x = ,int y = ,int z = ,int id = ,long long ans = ) : op(op), x(x), y(y), z(z), id(id), ans(ans) {}
}Q[N],t[N]; bool cmp(ss s1,ss s2) { if(s1.x == s2.x) return s1.op < s2.op;else return s1.x < s2.x; } int n,mx,san[N];
void init() {n = ;}
long long v[N * ]; void update(int i,int ll,int rr,int x,long long c,int ff) {
if(ll == rr && x == ll) {if(!ff)v[i] |= 1LL<<c;else v[i] = c;return ;}
if(x <= mid) update(ls,ll,mid,x,c,ff);
else update(rs,mid+,rr,x,c,ff);
v[i] = v[ls] | v[rs];
}
long long ask(int i,int ll,int rr,int x,int y) {
if(x > y) return ;
if(ll == x && rr == y) return v[i];
if(y <= mid) return ask(ls,ll,mid,x,y);
else if(x > mid) return ask(rs,mid+,rr,x,y);
else return (ask(ls,ll,mid,x,mid) | ask(rs,mid+,rr,mid+,y));
}
void cdq(int ll,int rr) {
if(ll == rr) return ;
for(int i = ll; i <= rr; ++i) {
if(Q[i].id <= mid && Q[i].op == )
update(,,mx,Q[i].y,Q[i].z,);
else if(Q[i].id > mid && Q[i].op == )
Q[i].ans |= ask(,,mx,Q[i].y,Q[i].z);
}
for(int i = ll; i <= rr; ++i) {
if(Q[i].id <= mid && Q[i].op == )
update(,,mx,Q[i].y,,);
}
int L1 = ll, R1 = mid+;
for(int i = ll; i <= rr; ++i) {
if(Q[i].id <= mid) t[L1++] = Q[i];
else t[R1++] = Q[i];
}
for(int i = ll; i <= rr; ++i) Q[i] = t[i];
cdq(ll,mid);cdq(mid+,rr);
}
void solve() {
if(n == ) return ;
int cny = ;
for(int i = ; i <= n; ++i) {
if(Q[i].op == ) san[++cny] = Q[i].y;
else {
san[++cny] = Q[i].y;
san[++cny] = Q[i].z;
}
}
sort(san+,san+cny+);
int SA = unique(san+,san+cny+) - san - ;
for(int i = ; i <= n; ++i) {
if(Q[i].op == ) Q[i].y = lower_bound(san+,san+SA+,Q[i].y) - san;
else {
Q[i].y = lower_bound(san+,san+SA+,Q[i].y) - san;
Q[i].z = lower_bound(san+,san+SA+,Q[i].z) - san;
}
}
mx = SA;
sort(Q+,Q+n+,cmp);
cdq(,n);
for(int i = ; i <= n; ++i) {
if(Q[i].op == ) {
int sum = ;
for(int j = ; j <= ; ++j)
if((Q[i].ans >> j) & ) sum++;
printf("%d\n",sum);
}
}
}
int op,x,z,y;
int main() {
IO::begin();
while() {
IO::read(op);
if(op == || op == ) {
solve();
init();
if(op == ) return ;
continue;
}
IO::read(x);
IO::read(y);
IO::read(z);
Q[++n] = ss(op,x,y,z,n,);
}
return ;
}
HDU 6183 Color it cdq分治 + 线段树 + 状态压缩的更多相关文章
- hdu 4366 Successor - CDQ分治 - 线段树 - 树分块
Sean owns a company and he is the BOSS.The other Staff has one Superior.every staff has a loyalty an ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ACdream1157 Segments(CDQ分治 + 线段树)
题目这么说的: 进行如下3种类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i (1-base) 删除第i条增加的线段, ...
- BZOJ3711 PA2014Druzyny(动态规划+cdq分治+线段树)
显然可以dp:设f[i]为前i个人最多能分多少组,则f[i]=max{f[j]}+1 (cmax<=i-j<=dmin). 容易发现d的限制是一段连续区间,二分或者随便怎么搞都行.c则有点 ...
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
题意:给你n个球排成一行,初始都为黑色,现在给一些操作(L,R,color),给[L,R]区间内的求染上颜色color,'w'为白,'b'为黑.问最后最长的白色区间的起点和终点的位置. 解法:先离散化 ...
- hdu 1199 Color the Ball(离散化线段树)
Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
- hdu 1556 Color the ball (技巧 || 线段树)
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- Codechef SEP14 QRECT cdq分治+线段树
题意 支持删除矩阵.插入矩阵.查询当前矩阵与之前有多少个矩阵相交 算相交的时候容斥一下:相交矩形数 = 总矩形数-X轴投影不相交的矩形数-Y轴投影不相交的矩形数-XY轴投影下都不相交的矩形数 最后一项 ...
随机推荐
- Caffe 不同版本之间layer移植方法
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/52185521 (前两天这篇博客不小心被 ...
- CSU-1336: Interesting Calculator,最短路思想!
1336: Interesting Calculator 这道题被LZQ抢了一血,于是去读题发现题意不难,纯广搜结果写的一塌糊涂. 题意:给你两个数x,y.由x每次可以经过一系列操作变换,每个变换都有 ...
- ios弹性头部
很久没写博客了,金天有点时间来写下,一直觉得弹性头部很炫,看起来高大上,写起来蛮简单的 层次分析 一共有3层,最底部是图像层,中间是scrollView或者它的子类,最上层是scrollView上面添 ...
- BZOJ 3295 [Cqoi2011]动态逆序对 ——CDQ分治
时间.位置.数字为三个属性. 排序时间,CDQ位置,树状数组处理数字即可. #include <cstdio> #include <cstring> #include < ...
- XPosed框架_简单的应用
0. Xposed框架简介 关于Xposed框架相信大家应该不陌生了,他是Android中Hook技术的一个著名的框架,而Xposed框架是免费的而且还是开源的,本文主要介绍如何通过这个框架来进行系统 ...
- 火柴排队(codevs 3286)
题目描述 Description 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度.现在将每盒中的火柴各自排成一列,同一列火柴的高度互不相同,两列火柴之间的距离定义为:,其中 ai表示第一列 ...
- IOS开发之触摸背景关闭键盘的代码实现
直接上代码: // 触摸背景,关闭键盘 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch ...
- 使用nginx时,让web取得原始请求地址
问题描述 当使用nginx配置proxy_pass参数以后,后端web取得的Request.Uri是proxy_pass中配置的地址,而不是client访问的原始地址 举例说明: 假设nginx配置文 ...
- 前端MVC Vue2学习总结(八)——前端路由
路由是根据不同的 url 地址展示不同的内容或页面,早期的路由都是后端直接根据 url 来 reload 页面实现的,即后端控制路由. 后来页面越来越复杂,服务器压力越来越大,随着AJAX(异步刷新技 ...
- HDC与CDC相互转换
转自loop_k原文 HDC与CDC相互转换 概念 首先说一下什么是DC(设备描述表):Windows应用程序通过为指定设备(屏幕,打印机等)创建一个设备描述表(Device Context, DC) ...