poj2352stars【treap树水题】
来源:互联网 发布:剑灵忽雷捏脸数据 编辑:程序博客网 时间:2024/06/08 15:30
又是审题!虽说好多网友都被坑在这里了==
说题意:给出的这些坐标只考虑小于等于自身横纵坐标的个数(不包括自己)分别有多少点的这种个数是在0~n-1范围内的 裸的treap不解释
/****************poj23522016.1.261040K469MSG++1648B****************/#include <cstdio>#include <cstring>#include <ctime>#include <iostream>#include <algorithm>#include <cstdlib>#include <cmath>#include <utility>#include <vector>#include <queue>#include <map>#include <set>#define max(x,y) ((x)>(y)?(x):(y))#define min(x,y) ((x)>(y)?(y):(x))#define INF 0x3f3f3f3f#define MAXN 20005using namespace std;int cnt=1,rt=0; //节点编号从1开始struct Tree{ int key, size, pri, son[2]; //保证父亲的pri大于儿子的pri void set(int x,int y, int z) { key=x; pri=y; size=z; son[0]=son[1]=0; }}T[MAXN];void rotate(int p, int &x){ int y=T[x].son[!p]; T[x].size=T[x].size-T[y].size+T[T[y].son[p]].size; T[x].son[!p]=T[y].son[p]; T[y].size=T[y].size-T[T[y].son[p]].size+T[x].size; T[y].son[p]=x; x=y;}void ins(int key, int &x){ if(x == 0) T[x = cnt++].set(key, rand(), 1); else { T[x].size++; int p=(key <= T[x].key); ins(key,T[x].son[!p]); if(T[x].pri < T[T[x].son[!p]].pri) rotate(p, x); }}int find_NoLarger(int key, int &x) //找出值小于等于key的节点个数{ if(x == 0) return 0; if(T[x].key <= key) return T[T[x].son[0]].size+1+find_NoLarger(key, T[x].son[1]); else return find_NoLarger(key, T[x].son[0]);}int num[15010],tmp[15010];int main(){ // freopen("cin.txt","r",stdin); int n,x,y; while(~scanf("%d",&n)) { cnt=1,rt=0; memset(tmp,0,sizeof(tmp)); for(int i=1;i<=n;i++) { scanf("%d%d",&x,&y); tmp[find_NoLarger(x,rt)]++; ins(x,rt); } for(int i=0;i<n;i++) printf("%d\n",tmp[i]); }}
0 0
- poj2352stars【treap树水题】
- poj2352Stars(树状数组)
- POJ2352Stars(树状数组)
- Treap
- Treap
- Treap
- Treap
- Treap
- Treap
- treap
- Treap
- treap
- Treap
- treap
- Treap
- Treap
- treap
- Treap
- 海量增量学习神经网络 lsnn,the finaly nn
- VS2013中带命令行参数的调试方法
- 个性化vim之映射(map,vmap)
- mongodb的group简单使用
- 空气质量数据下载
- poj2352stars【treap树水题】
- Linux下的多线程调试
- 引导界面微场景交互设计与技术实现V1.0
- 临时笔记
- java中的线程
- Spark问题之More than one scala library found in the build path
- sed编辑器
- 接着ACM2002
- Tomcat热部署