/*
* @Author: wxyww
* @Date: 2018-12-10 10:39:02
* @Last Modified time: 2018-12-10 11:20:39
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<bitset>
using namespace std;
typedef long long ll;
const int N = 200000 + 100,INF = 1e7,M = 1e6;
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
int tree[N * 20],ls[N * 20],rs[N * 20],root[55];
int num;
void update(int &rt,int l,int r,int pos,int c) {
if(!rt) {
rt = ++num;
tree[rt] = c;
}
tree[rt] = min(tree[rt],c);
if(l == r) return;
int mid = (l + r) >> 1;
if(pos <= mid) update(ls[rt],l,mid,pos,c);
else update(rs[rt],mid + 1,r,pos,c);
}
int tag,cx;
void query(int rt,int l,int r,int L,int R) {
if(!rt || tag) return;
if(L <= l && R >= r) {
if(tree[rt] <= cx) tag = 1;
return;
}
int mid = (l + r) >> 1;
if(L <= mid) query(ls[rt],l,mid,L,R);
if(R > mid) query(rs[rt],mid + 1,r,L,R);
}
int main() {
while(1) {
int opt = read();
if(opt == 3) return 0;
if(opt == 0) {
memset(tree,0x3f,sizeof(tree));
memset(root,0,sizeof(root));
num = 0;
memset(ls,0,sizeof(ls));
memset(rs,0,sizeof(rs));
}
if(opt == 1) {
int x = read(),y = read(),c = read();
update(root[c],1,M,y,x);
}
if(opt == 2) {
cx = read();int y1 = read(),y2 = read();
int ans = 0;
for(int i = 0;i <= 50;++i) {
tag = 0;
query(root[i],1,M,y1,y2);
ans += tag;
}
printf("%d\n",ans);
}
}
return 0;
}
原文:https://www.cnblogs.com/wxyww/p/10095608.html