• POJ2352 Stars


    嘟嘟嘟

    二维偏序。

    按y排序,在x方向上用树状数组维护前缀和。

    因为输入保证排好序了,所以y没什么用。

    x可以等于0,所以最好在输入的时候加1,否则会TLE……

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 using namespace std;
    12 #define enter puts("") 
    13 #define space putchar(' ')
    14 #define Mem(a, x) memset(a, x, sizeof(a))
    15 #define rg register
    16 typedef long long ll;
    17 typedef double db;
    18 const int INF = 0x3f3f3f3f;
    19 const db eps = 1e-8;
    20 const int maxn = 3.2e4 + 5;
    21 inline ll read()
    22 {
    23   ll ans = 0;
    24   char ch = getchar(), last = ' ';
    25   while(!isdigit(ch)) {last = ch; ch = getchar();}
    26   while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();}
    27   if(last == '-') ans = -ans;
    28   return ans;
    29 }
    30 inline void write(ll x)
    31 {
    32   if(x < 0) x = -x, putchar('-');
    33   if(x >= 10) write(x / 10);
    34   putchar(x % 10 + '0');
    35 }
    36 
    37 int n, ans[maxn];
    38 
    39 int c[maxn];
    40 int lowbit(int x)
    41 {
    42   return x & -x;
    43 }
    44 void add(int pos)
    45 {
    46   for(; pos < maxn; c[pos]++, pos += lowbit(pos));
    47 }
    48 int query(int pos)
    49 {
    50   int ret = 0;
    51   for(; pos; ret += c[pos], pos -= lowbit(pos));
    52   return ret;
    53 }
    54 
    55 int main()
    56 {
    57   n = read();
    58   for(int i = 1; i <= n; ++i)
    59     {
    60       int x = read() + 1, y = read();
    61       ans[query(x)]++;
    62       add(x);
    63     }
    64   for(int i = 0; i < n; ++i) write(ans[i]), enter;
    65   return 0;
    66 }
    View Code
  • 相关阅读:
    centos7 修复引导
    Django 过滤器
    Django 面向对象orm
    Django models字段查询谓词表
    linux常用的监控命令
    常用SQL语句
    python实现FTP服务器
    用python做一个图片验证码
    rsync
    jsonp的理解
  • 原文地址:https://www.cnblogs.com/mrclr/p/9796187.html
Copyright © 2020-2023  润新知