poj2352Stars
http://poj.org/problem?id=2352
二维逆序数 按一个数排序 转化为1维的 之前用树状数组写过 这次用线段树敲了下
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 32010
struct node
{
int x, y;
}st[N];
int s[N<<],f[N];
bool cmp(node a,node b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
void build(int l,int r,int w)
{
s[w] = ;
if(l==r)
{
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
}
void pushup(int w)
{
s[w] = s[w<<]+s[w<<|];
}
void update(int p,int l,int r,int w)
{
if(l==r)
{
s[w] += ;
return ;
}
int m = (l+r)>>;
if(p<=m)
update(p,l,m,w<<);
else
update(p,m+,r,w<<|);
pushup(w);
}
int getsum(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
int m = (l+r)>>,res=;
if(a<=m)
res+=getsum(a,b,l,m,w<<);
if(b>m)
res+=getsum(a,b,m+,r,w<<|);
return res;
}
int main()
{
int i,n;
while(cin>>n)
{
memset(f,,sizeof(f));
build(,n,);
for(i = ; i <= n ; i++)
scanf("%d%d",&st[i].x,&st[i].y);
sort(st+,st+n+,cmp);
for(i = ; i <= n ; i++)
{
int s = getsum(,st[i].x+,,N,);
update(st[i].x+,,N,);
f[s]++;
}
for(i = ; i < n ; i++)
cout<<f[i]<<endl;
}
return ;
}
poj2352Stars的更多相关文章
- POJ2352Stars【树状数组】
Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...
- C++-POJ2352-Stars[数据结构][树状数组]
/* 虽然题目没说,但是读入有以下特点 由于,输入是按照按照y递增,如果y相同则x递增的顺序给出的 所以,可以利用入读的时间进行降为处理 */ 于是我们就得到了一个一维的树状数组解法啦 值得一提:坐标 ...
- poj2481
题意:给定一些线段(s, e),起点为s,终点为e,求每一段线段被多少线段包含(不包括相等) 思路:很明显的树状数组题目..但是做的时候想了挺久..(下面的x为线段起点, y为线段终点) 做法1:先对 ...
随机推荐
- SQL Server如何使用XML格式传输解析
Sqlserver in 实现 参数化查询 XML类型解决方案 [转] :如果参数是int类型: declare @a xml set @a=' <row><id>1</ ...
- 解决svn “clean up" 失败
解决方法:清空svn的队列 1.下载sqlite3.exe 2.找到你项目的.svn文件,查看是否存在wc.db 3.将sqlite3.exe放到.svn的同级目录 4.启动cmd执行sqlite3 ...
- dapper extensions (predicates)
https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates The predicate system in Dapper Extensio ...
- 用pycharm开发django项目示例
pycharm开发django工程(一) 在pycharm(企业版)中新建Django工程,注意使用虚拟环境 创建成功后,在pycharm显示的工程目录结构如下: 打开pycharm的Termina ...
- SQL*Loader使用详解(一)
1.SQL*Loader介绍 1)SQL*Loader是一个从外部文件指加载数据到Oracle数据库的工具.语法类似于DB2的Load语法,但SQL*Loader支持各种load格式.选择性load和 ...
- 在虚拟中开启Windows 8.1的Hyper-V平台
VM安装windows8开启Hype-V 今天老魏用VM安装了Windows8.1系统,想用此系统来开发一下Windows Phone8,但是要求确实要开启Hyper-V平台技术,本来是没有任何的问题 ...
- 闭包(Closures)
浅析 JavaScript 中的闭包(Closures) 一.前言 对于 JavaScript 来说,闭包是一个非常强大的特征.但对于刚开始接触的初学者来说它又似乎是特别高深的.今天我们一起来揭开闭包 ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:把输入的三元运算用计算机运算出来. ; ci ...
- setTimeout浅析
刚学习javascript的时候,感觉setTimeout很好理解,不就是过n(传入的毫秒数)毫秒,执行以下传入的函数吗?这个理解伴随了我挺长的一段时间,才对setTimeout有了新的认识,请先看下 ...
- spoj 95
栈应用 ...... 水题 #include<cstdio> #include<cstdlib> #include<cstring> #include<alg ...