zoukankan      html  css  js  c++  java
  • POJ2352 Stars 线段树

      题目链接:http://poj.org/problem?id=2352

      水题。。。

     1 //STATUS:C++_AC_204MS_696KB
     2 #include<stdio.h>
     3 #include<stdlib.h>
     4 #include<string.h>
     5 #include<math.h>
     6 #include<iostream>
     7 #include<string>
     8 #include<algorithm>
     9 #include<vector>
    10 #include<queue>
    11 #include<stack>
    12 #include<map>
    13 using namespace std;
    14 #define LL long long
    15 #define pii pair<int,int>
    16 #define Max(a,b) ((a)>(b)?(a):(b))
    17 #define Min(a,b) ((a)<(b)?(a):(b))
    18 #define mem(a,b) memset(a,b,sizeof(a))
    19 #define lson l,mid,rt<<1
    20 #define rson mid+1,r,rt<<1|1
    21 const int N=32010,INF=0x3f3f3f3f,MOD=4001,STA=1000010;
    22 const double DNF=100000000000;
    23 
    24 int sum[N<<2],ans[N/2];
    25 int n,a,b,ret;
    26 
    27 void update(int l,int r,int rt)
    28 {
    29     if(l==r){
    30         sum[rt]++;
    31         return;
    32     }
    33     int mid=(l+r)>>1;
    34     if(a<=mid)update(lson);
    35     else update(rson);
    36     sum[rt]=sum[rt<<1]+sum[rt<<1|1];
    37 }
    38 
    39 void query(int l,int r,int rt)
    40 {
    41     if(r<=a){
    42         ret+=sum[rt];
    43         return;
    44     }
    45     int mid=(l+r)>>1;
    46     query(lson);
    47     if(a>mid)query(rson);
    48 }
    49 
    50 int main()
    51 {
    52  //   freopen("in.txt","r",stdin);
    53     int i,j;
    54     while(~scanf("%d",&n))
    55     {
    56         mem(ans,0);
    57         mem(sum,0);
    58         for(i=0;i<n;i++){
    59             scanf("%d%d",&a,&b);
    60             ret=0;
    61             query(0,N-1,1);
    62             ans[ret]++;
    63             update(0,N-1,1);
    64         }
    65 
    66         for(i=0;i<n;i++)
    67             printf("%d\n",ans[i]);
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    hbase 学习笔记一---基本概念
    hdu 4496 (并差集)
    rqnoj-105-核电站问题-dp
    面试之BI-SQL--table转换
    Android:从程序员到架构师之路Ⅲ_高焕堂
    Linux 的进程组、会话、守护进程
    Oracle创建dblink报错:ORA-01017、ORA-02063解决
    JSP 指令
    JSP 生命周期
    JSP 结构
  • 原文地址:https://www.cnblogs.com/zhsl/p/2990160.html
Copyright © 2011-2022 走看看