博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2017ACM/ICPC广西邀请赛 Color it
阅读量:6838 次
发布时间:2019-06-26

本文共 2389 字,大约阅读时间需要 7 分钟。

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 1ax and y1by2 , 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' (
1x,y106,0c50 ), '2 x y1 y2' (1x,y1,y2106 ) 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 
#include
#include
#include
#include
#include
#include
using namespace std;struct Node{ int x; int y;} node;vector
v[65];int main(){ int k,c; int x2,y1,y2; while(1) { scanf("%d",&k); if(k==3)break; if(k==0) { for(int i=0; i<65; ++i) v[i].clear(); } else if(k==1) { scanf("%d%d%d",&node.x,&node.y,&c); v[c].push_back(node); } else { int ans=0; scanf("%d%d%d",&x2,&y1,&y2); for(int i=0; i<=50; ++i) { for(int j=0; j
=y1) { ans++; break; } } } printf("%d\n",ans); } } return 0;} //欢迎喜欢算法 IT的dalao加1345411028 带我飞

 

 

转载于:https://www.cnblogs.com/52why/p/7459997.html

你可能感兴趣的文章
教育“优先”,落实才是关键
查看>>
传统IT大佬们,路在何方?
查看>>
基础练习
查看>>
shell学习笔记 (9.3)
查看>>
用chrome在电脑上模拟微信内置浏览器
查看>>
PHP获取常用时间的总结
查看>>
设计模式6大原则:里氏置换原则
查看>>
hbase0.94.14伪分布式安装
查看>>
Debug记录:vCenter6.5突然不能访问并报错“503 Service Unavailable”
查看>>
自动导出oracle的数据
查看>>
顺序表实现的源码
查看>>
我的友情链接
查看>>
iOS调用系统摄像头和相册
查看>>
mysql文件导入办法(直接copy数据库文件)
查看>>
【二叉树】线索化二叉树
查看>>
mysql的key和index
查看>>
squid windows 配置日志
查看>>
wordpress 安装主题
查看>>
linux磁盘管理及文件系统
查看>>
梭子鱼垃圾邮件网关-Barracuda Spam & Virus Firewall Email Alert: outQueueHigh
查看>>