Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to maintain following operations. The specific format of these operations is as follows.

0 0

: clear all the points.

1 1

x x

y y

c c

: add a point which color is c c

at point (x,y) (x,y)

.

2 2

x x

y 1  y1

y 2  y2

: count how many different colors in the square (1,y1) (1,y1)

and (x,y2) (x,y2)

. That is to say, if there is a point (a,b) (a,b)

colored c c

, that 1≤a≤x 1≤a≤x

and y 1 ≤b≤y 2  y1≤b≤y2

, then the color c c

should be counted.

3 3

: exit.

InputThe input contains many lines.

Each line contains a operation. It may be '0', '1 x y c' ( 1≤x,y≤10 6 ,0≤c≤50 1≤x,y≤106,0≤c≤50

), '2 x y1 y2' (1≤x,y 1 ,y 2 ≤10 6  1≤x,y1,y2≤106

) or '3'.

x,y,c,y1,y2 x,y,c,y1,y2

are all integers.

Assume the last operation is 3 and it appears only once.

There are at most 150000 150000

continuous operations of operation 1 and operation 2.

There are at most 10 10

operation 0.

OutputFor each operation 2, output an integer means the answer .
Sample Input

0
1 1000000 1000000 50
1 1000000 999999 0
1 1000000 999999 0
1 1000000 1000000 49
2 1000000 1000000 1000000
2 1000000 1 1000000
0
1 1 1 1
2 1 1 2
1 1 2 2
2 1 1 2
1 2 2 2
2 1 1 2
1 2 1 3
2 2 1 2
2 10 1 2
2 10 2 2
0
1 1 1 1
2 1 1 1
1 1 2 1
2 1 1 2
1 2 2 1
2 1 1 2
1 2 1 1
2 2 1 2
2 10 1 2
2 10 2 2
3

Sample Output

2
3
1
2
2
3
3
1
1
1
1
1
1
1

题意:给定一个1e6*1e6的矩阵,有四种操作,0是清空矩阵;1是给某点加一个颜色c;2是查询某个区间(1,y1)到(x2,y2)的颜色数,3是退出。

思路:由于矩阵位置的特殊性,都是x=1开始,那么我们就是查询每种颜色在区间(y1,y2)是否有点的最小值小于x2。 用线段树维护区间最小值,动态开点。

(日后来补CDQ分治。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
struct in{
int l,r,v;
in(){l=r=v=;}
}s[maxn<<]; int rt[],cnt;
void update(int &Now,int L,int R,int pos,int val)
{
if(!Now) Now=++cnt,s[Now].v=val;
s[Now].v=min(s[Now].v,val);
if(L==R) return ; int Mid=(L+R)>>;
if(pos<=Mid) update(s[Now].l,L,Mid,pos,val);
else update(s[Now].r,Mid+,R,pos,val);
}
bool query(int Now,int L,int R,int l,int r,int pos)
{
if(!Now) return false;
if(l<=L&&r>=R) return s[Now].v<=pos;
int Mid=(L+R)>>;
if(l<=Mid) if(query(s[Now].l,L,Mid,l,r,pos)) return true;
if(r>Mid) if(query(s[Now].r,Mid+,R,l,r,pos)) return true;
return false;
}
int main()
{
int opt,x1,y1,x2,y2,c;
while(scanf("%d",&opt)){
if(opt==){
rep(i,,) rt[i]=;
rep(i,,cnt) s[i].l=s[i].r=s[i].v=;cnt=;
}
else if(opt==){
scanf("%d%d%d",&x1,&y1,&c);
update(rt[c],,,y1,x1);
}
else if(opt==){
scanf("%d%d%d",&x2,&y1,&y2); int ans=;
rep(i,,) ans+=query(rt[i],,,y1,y2,x2);
printf("%d\n",ans);
}
else break;
}
return ;
}

最新文章

  1. CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决
  2. 用soapUI生成客户端代码
  3. 【转帖】自助式BI的崛起:三张图看清商业智能和大数据分析市场趋势
  4. .NET 配置文件简单使用
  5. 常见JS(JavaScript)冲突解决方法
  6. 【笨嘴拙舌WINDOWS】tagTEXTMETRIC结构
  7. HealthKit框架参考(转)
  8. HDU 1009 FatMouse&#39; Trade(贪心)
  9. QML Object Attributes QML对象属性
  10. 从CMOS到触发器(二)
  11. 【原码笔记】-- protobuf.js 与 Long.js
  12. C#实现注册表 LocalMachine 目录下CURD工具类
  13. NOIP 2017 宝藏 - 动态规划
  14. Apache-Flink深度解析-DataStream-Connectors之Kafka
  15. java学习(二)--- 变量类型
  16. iOS 弹幕制作
  17. Linux下卸载安装jdk
  18. MySql的数据分页的Sql
  19. xlutils模块使用
  20. Nginx1.8.1打开gzip压缩

热门文章

  1. 属性检测 In,hasOwnPreperty()和propertyIsEnumerable()
  2. ocx的容器调试和ie调试
  3. DNS解析过程和DNS挟持
  4. pyspider脚本编写指南
  5. 远程桌面.【转】Win10 家庭(home)版启用远程桌面(Remote Desktop)功能
  6. scala学习手记34 - trait方法的延迟绑定
  7. 落地案例|日本雅虎如何在 OpenStack 上大规模构建和运行 Kubernetes
  8. MySQL 5.6 二进制包安装配置多实例方法
  9. 漂亮的Html5网站
  10. js不执行的问题