Counting Stars

题目链接:http://acm.xidian.edu.cn/problem.php?id=1177

离线+树状数组

一眼扫过去:平面区间求和,1e6的数据范围,这要hash+二维树状数组吧?这么短时间我肯定调不出来,果断弃...

结束后有人说一维树状数组可以做,ヾ(。`Д´。)离线啊没想到。

然后就成了水题...(坐标要++,因为是从零开始的)

感悟:离线算法在某种情况下可以降低复杂度的维度。

代码如下:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#define met(a,b) memset(a,b,sizeof(a))
#define N 200005
#define M 1000001
using namespace std;
struct nod{
int x,y,index,type,v;
}a[N];
int tree[M];
bool cmp(nod a,nod b){
if(a.y==b.y)return a.x<b.x;
else return a.y<b.y;
}
bool recover(nod a,nod b){
if(a.type==b.type)return a.index<b.index;
else return a.type<b.type;
}
int n,m,x,y,k;
void init(){
met(a,);
met(tree,);
}
int lowbit(int x){
return x&(-x);
}
void add(int x){
for(int i=x;i<M;i+=lowbit(i))
tree[i]++;
}
int query(int x){
int sum=;
for(int i=x;i>;i-=lowbit(i))
sum+=tree[i];
return sum;
}
int main(void){
for(int times=;~scanf("%d%d",&n,&m);++times){
init();
for(k=;k<n;++k){
scanf("%d%d",&x,&y);
x++,y++;
a[k].x=x;
a[k].y=y;
a[k].type=;
}
for(;k<n+m;++k){
scanf("%d%d",&x,&y);
x++,y++;
a[k].x=x;
a[k].y=y;
a[k].type=;
a[k].index=k-n;
}
sort(a,a+k,cmp);
printf("Case #%d:\n",times);
for(int i=;i<k;++i){
if(a[i].type==)add(a[i].x);
else a[i].v=query(a[i].x);
}
sort(a,a+k,recover);
for(int i=;i<m;++i)
printf("%d\n",a[i].v);
}
}

Counting Stars的更多相关文章

  1. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  2. HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...

  3. 【刷题】HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful! ...

  4. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  5. HDU 6184 Counting Stars 经典三元环计数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V ...

  6. HDU6184【Counting Stars】(三元环计数)

    题面 传送门 给出一张无向图,求 \(4\) 个点构成两个有公共边的三元环的方案数. 题解 orz余奶奶,orz zzk 首先,如果我们知道经过每条边的三元环个数\(cnt_i\),那么答案就是\(\ ...

  7. hdu6184 Counting Stars 【三元环计数】

    题目链接 hdu6184 题解 题意是让我们找出所有的这样的图形: 我们只需要求出每条边分别在多少个三元环中,记为\(x\),再然后以该点为中心的图形数就是\({x \choose 2}\) 所以我们 ...

  8. 全国高校网安联赛Web专场~WriteUp

    1.Sign 题目:Good Luck!flag{X-nuca@GoodLuck!} Flag直接写在题目上了,flag{X-nuca@GoodLuck!} 2.BaseCoding 提示:这是编码不 ...

  9. Python 新浪微博中提取最常见转载的微博转载了几次,username,内容

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: fi ...

随机推荐

  1. 移动开发meta集合【精】

    以下是开发中经常用到的meta标签 1.移动webAPP的Meta 用法: <meta content="width=device-width, initial-scale=1.0, ...

  2. filter怎么在程序里写,不用再web.xml中配置

  3. CodeForces 669D Little Artem and Dance

    模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...

  4. CodeForces 670E Correct Bracket Sequence Editor

    链表,模拟. 写一个双向链表模拟一下过程. #pragma comment(linker, "/STACK:1024000000,1024000000") #include< ...

  5. VMware虚拟机服务的vmware-hostd自动启动和停止

    安装了虚拟机 任务管理器会出现vmware-hostd.exe  占用了80端口,导致xampp打不开,所以就想关闭vmware,解决方案如下: 开始——运行——services.msc,找到VM打头 ...

  6. Linux Tomcat 自启动

    使用chkconfig命令 修改tomcat/bin/startup.sh,在开头的地方添加如下内容 #chkconfig: #description:tomcat auto start #proce ...

  7. As input tri-stated

    前些日子正好看到了riple兄的<一波三折--危险的"未分配"引脚>一文,颇受启发.正好最近也遇上了类似的问题,也可谓一波三折,还好最后摆平了,要不煮熟的鸭子可就要飞了 ...

  8. java 的对象拷贝(有深浅拷贝两种方式,深拷贝实现的两种方式(逐层实现cloneable接口,序列化的方式来实现))

    Java提高篇--对象克隆(复制)(转自:http://www.cnblogs.com/Qian123/p/5710533.html#_label0)   阅读目录 为什么要克隆? 如何实现克隆 浅克 ...

  9. mac上设置sudo不要密码

    觉得每次sudo都需要设置密码太过麻烦,于是折腾了一番,谁知走了一番弯路记录下来. 以下是网上找到的步骤 chmod u+w /etc/sudoers  给当前用户增加写权限 vi /etc/sudo ...

  10. 使用Java注解开发自动生成SQL

    使用注解开发的好处就是减少配置文件的使用.在实际过程中,随着项目越来越复杂,功能越来越多,会产生非常多的配置文件.但是,当配置文件过多,实际维护过程中产生的问题就不容易定位,这样就会徒劳的增加工作量. ...