Color it

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s):
0

Problem Description
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

: 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.

 
Input
The input contains many lines.

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.

 
Output
For 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
 
题解:这道题目AC的人比较少    在这提供俩种想法
第一:题目规定了颜色的数目最多是51种    
我们可以使用51个线段树   来保存每一种颜色的那些坐标
然后使用线段树查询     时间可能会少点    
第二:我是使用的第二种方法,题目说了最多有150000个1和2的操作
所以穷举也不是不可以的考虑的    我就是使用穷举AC的
不过时间复杂度不能和线段树的比
//但是   我的代码简单    
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <vector>
#include <math.h>
using namespace std; struct Node
{
int x;
int y;
} node;
vector<Node>v[];
int main()
{
int k,c;
int x2,y1,y2;
while()
{
scanf("%d",&k);
if(k==)break;
if(k==)
{
for(int i=; i<; ++i)
v[i].clear();
}
else if(k==)
{
scanf("%d%d%d",&node.x,&node.y,&c);
v[c].push_back(node);
}
else
{
int ans=;
scanf("%d%d%d",&x2,&y1,&y2);
for(int i=; i<=; ++i)
{
for(int j=; j<v[i].size(); ++j)
{
int xx=v[i][j].x;
int yy=v[i][j].y;
if(xx<=x2&&yy<=y2&&yy>=y1)
{
ans++;
break;
}
}
}
printf("%d\n",ans);
}
}
return ;
}
//欢迎喜欢算法 IT的dalao加1345411028 带我飞
 

2017ACM/ICPC广西邀请赛 Color it的更多相关文章

  1. 2017ACM/ICPC广西邀请赛-重现赛

    HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...

  2. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  3. 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree

    Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...

  4. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

  5. HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序

    题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...

  6. 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem

    2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...

  7. 2017ACM/ICPC广西邀请赛-重现赛1005 CS course

    2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...

  8. 2017ACM/ICPC广西邀请赛

    A.A Math Problem #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll ...

  9. 2017ACM/ICPC广西邀请赛 Duizi and Shunzi

    题意:就是一个集合分开,有两种区分 对子:两个相同数字,顺子:连续三个不同数字,问最多分多少个 解法:贪心,如果当前数字不构成顺子就取对子 /2,如果可以取顺子,那么先取顺子再取对子 #include ...

随机推荐

  1. 【转】Web测试中定位bug方法

    在web测试过程中,经常会遇到页面中内容或数据显示错误,甚至不显示,第一反应就是BUG,进一步了解这个BUG的问题出在那里,是测试人员需要掌握的,可以简单的使用浏览器自带开发者工具.数据库工具配合去排 ...

  2. deque_queue_list

    #include <iostream> #include <deque>//front push pop back push pop [] at() #include < ...

  3. appium环境应该注意问题

    python中的script要加入到环境变量中 pip3 install appium-python-client(安装appium模块通过引入webdriver) 如果pip3不是内部命令解决方法 ...

  4. React Hook Flow Diagram

    一.概述 Donovon has created this nice flowchart that explains the new lifecycle of a Hooks component. C ...

  5. Generative Adversarial Networks overview(3)

    Libo1575899134@outlook.com Libo (原创文章,转发请注明作者) 本文章主要介绍Gan的应用篇,3,主要介绍图像应用,4, 主要介绍文本以及医药化学其他领域应用 原理篇请看 ...

  6. IDEA连接Oracle数据库

    连接Oracle的前提是导入了相关的jar或者依赖 下面是连接数据库的操作 如果出现了下面的画面,就说明连接成功

  7. planAhead的启动时间较长

    发现Xilinx planAhead的启动时间约需10秒钟.

  8. VUE的生命周期——钩子函数

  9. ThinkPHP 5.1 跨域中间件

    <?php namespace app\http\middleware; class CrossDomain { public function handle($request, \Closur ...

  10. Db2 Terminate Vs Connect Reset , Disconnect

    db2 Terminate and db2 connect Reset both break the connection to a database.                Connect ...