POJ2352 star
这道题有个非常好听的名字,求二维偏序!
听起来似乎很高端,但就是让求满足对于每个i,xi < xj && yi < yj的个数。
这道题特别良心,给的顺序都是y递增,y相同x递增的,所以可以直接用树状数组维护x,当前的i答案个数就是query(x-1)。
然后如果这道题顺序是乱的呢……?也没啥问题,我们可以离线操作,先把所有的都排一遍序,之后和上面的做法就一样了。
看一下代码。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#include<utility>
#include<map>
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define sc second
#define rep(i,a,n) for(int i = a;i <= n;i++)
#define per(i,n,a) for(int i = n;i >= a;i--)
#define enter putchar('\n')
#define lowbit(x) x & (-x)
using namespace std;
typedef long long ll;
const int M = ;
const int N = ; int read()
{
int ans = ,op = ;
char ch = getchar();
while(ch < '' || ch > '')
{
if(ch == '-') op = -;
ch = getchar();
}
while(ch >='' && ch <= '')
{
ans *= ;
ans += ch - '';
ch = getchar();
}
return ans * op;
} int n,a[M],cnt,ans[M],x,y; void add(int x)
{
while(x <= N) a[x]++,x += lowbit(x);
} int query(int x)
{
int cur = ;
while(x) cur += a[x],x -= lowbit(x);
return cur;
} int main()
{
n = read();
rep(i,,n)
{
x = read(),y = read(),x++;
ans[query(x)]++;
add(x);
}
rep(i,,n-) printf("%d\n",ans[i]);
return ;
}
POJ2352 star的更多相关文章
- 【Star CCM+实例】开发一个简单的计算流程.md
流程开发在CAE过程中处于非常重要的地位. 主要的作用可能包括: 将一些经过验证的模型隐藏在流程中,提高仿真的可靠性 将流程封装成更友好的界面,降低软件的学习周期 流程开发实际上需要做非常多的工作,尤 ...
- github中的watch、star、fork的作用
[转自:http://www.jianshu.com/p/6c366b53ea41] 在每个 github 项目的右上角,都有三个按钮,分别是 watch.star.fork,但是有些刚开始使用 gi ...
- [deviceone开发]-Star分享的几个示例
一.简介 这个是star早期分享的几个示例,都非常实用,包括弹出的菜单,模拟支付密码输入等.初学者推荐.也可以直接使用.二.效果图 三.相关下载 https://github.com/do-proje ...
- 时隔一年再读到the star
The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ...
- Github上的Watch和 Star的区别
Github 推出了新的 Notification 系统,更改了原有的 Watch 机制,为代码库增加了 Star 操作.Notification 将接收 Watching 代码库的动态,包括:* I ...
- 纯css3 Star
<style><!--* { box-sizing: border-box; padding: 0px; margin: 0px; } body, html { height: 10 ...
- Got the Best Employee of the year 2015 Star Award
Got "The Best Employee of the year 2015 Star Award" from the company, thanks to all that h ...
- star ccm+ 11.02安装
STAR CCM+是CD-Adapco公司的主打软件,其安装方式较为简单,这里以图文方式详细描述STAR CCM+11.02安装过程. 1 安装准备工作2 正式安装3 软件破解4 软件测试 1 安装准 ...
- System.Diagnostics.Process.Star的用法
System.Diagnostics.Process.Start(); 能做什么呢?它主要有以下几个功能: 1.打开某个链接网址(弹窗). 2.定位打开某个文件目录. 3.打开系统特殊文件夹,如“控制 ...
随机推荐
- mysql8忘记登录密码时,修改密码方法
一.停止mysqld进程 systemctl stop mysqld.service 二.修改/etc/my.cnf(在mysqld选项添加skip-grant-tables),设置免密码登录: vi ...
- 树莓派 -- 按键 (key)使用BCM2835 gpio library
BCM2835 GPIO library介绍 This is a C library for Raspberry Pi (RPi). It provides access to GPIO and ot ...
- 集训第五周 动态规划 B题LIS
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...
- 动态创建div(鼠标放上显示二维码)
最近的微信大行其道.各个网站上都给出的微信验证码,进行手机扫描加入. 怎么创建类似与点击鼠标弹出一个浮动的div显示二维码的这种效果. 1.首先制作好这样的图片,写css样式 <style ty ...
- HTML基础知识 table中 th,td,tr
https://www.2cto.com/kf/201711/701872.html table是一个布局神器,之前看过很多代码,都是用table布局的.但是,我在学习的过程中,发现table有很迷的 ...
- 567. Permutation in String
Problem statement: Given two strings s1 and s2, write a function to return true if s2 contains the p ...
- 仪仗队(bzoj 2190)
Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是 ...
- iOS点击cell时,控件背景色消失的解决方法
同时调用一下两个方法: - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected ...
- Add Two Numbers(链表)
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- LOAP& its implimenlation
LDAP 概念 LDAP的英文全称是Lightweight Directory Access Protocol,简称为LDAP,LDAP是轻量目录访问协议,LDAP是轻量目录访问协议.简单的说来,LD ...