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轴投影下都不相交的矩形数 最后一项 ...
随机推荐
- Flask+ Angularjs 实例: 创建博客
允许任何用户注册 允许注册的用户登录 允许登录的用户创建博客 允许在首页展示博客 允许登录的用户退 后端 Flask-RESTful - Flask 的 RESTful 扩展 Flask-SQLAlc ...
- PTA 09-排序2 Insert or Merge (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/675 5-13 Insert or Merge (25分) According to ...
- HDU——1195Open the Lock(双向BFS)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Opencv学习笔记——视频高斯模糊并分别输出
用两个窗口进行对比 #include "stdafx.h" #include <iostream> #include <opencv2/core/core.hpp ...
- 3931: [CQOI2015]网络吞吐量【网络流】
网络吞吐量(network)题目描述路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的地,路 ...
- POJ3744 Scout YYF I (矩阵优化的概率DP)
Scout YYF I YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into th ...
- LightOJ1125 Divisible Group Sums
Divisible Group Sums Given a list of N numbers you will be allowed to choose any M of them. So you c ...
- Mac 快速修改 hosts 文件
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
- 开始学习Objective-C
加油! 顺便试试这MarsEdit好用不~
- 使用 ftrace 调试 Linux 内核,第 2 部分
ftrace 操作概述 使用 ftrace 提供的跟踪器来调试或者分析内核时需要如下操作: 切换到目录 /sys/kernel/debug/tracing/ 下 查看 available_tracer ...