POJ2352——树状数组——Stars

http://poj.org/problem?id=2352

模板

/************************************************
* Author        :Powatr
* Created Time  :2015-8-13 16:18:10
* File Name     :POJ2352stars.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int m = 32000 + 10;

int level[MAXN];
int C[MAXN];

int query(int x)
{
    int ret = 0;
    while( x > 0){
        ret += C[x];
        x -= x&-x;
    }
    return ret;
}

void update(int x)
{
    while( x <= m){
        C[x]++;
        x += x&-x;
    }
}

int main(){
    int n;
    while(~scanf("%d", &n)){
        memset(level, 0, sizeof(level));
        memset(C, 0, sizeof(C));
    int x, y;
    for(int i = 1; i <= n; i++){
        scanf("%d%d", &x, &y);
        level[query(x+1)]++;
        update(x+1);
    }
    for(int i = 0; i < n; i++)
        printf("%d\n",level[i]);
    }
   return 0;
}

  

时间: 2024-10-16 02:49:48

POJ2352——树状数组——Stars的相关文章

poj2352树状数组

Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers wa

[ACM] POJ2352 [树状数组稍微变形]

Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. As

POJ2352 Stars 【树状数组】or【线段树】

Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31172   Accepted: 13595 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a st

POJ2352 Stars 树状数组

POJ2352 非常裸的树状数组的题. 注意数组下标不能从0开始 因为lowbit(0)==0 所以 所有横坐标统一加1 数组要开的够大 就酱 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<cmath> #include<vector> using namespace std; const int maxn=15000,

poj--2352 Stars(树状数组)

Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. As

POJ 2481 树状数组 区间覆盖(POJ2352 Stars 的变形题)(线段化点)

0)学会将题目情景转化为自己熟悉的结构或模型. 题目大意: 每个奶牛有自己的一个区间,求每个奶牛的区间所覆盖的子区间个数(注意,真子集,相等的不算),按照输入的顺序输出. 转化: 要学会将题目情景转化为自己熟悉的模型或结构上.把每个区间的左端x值作为点的x坐标,右端x值作为点的y坐标,就可以把所有区间转化为一个二维坐标图上的点集,而此时每个点左上方的点(同Stars那道题目一样不包括自身)的个数,就是每个区间所覆盖的子区间的个数(对应题目要求,这里或许可以再变形). 同POJ2481 Stars

POJ 2352 Stars(树状数组)

                                                                 Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 44309   Accepted: 19236 Description Astronomers often examine star maps where stars are represented by points on a pla

HDU 1541 Stars (树状数组)

Problem Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given

hdu 1541 Stars 树状数组水题

Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5210    Accepted Submission(s): 2053 Problem Description Astronomers often examine star maps where stars are represented by points on a pla