Color it
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 1745 Accepted Submission(s): 524
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.
解题 说明:待补。。。
AC代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int INF=1e9+7,inf=0x3f;
const int MAXN=1e6+5;
int l[MAXN*4],r[MAXN*4],v[MAXN*4],cnt=0;
int root[55],xx,flag;
void update(int k,int ll,int rr,int x,int y){
if(k==0){
k=++cnt;
v[k]=x;
}
if(v[k]>x)v[k]=x;
if(ll==rr)return;
int mid=(ll+rr)/2;
if(y<=mid)update(l[k],ll,mid,x,y);
else update(r[k],mid+1,rr,x,y);
}
void query(int k,int ll,int rr,int x,int y){
if(flag)return;
if(x<=ll&&y>=rr){
if(v[k]<=xx)flag=1;
return;
}
int mid=(ll+rr)/2;
if(x<=mid)query(v[k],ll,mid,x,y);
if(y>mid)query(v[k],mid+1,rr,x,y);
}
int main(){
ios::sync_with_stdio(false);
int ip,ip2,ip3;
while(true){
cin>>ip;
if(ip==3)break;
else if(ip==0){
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
cnt=0;
}
else if(ip==1){
cin>>xx>>ip2>>ip3;
update(root[ip3],1,1e6,xx,ip2);
}
else {
cin>>xx>>ip2>>ip3;
int ans=0;
for(int i=0;i<=50;i++){
flag=0;
query(root[i],1,1e6,ip2,ip3);
ans+=flag;
}
cout<<ans<<endl;
}
}
return 0;
}