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. Template Function

    // TemplateFunction.cpp : Defines the entry point for the console application. // #include "std ...

  2. Java-Modifier类常用方法详解

    一.Modifier类的定义 Modifier类 (修饰符工具类) 位于 java.lang.reflect 包中,用于判断和获取某个类.变量或方法的修饰符Modifier类将各个修饰符表示为相对应的 ...

  3. [Algorithm] Bitwise Operators

    "|" can be used as assign "&" can be used as check // Read, Write, Execute / ...

  4. 洛谷 P1991 无线通讯网 题解

    P1991 无线通讯网 题目描述 国防部计划用无线网络连接若干个边防哨所.2 种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫 ...

  5. SQL进阶-隐式类型转换

    一.隐式类型转换 1.隐式类型转换 隐式类型转换: '; 程序可读性差,且依赖数据库的隐式转换规则,如果数据库升级,则程序可能无法正确执行: 有可能会导致索引失效: 有可能会导致意想不到的结果: 显式 ...

  6. smartnic

    19年趋势: Intel® 2019网络技术研讨会圆满落幕 SANTOS: Flow and HQoS Acceleration Over DPDK Using Intel Programmable ...

  7. JSX 简介

    JSX 简介 考虑如下变量声明: const element = <h1>Hello, world!</h1>; 这个有趣的标签语法既不是字符串也不是HTML. 它被称为JSX ...

  8. Centos7 更改yum源与更新系统

    [1] 首先备份 /etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cen ...

  9. 在Eclipse打开css文件时,会自动调用文本编辑器打开,而不是在Eclipse中打开

    问题描述 在Eclipse中打开css文件时候,如下图,使用系统自带的文本编辑器打开 解决方案 点击Window下的Preference,找到File Associations,然后点击Add,将cs ...

  10. Mongoose 入门以及实现数据的增、删、改、查

    mongoose 介绍 Mongoose 是在 node.js 异步环境下对 mongodb 进行便捷操作的对象模型工具.Mongoose 是 NodeJS 的驱动,不能作为其他语言的驱动. Mong ...