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. 【repost】js字符串函数

    JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...

  2. asp.net小技巧:保留password模式文本框textbox内的数据不丢失。

    在asp.net 2.0环境下,使用textbox,提交到服务器再传回,如果textbox是password模式的,那么textbox内的密码(星号.圆点),就没有了! 一个可行的做法是 : prot ...

  3. 关于在框架中使用curl的思考,以及,curl其实很好用

    初步猜想: 在接触到框架文档的第一阶段时,会觉得控制器调用模型就是一件很简单的事,tp中用D方法或者M方法来实例化模型,laravel中用命名空间来加载模型,CI中用$this->load-&g ...

  4. 64位win7系统中vb工程显示加载MSCOMCTL.OCX失败

    MSCOMCTL.OCX明明已经注册成功,但还是提示加载失败,对象未注册 尝试过的方法:system32中注册,syswow64中注册,vb打sp6补丁, 修改工程文件:用记事本打开VBP文件找到这一 ...

  5. oracle建表的时候同时创建主键,外键,注释,约束,索引

    --主键create table emp (id number constraint id_pr primary key ,name1 varchar(8));create table emp9 (i ...

  6. SQL总结之导入导出

    (5)还原数据库[倒库] [数据泵模式]先要在D盘创建个目录,如D:/dbback 然后去plsql中创建目录sql命令:create directory dbback as 'D:\dbback'; ...

  7. lcd_1602

    module lcd_pdf( clk,lcd_data, lcd_rw,lcd_rs, lcd_en,rst_n ); input clk; input rst_n; output reg [:] ...

  8. svn恢复到某一版本

    转 经常由于坑爹的需求,功能要切回到之前的某一个版本.有两种方法可以实现: 方法1: 用svn merge 1) 先 svn up,保证更新到最新的版本,如20: 2) 然后用 svn log ,查看 ...

  9. swift3.0 原生GET请求 POST同理

    swift3.0 原生GET请求  POST同理 func getrequest(){ let url = URL(string: "http://117.135.196.139:" ...

  10. XTU 1246 Heartstone

    $2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$D$题 贪心. 我是这样贪的:开三个优先队列$q[0]$,$q[1]$,$q[2]$,$q[i]$存储对$3$取余之后为$i$的数. 首先看看还 ...