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. SSM项目day4 Oracle批量插入数据bug <foreach>标签中collection属性使用的是属性名

  2. 解决ie6下png背景不能透明bug

    /*第一种方法:通过滤镜 使用css解决的办法. 注意滤镜下的1像素透明gif的覆盖图片的路径是相对页面写的*/ /*注意:这个方法不适合处理img标签引入的png图片,代码太冗余了*/ .banne ...

  3. score indicator

    The strongest scorer applet is the strongest scorer specially designed for the players. No longer wo ...

  4. 不要轻易在java ext 目录放任何三方jar包

    今天在编写一个简单spi 应用demo的时候,在编译时总有一个其他的错误,如下: ERROR Failed to execute goal org.apache.maven.plugins:maven ...

  5. 重装了服务器,用的是centos/php微信小程序版,centos 命令大全

    centos 命令大全 1.关机 (系统的关机.重启以及登出 ) 的命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdo ...

  6. 关于window.getSelection

    window.getSelection(),返回一个Selection对象,表示用户选择的文本范围或光标的当前位置. selection对象先来看下面两个selection结果:selection对象 ...

  7. nginx php-fpm 配置问题(1)

    nginx php-fpm 配置问题(1) 1.问题    Nginx/FPM/PHP all php files say 'File not found.' nginx error日志: [erro ...

  8. 微信小程序之上传图片(含前后端代码例子)

    此代码示例,能够让你成功将图片上传至后端,后端做相应的处理,然后返回成功码. 前端小程序代码 index.wxml: <view class='content'> <view cla ...

  9. Gamma阶段第一次scrum meeting

    每日任务内容 队员 昨日完成任务 明日要完成的任务 张圆宁 #91 用户体验与优化:发现用户体验细节问题https://github.com/rRetr0Git/rateMyCourse/issues ...

  10. 【Python】[技术博客] 如何对使用PYQT编写的GUI文件进行单元测试

    如何对使用PYQT编写的GUI文件进行单元测试 想要对PYQT编写的GUI文件进行单元测试,我们主要用到QTest QTest里面包含了一些对窗体的各种控件进行模拟操作的函数,通过QTest对窗体进行 ...