题意分析
# 待填坑
我这个线段树怎么跑的比暴力还慢呢!
应该是没写lazy的锅吧
代码总览
线段树
#include<bits/stdc++.h>
using namespace std;
const int nmax = 50000;
const int INF = 0x3f3f3f3f;
typedef struct{
int l, r, v;
int mid(){return ((l+r)>>1);}
}Tree;
Tree tree[nmax<<1];
typedef struct{
int x, y;
}Node;
Node node[15005];
int ans[15005];
int n;
inline bool cmp(const Node & n1,const Node & n2){
if(n1.x == n2.x){
if(n1.y <= n2.y) return true;
else return false;
}else return n1.x < n2.x;
}
void build(int l, int r, int rt){
tree[rt].l = l; tree[rt].r = r;
tree[rt].v = 0;
if(tree[rt].l == tree[rt].r) return;
build(l,tree[rt].mid(),rt<<1);
build(tree[rt].mid()+1,r,rt<<1|1);
}
void update(int l, int r, int rt){
if(tree[rt].l == tree[rt].r){
tree[rt].v ++;
return;
}
if(l <= tree[rt].mid()) update(l,r,rt<<1);
if(r > tree[rt].mid()) update(l,r,rt<<1|1);
}
int query(int x ,int rt){
if(tree[rt].l == tree[rt].r) return tree[rt].v;
if( x <= tree[rt].mid()) return query(x,rt<<1);
else return query(x,rt<<1|1);
}
int main(){
scanf("%d",&n);
for(int i = 0;i<n;++i) scanf("%d %d",&node[i].x, &node[i].y);
sort(node,node+n,cmp);
build(1,32001,1);
for(int i = 0;i<n;++i){
ans[query(node[i].y,1)]++;
update(node[i].y,32001,1);
}
for(int i = 0;i<n;++i){
printf("%d\n",ans[i]);
}
return 0;
}
暴力
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
}a[15005];
int n;
int ans[15005];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].x>>a[i].y;
for(int i=1;i<=n;i++){
int tot=0;
for(int j=1;j<=n;j++){
if(i==j)
continue;
else
if(a[j].x<=a[i].x&&a[j].y<=a[i].y)
tot++;
}
ans[tot]++;
}
for(int i=0;i<n;i++)
cout<<ans[i]<<endl;
return 0;
}