HDU 6183
题意:有三种操作,分别为:
0 清除矩阵中所有颜色
1 x y c 在(x,y)点涂上c颜色
2 x y1 y2 询问左上角为(1,y1),右上角为(x,y2)的矩阵中含有的颜色种数
其实和CF 19D一样 只不过有50个颜色 你需要分别建立五十棵线段树 手法给别人学的 看看代码吧
做法就是给每个y坐标存该颜色最小值x
动态开点 值得好好回顾
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
const int MAX_N = 1000025;
int root[52];
int minn[MAX_N<<2],son[MAX_N<<2][2],cnt = 0;
int Min(int a,int b){if(a<b) return a;return b;}
inline void init()
{
memset(root,0,sizeof(root));
cnt = 0;
son[0][0] = son[0][1] = 0;
minn[0] = inf;
}
inline void up(int p)
{
minn[p] = min(minn[son[p][0]],minn[son[p][1]]);
}
inline void update(int &p,int l,int r,int x,int y)
{
if(!p)
{
p=++cnt;
minn[p] = y;
son[p][0] = son[p][1] = 0;
}
if(l==r)
{
minn[p] = min(minn[p],y);
return ;
}
int mid = (l+r)>>1;
if(x<=mid) update(son[p][0],l,mid,x,y);
else update(son[p][1],mid+1,r,x,y);
up(p);
}
inline int query(int p,int l,int r,int ql,int qr){
if(!p)return inf;
if(ql<=l&&r<=qr)return minn[p];
int mid=l+r>>1;
if(qr<=mid)return query(son[p][0],l,mid,ql,qr);
if(ql>mid)return query(son[p][1],mid+1,r,ql,qr);
return min(query(son[p][0],l,mid,ql,mid),query(son[p][1],mid+1,r,mid+1,qr));
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int t,x,y,c;
init();
while(~scanf("%d",&t))
{
if(t==3) break;
else if(t==0) init();
else if(t==1)
{
scanf("%d%d%d",&x,&y,&c);
update(root[c],1,1000000,y,x);
}
else
{
scanf("%d%d%d",&x,&y,&c);
int ans = 0;
for(int i = 0;i<=50;++i)
ans+=(query(root[i],1,1000000,y,c)<=x);
printf("%d\n",ans);
}
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}