题目地址:

id=2352">POJ 2352

今天的周赛被虐了。

TAT..线段树太渣了。。得好好补补了(尽管是从昨天才開始学的。。不能算补。。。)

这题还是非常easy的。。维护信息是每个横坐标的出现的次数。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
struct node
{
int x, y;
} star[40000];
int cmp(node x, node y)
{
if(x.y==y.y)
{
return x.x<y.x;
}
return x.y<y.y;
}
int sum[323000], _hash[130000];
void PushUp(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void update(int x, int l ,int r, int rt)
{
if(l==r)
{
sum[rt]++;
return ;
}
int mid=l+r>>1;
if(x<=mid) update(x,lson);
else update(x,rson);
PushUp(rt);
}
int query(int ll, int rr, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
return sum[rt];
}
int mid=l+r>>1;
int ans=0;
if(ll<=mid) ans+=query(ll,rr,lson);
if(rr>mid) ans+=query(ll,rr,rson);
return ans;
}
int main()
{
int n, x, y, i, j, ans, max1=-1;
scanf("%d",&n);
memset(sum,0,sizeof(sum));
for(i=0; i<n; i++)
{
scanf("%d%d",&star[i].x,&star[i].y);
if(max1<star[i].x)
max1=star[i].x;
}
sort(star,star+n,cmp);
memset(_hash,0,sizeof(_hash));
for(i=0; i<n; i++)
{
ans=query(0,star[i].x,0,max1,1);
update(star[i].x,0,max1,1);
_hash[ans]++;
}
for(i=0; i<n; i++)
{
printf("%d\n",_hash[i]);
}
return 0;
}

POJ 2352 Stars(线段树)的更多相关文章

  1. [POJ] 2352 Stars [线段树区间求和]

    Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...

  2. POJ 2352 Stars 线段树

    题目链接 题意:在一个二维平面上有n个星星,每个星星的等级为x,x为该星星左方和下方所包含的星星的数量(包含正左和正下的),输出每个等级各有多少星星,星星坐标按照y序递增给出,y值相同按照x递增给出. ...

  3. POJ 2352 Stars 线段树 数星星

    转载自 http://www.cnblogs.com/fenshen371/archive/2013/07/25/3214927.html 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标 ...

  4. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  5. hdu 1541/poj 2352:Stars(树状数组,经典题)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. POJ 2352 Stars(树状数组)题解

    Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...

  7. POJ 2352 stars (树状数组入门经典!!!)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 54352   Accepted: 23386 Descripti ...

  8. POJ 2352 Stars【树状数组】

    <题目链接> 题目大意: 题目给出n个点,这些点按照y坐标的升序,若y相同,则按照x的升序顺序输入,问,在这些点中,左下角的点的数量分别在0~n-1的点分别有多少个,写出它们的对应点数. ...

  9. poj 2352 stars 【树状数组】

    题目 题意:按y递增的顺序给出n颗星星的坐标(y相等则x递增),每个星星的等级等于在它左边且在它下边(包括水平和垂直方向)的星星的数量,求出等级为0到n-1的星星分别有多少个. 因为y递增的顺序给出, ...

  10. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. 使用bbed恢复表数据

    对于表级别的数据恢复,ORACLE提供了多种恢复方法:flashback query,logmnr等. 本文通过演示样例演示使用bbed的copy命令恢复用户误删除或者损坏的表数据,当然我们也能够使用 ...

  2. SVN管理工具的使用(实习第9天)

    最后就是我进行提交代码的时候要记得写注释,自己写了那些方法要标明,或者自己修改了哪些功能也要表明.不然我会被骂的. 2>代码冲突解决的问题: 服务器上的代码跟自己代码改动的地方不同 这种情况比较 ...

  3. node06---npm、silly-datetime、路径问题

    我们刚才学习了,模块就是一些功能的封装,所以一些成熟的.经常使用的功能,都有人封装成为了模块.并且放到了社区中,供人免费下载. 这个伟大的社区,叫做npm. 也是一个工具名字 node package ...

  4. java生成MD5校验码

    在Java中,java.security.MessageDigest (rt.jar中)已经定义了 MD5 的计算,所以我们只需要简单地调用即可得到 MD5 的128 位整数.然后将此 128 位计 ...

  5. Dictionary subtraction

    Finding the words from the book that are not in the word list from words.txt is a problem you might ...

  6. [转]Adobe Creative Cloud 2015 下载 Adobe CC 2015 Download

    Adobe Creative Cloud 2015 下载   Adobe 宣布 Creative Cloud 设计套件全线更新! Adobe CC 2015新功能包括: – Premiere Pro ...

  7. ListView中嵌套GridView点击事件

    做一个项目时,需要在ListView中嵌套GridView,因为ListView的每个条目中不一定出现GridView,那么问题来了,添加GridView的Item的点击事件后,有GridView出现 ...

  8. bootstrap-treeview简单使用

    废话不多说,直接上干干货. 1.bootstrap-treeview Github网址:https://github.com/jonmiles/bootstrap-treeview 2.使用要求: & ...

  9. kotlin MutableList sort

    fun MutableList<Int>.swap(index1: Int, index2: Int) {val tmp = this[index1] // 'this' correspo ...

  10. Futures and promises

    In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing ...